From b48f78a381058c188ed61e6f372fbf86d95ad2f9 Mon Sep 17 00:00:00 2001 From: TheArcaneBrony Date: Wed, 14 Jun 2023 22:26:39 +0200 Subject: Add changes --- MatrixRoomUtils.Web/Shared/RoomList.razor | 56 ++++++++++++++++++++++ MatrixRoomUtils.Web/Shared/RoomList.razor.css | 8 ++++ .../RoomListComponents/RoomListCategory.razor | 24 ++++++++++ .../Shared/RoomListComponents/RoomListSpace.razor | 42 ++++++++++++++++ MatrixRoomUtils.Web/Shared/RoomListItem.razor | 6 +-- .../Shared/SimpleComponents/FancyTextBox.razor | 2 +- .../Shared/SimpleComponents/FancyTextBox.razor.css | 5 ++ .../Shared/SimpleComponents/LinkButton.razor | 13 +++++ 8 files changed, 151 insertions(+), 5 deletions(-) create mode 100644 MatrixRoomUtils.Web/Shared/RoomList.razor create mode 100644 MatrixRoomUtils.Web/Shared/RoomList.razor.css create mode 100644 MatrixRoomUtils.Web/Shared/RoomListComponents/RoomListCategory.razor create mode 100644 MatrixRoomUtils.Web/Shared/RoomListComponents/RoomListSpace.razor create mode 100644 MatrixRoomUtils.Web/Shared/SimpleComponents/FancyTextBox.razor.css create mode 100644 MatrixRoomUtils.Web/Shared/SimpleComponents/LinkButton.razor (limited to 'MatrixRoomUtils.Web/Shared') diff --git a/MatrixRoomUtils.Web/Shared/RoomList.razor b/MatrixRoomUtils.Web/Shared/RoomList.razor new file mode 100644 index 0000000..ca93fa6 --- /dev/null +++ b/MatrixRoomUtils.Web/Shared/RoomList.razor @@ -0,0 +1,56 @@ +@using MatrixRoomUtils.Web.Shared.RoomListComponents; +

@Rooms.Count rooms total, @RoomsWithTypes.Sum(x=>x.Value.Count) fetched so far...

+@foreach (var category in RoomsWithTypes.OrderBy(x => x.Value.Count)) { + +} + +@code { + + [Parameter] + public List Rooms { get; set; } + + Dictionary> RoomsWithTypes = new(); + + protected override async Task OnInitializedAsync() { + if (RoomsWithTypes.Any()) return; + + await LocalStorageWrapper.LoadFromLocalStorage(LocalStorage); + + var tasks = Rooms.Select(AddRoom); + await Task.WhenAll(tasks); + + await base.OnInitializedAsync(); + } + + private string GetRoomTypeName(string? roomType) => roomType switch { + "m.space" => "Space", + "msc3588.stories.stories-room" => "Story room", + null => "Room", + _ => roomType + }; + + + private static SemaphoreSlim _semaphoreSlim = new SemaphoreSlim(8, 8); + private async Task AddRoom(Room room) { + await _semaphoreSlim.WaitAsync(); + var roomType = GetRoomTypeName(await room.GetRoomType()); + + if (roomType == "Room") { + var shortcodeState = await room.GetStateAsync("org.matrix.mjolnir.shortcode"); + if (shortcodeState.HasValue) roomType = "Legacy policy room"; + } + + if (!RoomsWithTypes.ContainsKey(roomType)) { + RoomsWithTypes.Add(roomType, new List()); + } + RoomsWithTypes[roomType].Add(room); + + // if (RoomsWithTypes.Count % 10 == 0) + StateHasChanged(); + await Task.Delay(100); + _semaphoreSlim.Release(); + } + + private bool _isSpaceChildrenOpen = false; + +} \ No newline at end of file diff --git a/MatrixRoomUtils.Web/Shared/RoomList.razor.css b/MatrixRoomUtils.Web/Shared/RoomList.razor.css new file mode 100644 index 0000000..a159305 --- /dev/null +++ b/MatrixRoomUtils.Web/Shared/RoomList.razor.css @@ -0,0 +1,8 @@ +.room-list-item { + background-color: #ffffff11; + border-radius: 0.5em; + display: block; + margin-top: 4px; + padding: 4px; + width: fit-content; +} \ No newline at end of file diff --git a/MatrixRoomUtils.Web/Shared/RoomListComponents/RoomListCategory.razor b/MatrixRoomUtils.Web/Shared/RoomListComponents/RoomListCategory.razor new file mode 100644 index 0000000..ecdcc68 --- /dev/null +++ b/MatrixRoomUtils.Web/Shared/RoomListComponents/RoomListCategory.razor @@ -0,0 +1,24 @@ +
+ @roomType (@rooms.Count) + @foreach (var room in rooms) { +
+ + View timeline + + @if (roomType == "Space") { + + } +
+ } +
+
+ +@code { + + [Parameter] + public KeyValuePair> Category { get; set; } + + private string roomType => Category.Key; + private List rooms => Category.Value; + +} \ No newline at end of file diff --git a/MatrixRoomUtils.Web/Shared/RoomListComponents/RoomListSpace.razor b/MatrixRoomUtils.Web/Shared/RoomListComponents/RoomListSpace.razor new file mode 100644 index 0000000..c90ae8f --- /dev/null +++ b/MatrixRoomUtils.Web/Shared/RoomListComponents/RoomListSpace.razor @@ -0,0 +1,42 @@ +Manage space + +
+
+ @Children.Count children + @if (_shouldRenderChildren) { +

Breadcrumb: @Breadcrumbs

+
+ +
+ } +
+ +@code { + + [Parameter] + public Room Space { get; set; } + + [Parameter, CascadingParameter] + public string? Breadcrumbs { + get => _breadcrumbs + Space.RoomId; + set => _breadcrumbs = value; + } + + private List Children { get; set; } = new(); + + protected override async Task OnInitializedAsync() { + if (Breadcrumbs == null) throw new ArgumentNullException(nameof(Breadcrumbs)); + Children = (await Space.AsSpace.GetRoomsAsync()).Where(x => !Breadcrumbs.Contains(x.RoomId)).ToList(); + await base.OnInitializedAsync(); + } + + private bool _shouldRenderChildren = false; + private string? _breadcrumbs; + + private async Task SpaceChildrenOpened() { + if (_shouldRenderChildren) return; + _shouldRenderChildren = true; + Console.WriteLine($"[RoomList] Rendering children of {Space.RoomId}"); + } + +} \ No newline at end of file diff --git a/MatrixRoomUtils.Web/Shared/RoomListItem.razor b/MatrixRoomUtils.Web/Shared/RoomListItem.razor index f58ab3a..6dc0683 100644 --- a/MatrixRoomUtils.Web/Shared/RoomListItem.razor +++ b/MatrixRoomUtils.Web/Shared/RoomListItem.razor @@ -2,7 +2,7 @@ @using System.Text.Json
@if (ShowOwnProfile) { - + @(profileName ?? "Loading...") -> } @@ -51,7 +51,7 @@ await _semaphoreSlim.WaitAsync(); - var hs = RuntimeCache.CurrentHomeServer; //await new AuthenticatedHomeServer(RuntimeCache.CurrentHomeServer.UserId, RuntimeCache.CurrentHomeServer.AccessToken, RuntimeCache.CurrentHomeServer.HomeServerDomain).Configure(); + var hs = RuntimeCache.CurrentHomeServer; if (Room == null) { if (RoomId == null) { @@ -119,6 +119,4 @@ await LocalStorageWrapper.SaveCacheToLocalStorage(LocalStorage); } - private void Callback(ProgressEventArgs obj) => Console.WriteLine("prog: " + obj.ToJson(false)); - } \ No newline at end of file diff --git a/MatrixRoomUtils.Web/Shared/SimpleComponents/FancyTextBox.razor b/MatrixRoomUtils.Web/Shared/SimpleComponents/FancyTextBox.razor index d17d0de..966c44d 100644 --- a/MatrixRoomUtils.Web/Shared/SimpleComponents/FancyTextBox.razor +++ b/MatrixRoomUtils.Web/Shared/SimpleComponents/FancyTextBox.razor @@ -3,7 +3,7 @@ } else { - @(Formatter?.Invoke(Value) ?? (IsPassword ? string.Join("", Value.Select(x => '*')) : Value)) + @(Formatter?.Invoke(Value) ?? (IsPassword ? string.Join("", Value.Select(x => '*')) : Value)) } @code { diff --git a/MatrixRoomUtils.Web/Shared/SimpleComponents/FancyTextBox.razor.css b/MatrixRoomUtils.Web/Shared/SimpleComponents/FancyTextBox.razor.css new file mode 100644 index 0000000..01b2c6f --- /dev/null +++ b/MatrixRoomUtils.Web/Shared/SimpleComponents/FancyTextBox.razor.css @@ -0,0 +1,5 @@ +.fancy-textbox-inline { + border-bottom: #ccc solid 1px; + height: 1.4em; + display: inline-block; +} \ No newline at end of file diff --git a/MatrixRoomUtils.Web/Shared/SimpleComponents/LinkButton.razor b/MatrixRoomUtils.Web/Shared/SimpleComponents/LinkButton.razor new file mode 100644 index 0000000..8c9e73b --- /dev/null +++ b/MatrixRoomUtils.Web/Shared/SimpleComponents/LinkButton.razor @@ -0,0 +1,13 @@ + + @ChildContent + + +@code { + + [Parameter] + public string href { get; set; } + + [Parameter] + public RenderFragment ChildContent { get; set; } + +} \ No newline at end of file -- cgit 1.5.1