From 63677f70bf0663ef3fae47b4fce64d9de7f428f4 Mon Sep 17 00:00:00 2001 From: Rory& Date: Tue, 9 Jul 2024 00:18:44 +0200 Subject: Older changes --- .../ScopedContainers/IssueContainer.razor | 101 ++++++++++++++ .../ScopedContainers/ProjectContainer.razor | 155 +++++++++++++++++++++ 2 files changed, 256 insertions(+) create mode 100644 BugMine.Web/Components/ScopedContainers/IssueContainer.razor create mode 100644 BugMine.Web/Components/ScopedContainers/ProjectContainer.razor (limited to 'BugMine.Web/Components/ScopedContainers') diff --git a/BugMine.Web/Components/ScopedContainers/IssueContainer.razor b/BugMine.Web/Components/ScopedContainers/IssueContainer.razor new file mode 100644 index 0000000..dac3e97 --- /dev/null +++ b/BugMine.Web/Components/ScopedContainers/IssueContainer.razor @@ -0,0 +1,101 @@ +@using System.Text.Json.Serialization +@using ArcaneLibs.Extensions +@using BugMine.Web.Classes.Exceptions +@using LibMatrix +@inject ILogger Logger + +@if (Constants.Debug) { +
+ IssueContainer Debug info - Debug build, here be dragons! +

IssueContainer debug info:

+ @*
Slug: @ProjectSlug
*@ + @*
Progress: @Progress.ToString()
*@ + @* @if (ProjectContext is null) { *@ + @*
ProjectContext is null!
*@ + @* } *@ + @* else { *@ + @*
*@ + @* Context json dump *@ + @*
@ProjectContext.ToJson()
*@ + @*
*@ + @* @if (ProjectContext?.Project?.Room is not null) { *@ + @* Dispose room *@ + @* } *@ + @* } *@ +
+ +
+} +@if (ProjectContext?.Client is null) { +

Authenticating

+} +else { + + @ChildContent + +} + +@code { + private Status? _progress = Status.Loading; + + [Parameter] + public string IssueId { get; set; } = null!; + + [Parameter, CascadingParameter] + public ProjectContainer.ProjectContainerContext? ProjectContext { get; set; } + + [Parameter] + public IssueContainerContext? IssueContext { get; set; } + + [Parameter] + public RenderFragment ChildContent { get; set; } + + [Parameter] + public Func? 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; + + + Progress = Status.Done; + if (Loaded != null) { + await Loaded.Invoke(); + } + + StateHasChanged(); + } + + public class IssueContainerContext { + public ProjectContainer.ProjectContainerContext ProjectContext { get; set; } + } + + private enum Status { + Loading, + NotInRoom, + RoomNotFound, + Done + } + +} \ No newline at end of file diff --git a/BugMine.Web/Components/ScopedContainers/ProjectContainer.razor b/BugMine.Web/Components/ScopedContainers/ProjectContainer.razor new file mode 100644 index 0000000..44578a7 --- /dev/null +++ b/BugMine.Web/Components/ScopedContainers/ProjectContainer.razor @@ -0,0 +1,155 @@ +@using System.Text.Json.Serialization +@using ArcaneLibs.Extensions +@using BugMine.Web.Classes.Exceptions +@using LibMatrix +@inject ILogger Logger + +@if (Constants.Debug) { +
+ ProjectContainer Debug info - Debug build, here be dragons! +

ProjectContainer debug info:

+
Slug: @ProjectSlug
+
Progress: @Progress.ToString()
+ @if (ProjectContext is null) { +
ProjectContext is null!
+ } + else { +
+ Context json dump +
@ProjectContext.ToJson()
+
+ @if (ProjectContext?.Project?.Room is not null) { + Dispose room + } + } +
+ +
+} +@if (ProjectContext.Client is null) { +

Authenticating

+} +else if (ProjectContext?.Project is null) { + @if (Progress == Status.Loading) { +

Loading project

+ } + else if (Progress == Status.NotInRoom) { +

You are not in the project room.

+

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

+ Attempt to join + } + else if (Progress == Status.RoomNotFound) { +

Project not found.

+

If you believe this is an error, please contact the project in order to obtain a new room.

+ } +} +else { + + @ChildContent + +} + +@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? 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 + } + +} \ No newline at end of file -- cgit 1.5.1