about summary refs log tree commit diff
path: root/MatrixUtils.Web/Pages/Rooms/Index2.razor
blob: ae3112647ce51ec1002e7281ce03f7cc91209f0b (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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
@page "/Rooms2"
@using LibMatrix.Responses
@using System.Collections.ObjectModel
@using System.ComponentModel
@using MatrixUtils.Abstractions
@using MatrixUtils.Web.Pages.Rooms.Index2Components
@inject ILogger<Index> logger
<h3>Room list</h3>

<RoomsIndex2SyncContainer Data="@Data"></RoomsIndex2SyncContainer>
@if (Data.Homeserver is null || Data.GlobalProfile is null) {
    <p>Creating homeserver instance and fetching global profile...</p>
    return;
}

<div>
    <LinkButton Color="@(SelectedTab == Tab.Main ? null : "#0b0e62")" OnClick="() => Task.FromResult(SelectedTab = Tab.Main)">Main</LinkButton>
    <LinkButton Color="@(SelectedTab == Tab.DMs ? null : "#0b0e62")" OnClick="() => Task.FromResult(SelectedTab = Tab.DMs)">DMs</LinkButton>
    <LinkButton Color="@(SelectedTab == Tab.ByRoomType ? null : "#0b0e62")" OnClick="() => Task.FromResult(SelectedTab = Tab.ByRoomType)">By room type</LinkButton>
</div>
<br/>
<CascadingValue Value="@Data">
    @switch (SelectedTab) {
        case Tab.Main:
            <h3>Main tab</h3>
            <RoomsIndex2MainTab></RoomsIndex2MainTab>
            break;
        case Tab.DMs:
            <h3>DMs tab</h3>
            break;
        case Tab.ByRoomType:
            <h3>By room type tab</h3>
            break;
        default:
            throw new InvalidEnumArgumentException();
    }
</CascadingValue>
<br/>

@* <LinkButton href="/Rooms/Create">Create new room</LinkButton> *@


@code {

    private Tab SelectedTab {
        get => _selectedTab;
        set {
            _selectedTab = value;
            StateHasChanged();
        }
    }

    public RoomListViewData Data { get; set; } = new RoomListViewData();

    protected override async Task OnInitializedAsync() {
        Data.Homeserver = await RMUStorage.GetCurrentSessionOrNavigate();
        if (Data.Homeserver is null) return;
        var rooms = await Data.Homeserver.GetJoinedRooms();
        Data.GlobalProfile = await Data.Homeserver.GetProfileAsync(Data.Homeserver.WhoAmI.UserId);
        
        foreach (var room in rooms) {
            Data.Rooms.Add(new RoomInfo(room));
        }
        StateHasChanged();
        
        await base.OnInitializedAsync();
    }

    private Tab _selectedTab = Tab.Main;

    private enum Tab {
        Main,
        DMs,
        ByRoomType
    }

    public class RoomListViewData {
        public ObservableCollection<RoomInfo> Rooms { get; } = [];

        public UserProfileResponse? GlobalProfile { get; set; }

        public AuthenticatedHomeserverGeneric? Homeserver { get; set; }
    }

}