about summary refs log tree commit diff
path: root/BugMine.Web/Pages/Projects
diff options
context:
space:
mode:
authorRory& <root@rory.gay>2024-04-20 23:48:43 +0200
committerRory& <root@rory.gay>2024-04-20 23:48:43 +0200
commit68fe1a2284045908d92ef06c1c26cd937ded784e (patch)
tree71144f404f060888dcc5e4036e038abe857adc4e /BugMine.Web/Pages/Projects
parentStart adding pages (diff)
downloadBugMine-68fe1a2284045908d92ef06c1c26cd937ded784e.tar.xz
Add basic project management
Diffstat (limited to 'BugMine.Web/Pages/Projects')
-rw-r--r--BugMine.Web/Pages/Projects/Index.razor44
-rw-r--r--BugMine.Web/Pages/Projects/Index.razor.css26
-rw-r--r--BugMine.Web/Pages/Projects/NewProject.razor36
-rw-r--r--BugMine.Web/Pages/Projects/ViewProject.razor33
4 files changed, 125 insertions, 14 deletions
diff --git a/BugMine.Web/Pages/Projects/Index.razor b/BugMine.Web/Pages/Projects/Index.razor
index a24747c..eaf8dc1 100644
--- a/BugMine.Web/Pages/Projects/Index.razor
+++ b/BugMine.Web/Pages/Projects/Index.razor
@@ -1,22 +1,52 @@
 @page "/Projects"
+@using LibMatrix.Homeservers
 <h3>Projects</h3>
 
-@if (true) {
+@if (Projects.Count == 0) {
     <p>There are no projects to display.</p>
 }
+else {
+    <div class="projects">
+        @foreach (var project in Projects) {
+            <div class="card project-card" @onclick="@(()=>Navigate(project))">
+                @if (string.IsNullOrWhiteSpace(project.Info.ProjectIcon)) {
+                    <img class="project-icon" src="/icon-512.png">
+                }
+                else {
+                    <img class="project-icon" src="/icon-512.png">
+                }
+                <span class="project-name">@project.Info.Name</span>
+            </div>
+            @* <p>@project.Info.Name</p> *@
+        }
+    </div>
+}
 
 <p>Did not find the project board you are looking for?</p>
 <LinkButton href="/Projects/New">Create new board</LinkButton>
 
 @code {
 
-    private List<Project> projects = new List<Project>();
-
-    
+    private BugMineClient? Client { get; set; }
+    private List<BugMineProject> Projects { get; set; } = [];
+    private CancellationTokenSource? _cts = new();
 
     protected override async Task OnInitializedAsync() {
-        
+        Client = await BugMineStorage.GetCurrentSessionOrNavigate();
+        if (Client == null) {
+            return;
+        }
+
+        await foreach (var project in Client.GetProjects()) {
+            Projects.Add(project);
+            StateHasChanged();
+            // await Task.Delay(100);
+        }
     }
-    
-    private class Project { }
+
+    private async Task Navigate(BugMineProject project) {
+        Console.WriteLine($"Navigating to {project.ProjectSlug}");
+        NavigationManager.NavigateTo($"/Projects/{project.ProjectSlug}/");
+    }
+
 }
\ No newline at end of file
diff --git a/BugMine.Web/Pages/Projects/Index.razor.css b/BugMine.Web/Pages/Projects/Index.razor.css
new file mode 100644
index 0000000..20d8c4d
--- /dev/null
+++ b/BugMine.Web/Pages/Projects/Index.razor.css
@@ -0,0 +1,26 @@
+.projects {
+    display: grid;
+    grid-template-columns: repeat(auto-fill, minmax(20rem, 1fr));
+    gap: 1rem;
+    padding-bottom: 1rem;
+}
+
+.project-card {
+    display: flex;
+    padding: 1rem;
+    border-radius: 0.5rem;
+    background-color: var(--bs-dark);
+    box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.5);
+    transition: background-color 1s, box-shadow 3s;
+}
+
+.project-icon {
+    border-radius: 50%;
+    width: 2rem;
+    height: 2rem;
+    margin-right: 1rem;
+}
+
+.project-name {
+    display: inline;
+}
\ No newline at end of file
diff --git a/BugMine.Web/Pages/Projects/NewProject.razor b/BugMine.Web/Pages/Projects/NewProject.razor
index 529813e..00b7b21 100644
--- a/BugMine.Web/Pages/Projects/NewProject.razor
+++ b/BugMine.Web/Pages/Projects/NewProject.razor
@@ -1,25 +1,47 @@
 @page "/Projects/New"
-@using LibMatrix.Responses
-@using BugMine.Web.Classes
 @using ArcaneLibs.Extensions
 <h3>New project</h3>
 
 <span>Project name: </span>
-<FancyTextBox bind-Value="@request.Name"></FancyTextBox>
+<FancyTextBox @bind-Value="@_request.Name"></FancyTextBox>
 <br/>
-<span>Shortname: </span>
-<FancyTextBox bind-Value="@request.RoomAliasName"></FancyTextBox>
+<span>Project repository: </span>
+<FancyTextBox @bind-Value="@_request.Repository"></FancyTextBox>
 <br/>
+@* <span>Room alias: </span> *@
+@* <FancyTextBox @bind-Value="@_request."></FancyTextBox> *@
+@* <br/> *@
 
 @if (Constants.Debug) {
     <span>Debug: </span>
     <pre>
-        @request.ToJson()
+        @_request.ToJson()
     </pre>
     <br/>
 }
 
+<LinkButton OnClick="@CreateProject">Create project</LinkButton>
+
 @code {
-    private CreateRoomRequest request = new CreateRoomRequest();
+
+    private BugMineClient? Client { get; set; }
+
+    private readonly ProjectInfo _request = new();
+
+    protected override async Task OnInitializedAsync() {
+        Client = await BugMineStorage.GetCurrentSessionOrNavigate();
+        if (Client == null) {
+            return;
+        }
+    }
+
+    private async Task CreateProject() {
+        if (Client == null) {
+            return;
+        }
+
+        var proj = await Client.CreateProject(_request);
+        NavigationManager.NavigateTo($"/Projects/{proj.ProjectSlug}/");
+    }
 
 }
\ No newline at end of file
diff --git a/BugMine.Web/Pages/Projects/ViewProject.razor b/BugMine.Web/Pages/Projects/ViewProject.razor
new file mode 100644
index 0000000..de94c79
--- /dev/null
+++ b/BugMine.Web/Pages/Projects/ViewProject.razor
@@ -0,0 +1,33 @@
+@page "/Projects/{ProjectSlug}/"
+
+<ProgressLog ></ProgressLog>
+
+@if (Client is null) {
+    <p>Authenticating</p>
+}
+else if(Project is null) {
+    <p>Loading</p>
+}
+else {
+    <h1>@Project.Info.Name</h1>
+    @* <p>@Project.Description</p> *@
+}
+
+@code {
+    [Parameter] public string ProjectSlug { get; set; }
+    
+    private BugMineClient? Client { get; set; }
+
+    private BugMineProject? Project { get; set; }
+
+    protected override async Task OnInitializedAsync() {
+        Client = await BugMineStorage.GetCurrentSessionOrNavigate();
+        if (Client == null) {
+            return;
+        }
+        StateHasChanged();
+        
+        Project = await Client.GetProject(ProjectSlug);
+    }
+
+}
\ No newline at end of file