diff --git a/BugMine.Web/Classes/BugMineStorage.cs b/BugMine.Web/Classes/BugMineStorage.cs
index 73b46b5..3c838c7 100644
--- a/BugMine.Web/Classes/BugMineStorage.cs
+++ b/BugMine.Web/Classes/BugMineStorage.cs
@@ -74,7 +74,7 @@ public class BugMineStorage(
return session;
}
- public async Task<BugMineClient?> GetCurrentSessionOrNull() {
+ public async Task<BugMineClient?> GetCurrentSessionOrNull(bool navigateOnInvalid = true) {
BugMineClient? session = null;
try {
@@ -85,7 +85,7 @@ public class BugMineStorage(
if (e.ErrorCode == "M_UNKNOWN_TOKEN") {
var token = await GetCurrentToken();
logger.LogWarning("Encountered invalid token for {user} on {homeserver}", token.UserId, token.Homeserver);
- navigationManager.NavigateTo("/InvalidSession?ctx=" + token.AccessToken);
+ if (navigateOnInvalid) navigationManager.NavigateTo("/InvalidSession?ctx=" + token.AccessToken);
return null;
}
diff --git a/BugMine.Web/Components/IssueImportWorker.razor b/BugMine.Web/Components/IssueImportWorker.razor
index bc72156..b53daf7 100644
--- a/BugMine.Web/Components/IssueImportWorker.razor
+++ b/BugMine.Web/Components/IssueImportWorker.razor
@@ -15,7 +15,7 @@
private string Status { get; set; } = "";
protected override async Task OnInitializedAsync() {
while(Client == null) {
- Client = await BugMineStorage.GetCurrentSessionOrNull();
+ Client = await BugMineStorage.GetCurrentSessionOrNull(false);
if(Client == null) {
await Task.Delay(1000);
}
diff --git a/BugMine.Web/Pages/Auth/LegacyLogin.razor b/BugMine.Web/Pages/Auth/LegacyLogin.razor
index 5257028..eec381a 100644
--- a/BugMine.Web/Pages/Auth/LegacyLogin.razor
+++ b/BugMine.Web/Pages/Auth/LegacyLogin.razor
@@ -23,7 +23,7 @@
<br/>
<LinkButton OnClick="@(() => LoginWithAuth(authData))">Log in</LinkButton>
-<h4>Continue as guest</h4>
+<h4>Continue as guest (doesn't work)</h4>
<hr/>
<LinkButton OnClick="@(() => LoginWithAuth(new LoginStruct { Homeserver = "matrix.org", Username = "guest", Password = "guest" }))">Log in as guest</LinkButton>
diff --git a/BugMine.Web/Pages/Auth/Login.razor b/BugMine.Web/Pages/Auth/Login.razor
index 7b457ec..bea449e 100644
--- a/BugMine.Web/Pages/Auth/Login.razor
+++ b/BugMine.Web/Pages/Auth/Login.razor
@@ -61,7 +61,6 @@
Homeserver = await hsProvider.GetRemoteHomeserver(HomeserverName);
CurrentStage = await Homeserver.Auth.GetAvailableFlowsAsync(enableRegister: true, enableGuest: true);
-
StateHasChanged();
}
diff --git a/BugMine.Web/Pages/DevTools.razor b/BugMine.Web/Pages/DevTools.razor
index f8fc408..afed0cc 100644
--- a/BugMine.Web/Pages/DevTools.razor
+++ b/BugMine.Web/Pages/DevTools.razor
@@ -15,10 +15,10 @@
}
private async Task DestroyAllProjects() {
- var ss = new SemaphoreSlim(16, 16);
+ var ss = new SemaphoreSlim(4, 4);
await foreach (var proj in Client.Homeserver.GetJoinedRoomsByType(BugMineProject.RoomType)) {
- Task.Run(async () => {
- await ss.WaitAsync();
+ // Task.Run(async () => {
+ // await ss.WaitAsync();
await proj.SendStateEventAsync(RoomNameEventContent.EventId, new RoomNameEventContent() {
Name = "Disbanded BugMine project."
});
@@ -29,15 +29,15 @@
Alias = null
});
await proj.LeaveAsync("Disbanded room.");
- ss.Release();
- });
+ // ss.Release();
+ // });
}
}
private async Task MassCreateProjects() {
// var rooms = await Client.Homeserver.GetJoinedRooms();
// List<string> roomNames = (await Task.WhenAll(rooms.Select(x => x.GetNameAsync()))).Where(x => x != null).ToList();
- for (int i = 0; i < 5; i++) {
+ for (int i = 0; i < 20; i++) {
Task.Run(async () => {
// var randomName = roomNames[Random.Shared.Next(roomNames.Count)];
var proj = await Client.CreateProject(new() {
diff --git a/BugMine.Web/Pages/Projects/Index.razor b/BugMine.Web/Pages/Projects/Index.razor
index eaf8dc1..47c2f4a 100644
--- a/BugMine.Web/Pages/Projects/Index.razor
+++ b/BugMine.Web/Pages/Projects/Index.razor
@@ -2,7 +2,13 @@
@using LibMatrix.Homeservers
<h3>Projects</h3>
-@if (Projects.Count == 0) {
+@if (Client == null) {
+ <p>Authenticating... <SimpleSpinner/></p>
+}
+else if (Projects is null) {
+ <p>Loading projects... <SimpleSpinner/></p>
+}
+else if (Projects.Count == 0) {
<p>There are no projects to display.</p>
}
else {
@@ -28,7 +34,7 @@ else {
@code {
private BugMineClient? Client { get; set; }
- private List<BugMineProject> Projects { get; set; } = [];
+ private List<BugMineProject>? Projects { get; set; }
private CancellationTokenSource? _cts = new();
protected override async Task OnInitializedAsync() {
@@ -36,12 +42,17 @@ else {
if (Client == null) {
return;
}
-
+ StateHasChanged();
+
await foreach (var project in Client.GetProjects()) {
+ Projects ??= [];
Projects.Add(project);
StateHasChanged();
// await Task.Delay(100);
}
+
+ Projects ??= [];
+ StateHasChanged();
}
private async Task Navigate(BugMineProject project) {
diff --git a/BugMine.Web/Pages/Projects/ViewProject.razor b/BugMine.Web/Pages/Projects/ViewProject.razor
index de94c79..a778728 100644
--- a/BugMine.Web/Pages/Projects/ViewProject.razor
+++ b/BugMine.Web/Pages/Projects/ViewProject.razor
@@ -1,33 +1,114 @@
@page "/Projects/{ProjectSlug}/"
+@using LibMatrix
+@using BugMine.Web.Classes.Exceptions
<ProgressLog ></ProgressLog>
@if (Client is null) {
<p>Authenticating</p>
}
-else if(Project is null) {
- <p>Loading</p>
+else if (Project is null) {
+ @if (Progress == "loading") {
+ <p>Loading project <SimpleSpinner/></p>
+ }
+ else if (Progress == "not-in-room") {
+ <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 {
<h1>@Project.Info.Name</h1>
+
+ @if (Constants.Debug) {
+ <p>Debug, beware: here be dragons!</p>
+ <LinkButton OnClick="@Project.Room.PermanentlyBrickRoomAsync">Dispose room</LinkButton>
+ }
+
+ @if (Progress == "loading-issues") {
+ <p>Loading issues, got @(Issues?.Count ?? 0) so far... <SimpleSpinner/></p>
+ }
@* <p>@Project.Description</p> *@
}
@code {
- [Parameter] public string ProjectSlug { get; set; }
-
+ private string? _progress = "loading";
+
+ [Parameter]
+ public string ProjectSlug { get; set; } = null!;
+
private BugMineClient? Client { get; set; }
private BugMineProject? Project { get; set; }
+
+ private List<BugMineIssue>? Issues { get; set; }
+
+ private string? Progress {
+ get => _progress;
+ set {
+ _progress = value;
+ StateHasChanged();
+ }
+ }
protected override async Task OnInitializedAsync() {
- Client = await BugMineStorage.GetCurrentSessionOrNavigate();
+ Client ??= await BugMineStorage.GetCurrentSessionOrNavigate();
if (Client == null) {
return;
}
+
+ Progress = "loading";
StateHasChanged();
+
+ try {
+ Project = await Client.GetProject(ProjectSlug);
+ }
+ catch (MatrixException e) {
+ if (e.ErrorCode == BugMineException.ErrorCodes.UserNotInRoom) {
+ Progress = "not-in-room";
+ StateHasChanged();
+ return;
+ }
+
+ throw;
+ }
- Project = await Client.GetProject(ProjectSlug);
+ Progress = "loading-issues";
+ await foreach (var issue in Project.GetIssues()) {
+ Issues ??= new List<BugMineIssue>();
+ Issues.Add(issue);
+ StateHasChanged();
+ }
+
+
+ StateHasChanged();
}
-}
\ No newline at end of file
+ private async Task TryJoin() {
+ var room = await 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();
+ }
+
+}
+
|