From 3054b456dcb54f069a5d8aaa615c1dfe060eef9b Mon Sep 17 00:00:00 2001 From: Rory& Date: Thu, 25 Apr 2024 06:31:52 +0200 Subject: Add projects logic, start of issues --- BugMine.Web/Pages/Projects/Index.razor | 17 ++++- BugMine.Web/Pages/Projects/ViewProject.razor | 95 ++++++++++++++++++++++++++-- 2 files changed, 102 insertions(+), 10 deletions(-) (limited to 'BugMine.Web/Pages/Projects') 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

Projects

-@if (Projects.Count == 0) { +@if (Client == null) { +

Authenticating...

+} +else if (Projects is null) { +

Loading projects...

+} +else if (Projects.Count == 0) {

There are no projects to display.

} else { @@ -28,7 +34,7 @@ else { @code { private BugMineClient? Client { get; set; } - private List Projects { get; set; } = []; + private List? 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 @if (Client is null) {

Authenticating

} -else if(Project is null) { -

Loading

+else if (Project is null) { + @if (Progress == "loading") { +

Loading project

+ } + else if (Progress == "not-in-room") { +

You are not in the project room.

+

You must join before you can view or interact with this project.

+ Attempt to join + } } else {

@Project.Info.Name

+ + @if (Constants.Debug) { +

Debug, beware: here be dragons!

+ Dispose room + } + + @if (Progress == "loading-issues") { +

Loading issues, got @(Issues?.Count ?? 0) so far...

+ } @*

@Project.Description

*@ } @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? 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(); + 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(); + } + +} + -- cgit 1.5.1