blob: 44578a7ff34dca51c50ef65c39561776ce999eb9 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
|
@using System.Text.Json.Serialization
@using ArcaneLibs.Extensions
@using BugMine.Web.Classes.Exceptions
@using LibMatrix
@inject ILogger<ProjectContainer> Logger
@if (Constants.Debug) {
<details>
<summary>ProjectContainer Debug info - Debug build, here be dragons!</summary>
<p>ProjectContainer debug info:</p>
<pre>Slug: @ProjectSlug</pre>
<pre>Progress: @Progress.ToString()</pre>
@if (ProjectContext is null) {
<pre>ProjectContext is null!</pre>
}
else {
<details>
<summary>Context json dump</summary>
<pre>@ProjectContext.ToJson()</pre>
</details>
@if (ProjectContext?.Project?.Room is not null) {
<LinkButton OnClick="@ProjectContext.Project.Room.PermanentlyBrickRoomAsync">Dispose room</LinkButton>
}
}
</details>
<hr/>
}
@if (ProjectContext.Client is null) {
<p>Authenticating</p>
}
else if (ProjectContext?.Project is null) {
@if (Progress == Status.Loading) {
<p>Loading project <SimpleSpinner/></p>
}
else if (Progress == Status.NotInRoom) {
<p>You are not in the project room.</p>
<p>You must join before you can view or interact with this project.</p>
<LinkButton OnClick="TryJoin">Attempt to join</LinkButton>
}
else if (Progress == Status.RoomNotFound) {
<p>Project not found.</p>
<p>If you believe this is an error, please contact the project in order to obtain a new room.</p>
}
}
else {
<CascadingValue Value="ProjectContext">
@ChildContent
</CascadingValue>
}
@code {
private Status? _progress = Status.Loading;
[Parameter]
public string ProjectSlug { get; set; } = null!;
[Parameter]
public ProjectContainerContext? ProjectContext { get; set; }
[Parameter]
public RenderFragment ChildContent { get; set; }
[Parameter]
public Func<Task>? Loaded { get; set; }
private Status? Progress {
get => _progress;
set {
_progress = value;
StateHasChanged();
}
}
protected override async Task OnInitializedAsync() {
if (ProjectContext is null) {
Logger.LogError("ProjectContext is null");
ProjectContext = new();
}
if (ProjectContext.Project != null) {
Logger.LogWarning("ProjectContext.Project is not null");
}
ProjectContext.Client ??= await BugMineStorage.GetCurrentSessionOrNavigate();
if (ProjectContext.Client == null) {
return;
}
Progress = Status.Loading;
try {
ProjectContext.Project = await ProjectContext.Client.GetProject(ProjectSlug);
}
catch (MatrixException e) {
if (e.ErrorCode == BugMineException.ErrorCodes.UserNotInRoom) {
Progress = Status.NotInRoom;
return;
}
else if (e.ErrorCode == BugMineException.ErrorCodes.ProjectNotFound) {
Progress = Status.RoomNotFound;
return;
}
throw;
}
Progress = Status.Done;
if (Loaded != null) {
await Loaded.Invoke();
}
StateHasChanged();
}
private async Task TryJoin() {
var room = await ProjectContext.Client.ResolveProjectSlug(ProjectSlug);
bool success = false;
while (!success) {
try {
await room.JoinAsync();
if (!string.IsNullOrWhiteSpace(room.RoomId)) {
success = true;
}
else {
await Task.Delay(1000);
}
}
catch (MatrixException e) {
// if (e.ErrorCode == MatrixException.ErrorCodes.) {
// await Task.Delay(1000);
// continue;
// }
throw;
}
}
await OnInitializedAsync();
}
public class ProjectContainerContext {
public BugMineClient? Client { get; set; }
public BugMineProject? Project { get; set; }
}
private enum Status {
Loading,
NotInRoom,
RoomNotFound,
Done
}
}
|