diff options
Diffstat (limited to 'MatrixRoomUtils.Web/Shared/IndexComponents')
-rw-r--r-- | MatrixRoomUtils.Web/Shared/IndexComponents/IndexUserItem.razor | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/MatrixRoomUtils.Web/Shared/IndexComponents/IndexUserItem.razor b/MatrixRoomUtils.Web/Shared/IndexComponents/IndexUserItem.razor new file mode 100644 index 0000000..cc6f9f6 --- /dev/null +++ b/MatrixRoomUtils.Web/Shared/IndexComponents/IndexUserItem.razor @@ -0,0 +1,49 @@ +@using MatrixRoomUtils.Authentication +@using MatrixRoomUtils.Web.Classes +@using System.Text.Json +@using Blazored.LocalStorage +@using MatrixRoomUtils.Extensions +@using Index = MatrixRoomUtils.Web.Pages.Index +@inject ILocalStorageService LocalStorage +@inject NavigationManager NavigationManager + +<div style="margin-bottom: 1em;"> + <img style="border-radius: 50%; height: 3em; width: 3em;" src="@_avatarUrl"/> + <span style="margin-left: 1em;"><input type="radio" name="csa" checked="@(RuntimeStorage.AccessToken == Token)" onclick="@SetCurrent" style="text-decoration-line: unset;"/> <b>@User.Profile.DisplayName</b> on <b>@User.LoginResponse.HomeServer</b></span> + <a href="#" onclick="@RemoveUser">Remove</a> +</div> + +@code { + [Parameter] + public string Token { get; set; } + [Parameter] + public UserInfo User { get; set; } + + 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(); + else _avatarUrl = "https://api.dicebear.com/6.x/identicon/svg?seed=" + User.LoginResponse.UserId; + await base.OnInitializedAsync(); + } + + private async Task RemoveUser() + { + RuntimeStorage.UsersCache.Remove(Token); + await RuntimeStorage.SaveToLocalStorage(LocalStorage); + _removed = true; + + StateHasChanged(); + } + private async Task SetCurrent() + { + RuntimeStorage.AccessToken = Token; + RuntimeStorage.CurrentHomeserver = await MatrixAccount.ResolveHomeserverFromWellKnown(RuntimeStorage.UsersCache[Token].LoginResponse.HomeServer); + await RuntimeStorage.SaveToLocalStorage(LocalStorage); + + StateHasChanged(); + } +} \ No newline at end of file |