From b933f7ed1189c7e14d82b4fcf5c98fb3ef4b9cf1 Mon Sep 17 00:00:00 2001 From: TheArcaneBrony Date: Thu, 4 May 2023 00:13:25 +0200 Subject: Refactoring --- .../Shared/IndexComponents/IndexUserItem.razor | 19 ++++++++++--------- MatrixRoomUtils.Web/Shared/LogView.razor | 11 ++++++----- MatrixRoomUtils.Web/Shared/MainLayout.razor | 5 ++--- 3 files changed, 18 insertions(+), 17 deletions(-) (limited to 'MatrixRoomUtils.Web/Shared') diff --git a/MatrixRoomUtils.Web/Shared/IndexComponents/IndexUserItem.razor b/MatrixRoomUtils.Web/Shared/IndexComponents/IndexUserItem.razor index d0fb2f0..08161b2 100644 --- a/MatrixRoomUtils.Web/Shared/IndexComponents/IndexUserItem.razor +++ b/MatrixRoomUtils.Web/Shared/IndexComponents/IndexUserItem.razor @@ -1,44 +1,45 @@ -@using MatrixRoomUtils.Authentication @using MatrixRoomUtils.Web.Classes @using System.Text.Json @using Blazored.LocalStorage -@using MatrixRoomUtils.Extensions +@using MatrixRoomUtils.Core +@using MatrixRoomUtils.Core.Extensions @using Index = MatrixRoomUtils.Web.Pages.Index +@using System.ComponentModel.DataAnnotations @inject ILocalStorageService LocalStorage @inject NavigationManager NavigationManager
- @User.Profile.DisplayName on @User.LoginResponse.HomeServer + @User.Profile.DisplayName on @User.LoginResponse.HomeServer Remove
@code { + [Parameter] - public UserInfo User { get; set; } + public UserInfo User { get; set; } = null!; private string _avatarUrl { get; set; } - private bool _removed { get; set; } = false; protected override async Task OnInitializedAsync() { - if(User.Profile.AvatarUrl != null && User.Profile.AvatarUrl != "") - _avatarUrl = await User.Profile.AvatarUrl.GetMediaUrl(); + if (User.Profile.AvatarUrl != null && User.Profile.AvatarUrl != "") + _avatarUrl = await (await new AuthenticatedHomeServer(User.LoginResponse.UserId, User.AccessToken, User.LoginResponse.HomeServer).Configure()).ResolveMediaUri(User.Profile.AvatarUrl); else _avatarUrl = "https://api.dicebear.com/6.x/identicon/svg?seed=" + User.LoginResponse.UserId; await base.OnInitializedAsync(); } private async Task RemoveUser() { + Console.WriteLine(User.ToJson()); RuntimeCache.LoginSessions.Remove(User.AccessToken); await LocalStorageWrapper.ReloadLocalStorage(LocalStorage); - _removed = true; StateHasChanged(); } private async Task SetCurrent() { - RuntimeCache.AccessToken = User.AccessToken; + RuntimeCache.LastUsedToken = User.AccessToken; //RuntimeCache.CurrentHomeserver = await MatrixAuth.ResolveHomeserverFromWellKnown(LocalStorageWrapper.LoginSessions[Token].LoginResponse.HomeServer); await LocalStorageWrapper.ReloadLocalStorage(LocalStorage); diff --git a/MatrixRoomUtils.Web/Shared/LogView.razor b/MatrixRoomUtils.Web/Shared/LogView.razor index fbe5264..f60f271 100644 --- a/MatrixRoomUtils.Web/Shared/LogView.razor +++ b/MatrixRoomUtils.Web/Shared/LogView.razor @@ -1,15 +1,15 @@ @using System.Text Logs
-    @sb
+    @_stringBuilder
 
@code { - StringBuilder sb = new(); + StringBuilder _stringBuilder = new(); protected override void OnInitialized() { //intecept stdout with textwriter to get logs - var sw = new StringWriter(sb); + var sw = new StringWriter(_stringBuilder); Console.SetOut(sw); Console.SetError(sw); //keep updated @@ -19,12 +19,13 @@ while (true) { await Task.Delay(100); - if (sb.Length != length) + if (_stringBuilder.Length != length) { StateHasChanged(); - length = sb.Length; + length = _stringBuilder.Length; } } + // ReSharper disable once FunctionNeverReturns - This is intentional behavior }); base.OnInitialized(); } diff --git a/MatrixRoomUtils.Web/Shared/MainLayout.razor b/MatrixRoomUtils.Web/Shared/MainLayout.razor index 055cec7..4aa01c6 100644 --- a/MatrixRoomUtils.Web/Shared/MainLayout.razor +++ b/MatrixRoomUtils.Web/Shared/MainLayout.razor @@ -1,6 +1,4 @@ @inherits LayoutComponentBase -@inject ILocalStorageService LocalStorage -@inject NavigationManager NavigationManager