about summary refs log tree commit diff
path: root/MatrixUtils.Web/Pages/Rooms/Index2Components/RoomsIndex2ByRoomTypeTab.razor
blob: f4cf849a2237b228bb6eadd8c1d07b6e3efa94f8 (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
@using MatrixUtils.Abstractions
@using System.Security.Cryptography
@using ArcaneLibs.Extensions
<h3>RoomsIndex2MainTab</h3>

<div>
    <div class="row">
        <div class="col-3" style="background-color: #ffffff66;">
            <LinkButton>Uncategorised rooms</LinkButton>
            @foreach (var space in Data.Rooms.Where(x => x.RoomType == "m.space")) {
                <div style="@("width: 100%; height: 50px; background-color: #" + RandomNumberGenerator.GetBytes(3).Append((byte)0x11).ToArray().AsHexString().Replace(" ",""))">
                    <p>@space.RoomName</p>
                </div>
            }
        </div>
        <div class="col-9" style="background-color: #ff00ff66;">
            <p>omae wa mou shindeiru</p>
        </div>
    </div>
</div>

@code {

    [CascadingParameter]
    public Index2.RoomListViewData Data { get; set; } = null!;

    protected override async Task OnInitializedAsync() {
        Data.Rooms.CollectionChanged += (sender, args) => {
            DebouncedStateHasChanged();
            if (args.NewItems is { Count: > 0 })
                foreach (var newItem in args.NewItems) {
                    (newItem as RoomInfo).PropertyChanged += (sender, args) => { DebouncedStateHasChanged(); };
                }
        };
        await base.OnInitializedAsync();
    }

    //debounce StateHasChanged, we dont want to reredner on every key stroke

    private CancellationTokenSource _debounceCts = new CancellationTokenSource();

    private async Task DebouncedStateHasChanged() {
        _debounceCts.Cancel();
        _debounceCts = new CancellationTokenSource();
        try {
            await Task.Delay(100, _debounceCts.Token);
            Console.WriteLine("DebouncedStateHasChanged - Calling StateHasChanged!");
            StateHasChanged();
        }
        catch (TaskCanceledException) { }
    }

}