From 602b86ee94f2deb5361cc215f5010cff7d1d9de4 Mon Sep 17 00:00:00 2001 From: Andrii Voznesenskyi Date: Thu, 10 Oct 2024 22:40:59 +0200 Subject: [PATCH] (#431) wasm: update show account components --- .../Pages/Account/GalleryComponent.razor | 2 +- .../Account/NotificationsComponent.razor | 2 +- .../Pages/Account/PrivacyComponent.razor | 2 +- .../Pages/Account/ProfileComponent.razor | 2 +- .../Pages/Account/SecurityComponent.razor | 2 +- .../Pages/Account/ShowAccountOLD.razor | 293 ------------------ .../Pages/Account/UserSettingsComponent.razor | 2 +- 7 files changed, 6 insertions(+), 299 deletions(-) delete mode 100644 MiniSpace.Web/src/Astravent.Web.Wasm/Pages/Account/ShowAccountOLD.razor diff --git a/MiniSpace.Web/src/Astravent.Web.Wasm/Pages/Account/GalleryComponent.razor b/MiniSpace.Web/src/Astravent.Web.Wasm/Pages/Account/GalleryComponent.razor index 5784785c8..047635253 100644 --- a/MiniSpace.Web/src/Astravent.Web.Wasm/Pages/Account/GalleryComponent.razor +++ b/MiniSpace.Web/src/Astravent.Web.Wasm/Pages/Account/GalleryComponent.razor @@ -7,7 +7,7 @@ @using MudBlazor @using System.IO -Gallery +Gallery @if (IsLoading) { diff --git a/MiniSpace.Web/src/Astravent.Web.Wasm/Pages/Account/NotificationsComponent.razor b/MiniSpace.Web/src/Astravent.Web.Wasm/Pages/Account/NotificationsComponent.razor index 0c38adf88..4eebcd3c9 100644 --- a/MiniSpace.Web/src/Astravent.Web.Wasm/Pages/Account/NotificationsComponent.razor +++ b/MiniSpace.Web/src/Astravent.Web.Wasm/Pages/Account/NotificationsComponent.razor @@ -6,7 +6,7 @@ @using MudBlazor @using System.Text.Json -Notifications +Notifications @if (IsLoading) { diff --git a/MiniSpace.Web/src/Astravent.Web.Wasm/Pages/Account/PrivacyComponent.razor b/MiniSpace.Web/src/Astravent.Web.Wasm/Pages/Account/PrivacyComponent.razor index da961d497..e8a06fcbf 100644 --- a/MiniSpace.Web/src/Astravent.Web.Wasm/Pages/Account/PrivacyComponent.razor +++ b/MiniSpace.Web/src/Astravent.Web.Wasm/Pages/Account/PrivacyComponent.razor @@ -2,7 +2,7 @@ @inject IIdentityService IdentityService @using MudBlazor -Privacy +Privacy @if (IsLoading) { diff --git a/MiniSpace.Web/src/Astravent.Web.Wasm/Pages/Account/ProfileComponent.razor b/MiniSpace.Web/src/Astravent.Web.Wasm/Pages/Account/ProfileComponent.razor index f4f7091c5..25aa1c044 100644 --- a/MiniSpace.Web/src/Astravent.Web.Wasm/Pages/Account/ProfileComponent.razor +++ b/MiniSpace.Web/src/Astravent.Web.Wasm/Pages/Account/ProfileComponent.razor @@ -9,7 +9,7 @@ @using MudBlazor @using System -Profile +Profile @if (IsLoading) { diff --git a/MiniSpace.Web/src/Astravent.Web.Wasm/Pages/Account/SecurityComponent.razor b/MiniSpace.Web/src/Astravent.Web.Wasm/Pages/Account/SecurityComponent.razor index ba0455b68..a11aa634a 100644 --- a/MiniSpace.Web/src/Astravent.Web.Wasm/Pages/Account/SecurityComponent.razor +++ b/MiniSpace.Web/src/Astravent.Web.Wasm/Pages/Account/SecurityComponent.razor @@ -2,7 +2,7 @@ @inject IIdentityService IdentityService @using MudBlazor -Security +Security @if (IsLoading) { diff --git a/MiniSpace.Web/src/Astravent.Web.Wasm/Pages/Account/ShowAccountOLD.razor b/MiniSpace.Web/src/Astravent.Web.Wasm/Pages/Account/ShowAccountOLD.razor deleted file mode 100644 index 42036db0b..000000000 --- a/MiniSpace.Web/src/Astravent.Web.Wasm/Pages/Account/ShowAccountOLD.razor +++ /dev/null @@ -1,293 +0,0 @@ -@* @page "/account" -@using System.Globalization -@using Astravent.Web.Wasm.Areas.Students -@using Astravent.Web.Wasm.Components -@using Astravent.Web.Wasm.DTO -@using Astravent.Web.Wasm.Areas.MediaFiles -@using Astravent.Web.Wasm.DTO.Types -@using Astravent.Web.Wasm.Shared -@using Radzen -@using System.IO -@inject IIdentityService IdentityService -@inject IStudentsService StudentsService -@inject IMediaFilesService MediaFilesService -@inject NavigationManager NavigationManager -@using MudBlazor - - - - -@code { - private List _items = new List - { - new BreadcrumbItem("Home", href: "/", icon: Icons.Material.Filled.Home), - new BreadcrumbItem("Account settings", href: "/events/follow", disabled: true, icon: @Icons.Material.Filled.ManageAccounts), - }; - private StudentDto studentDto = new(); - private bool editionDisabled = true; - private string profileImage = string.Empty; - private TaskCompletionSource clientChangeCompletionSource; - private bool isUploading = false; - private bool isLoading = true; - - private const string dateFormat = "dd/MM/yyyy HH:mm"; - private const string shortDateFormat = "dd/MM/yyyy"; - - protected override async Task OnInitializedAsync() - { - isLoading = true; - StateHasChanged(); - - try - { - await IdentityService.InitializeAuthenticationState(); - - if (IdentityService.IsAuthenticated) - { - var studentId = IdentityService.GetCurrentUserId(); - studentDto = await StudentsService.GetStudentAsync(studentId); - profileImage = studentDto.ProfileImageUrl; // Directly using the URL from the DTO - } - else - { - NavigationManager.NavigateTo("/login"); - } - } - catch (Exception ex) - { - Console.WriteLine(ex.Message); - } - finally - { - isLoading = false; - StateHasChanged(); - } - } - - void EnableEdition() - { - editionDisabled = false; - StateHasChanged(); - } - - private async Task HandleUpdateStudent() - { - if (clientChangeCompletionSource != null) - { - await clientChangeCompletionSource.Task; - } - editionDisabled = true; - await StudentsService.UpdateStudentAsync(studentDto.Id, studentDto.ProfileImageUrl, - studentDto.Description, studentDto.EmailNotifications, studentDto.ContactEmail); - await OnInitializedAsync(); - } - - private string GetImage() - { - if (!string.IsNullOrEmpty(profileImage)) - { - return profileImage; - } - - return "images/default_profile_image.webp"; - } - - async void OnClientChange(UploadChangeEventArgs args) - { - clientChangeCompletionSource = new TaskCompletionSource(); - - foreach (var file in args.Files) - { - isUploading = true; - StateHasChanged(); - - try - { - long maxFileSize = 10 * 1024 * 1024; - var stream = file.OpenReadStream(maxFileSize); - byte[] bytes = await ReadFully(stream); - var base64Content = Convert.ToBase64String(bytes); - var response = await MediaFilesService.UploadMediaFileAsync(IdentityService.UserDto.Id, - MediaFileContextType.StudentProfileImage.ToString(), IdentityService.UserDto.Id, - file.Name, file.ContentType, base64Content); - if (response.Content != null && !string.IsNullOrEmpty(response.Content.FileUrl)) - { - studentDto.ProfileImageUrl = response.Content.FileUrl; - profileImage = response.Content.FileUrl; // Update the local profile image URL - } - - stream.Close(); - clientChangeCompletionSource.SetResult(true); - } - catch (Exception ex) - { - clientChangeCompletionSource.SetResult(false); - } - finally - { - isUploading = false; - StateHasChanged(); - } - } - } - - private static async Task ReadFully(Stream input) - { - byte[] buffer = new byte[16 * 1024]; - using (MemoryStream ms = new MemoryStream()) - { - int read; - while ((read = await input.ReadAsync(buffer, 0, buffer.Length)) > 0) - { - ms.Write(buffer, 0, read); - } - return ms.ToArray(); - } - } -} - - - -@if (isLoading) -{ -
- - - -
-} -else if (studentDto.Id != Guid.Empty) -{ - - @if (studentDto.State == "valid") - { - - - - } - - - - - - - - - - - - - -} -else -{ -
- - - -
-} -
- - *@ diff --git a/MiniSpace.Web/src/Astravent.Web.Wasm/Pages/Account/UserSettingsComponent.razor b/MiniSpace.Web/src/Astravent.Web.Wasm/Pages/Account/UserSettingsComponent.razor index 250f601ba..2ba2b0206 100644 --- a/MiniSpace.Web/src/Astravent.Web.Wasm/Pages/Account/UserSettingsComponent.razor +++ b/MiniSpace.Web/src/Astravent.Web.Wasm/Pages/Account/UserSettingsComponent.razor @@ -2,7 +2,7 @@ @inject IIdentityService IdentityService @using MudBlazor -User Settings +User Settings @if (IsLoading) {