about summary refs log tree commit diff
path: root/BugMine.Web/Pages/Projects/Index.razor
blob: eaf8dc1031bc0c51e9f3e0caacd9b7311700dac2 (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
@page "/Projects"
@using LibMatrix.Homeservers
<h3>Projects</h3>

@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 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 async Task Navigate(BugMineProject project) {
        Console.WriteLine($"Navigating to {project.ProjectSlug}");
        NavigationManager.NavigateTo($"/Projects/{project.ProjectSlug}/");
    }

}