From 93b5e9d95d76f14b83218cdb7a62038c12bc6987 Mon Sep 17 00:00:00 2001 From: Andrii Voznesenskyi Date: Sun, 13 Oct 2024 01:18:17 +0200 Subject: [PATCH] (#433) wasm: add lazy images loading for te work and education associated with organizations --- .../Pages/Account/ProfileComponent.razor | 106 +++++++++++------- .../Pages/Events/Components/EventItem.razor | 3 +- .../Shared/themes/MiniSpaceTheme.cs | 12 +- 3 files changed, 75 insertions(+), 46 deletions(-) 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 982b60cb..7b006866 100644 --- a/MiniSpace.Web/src/Astravent.Web.Wasm/Pages/Account/ProfileComponent.razor +++ b/MiniSpace.Web/src/Astravent.Web.Wasm/Pages/Account/ProfileComponent.razor @@ -126,10 +126,21 @@ else - - Associate with Organization - + @if (education.OrganizationId != Guid.Empty) + { + + Edit Association + + } + else + { + + Associate with Organization + + } + Remove @@ -171,10 +182,21 @@ else - - Associate with Organization - + @if (work.OrganizationId != Guid.Empty) + { + + Edit Association + + } + else + { + + Associate with Organization + + } + Remove @@ -187,6 +209,7 @@ else + @@ -251,11 +274,9 @@ else [Parameter] public bool IsUploading { get; set; } [Inject] public IDialogService DialogService { get; set; } private string CroppedImageBase64 { get; set; } - private IBrowserFile croppedImageFile; private string currentImageType = string.Empty; - private Dictionary _organizationImages = new(); protected override async Task OnAfterRenderAsync(bool firstRender) @@ -263,21 +284,29 @@ else if (firstRender) { await JSRuntime.InvokeVoidAsync("GLOBAL.SetDotnetReference", DotNetObjectReference.Create(this)); + await LoadOrganizationImagesAsync(); } - await LoadOrganizationImagesAsync(); } private async Task LoadOrganizationImagesAsync() { foreach (var education in StudentWithGalleryImagesDto.Student.Education) { - _organizationImages[education.OrganizationId] = await GetOrganizationImage(education.OrganizationId); + if (education.OrganizationId != Guid.Empty) + { + _organizationImages[education.OrganizationId] = await GetOrganizationImage(education.OrganizationId); + } } foreach (var work in StudentWithGalleryImagesDto.Student.Work) { - _organizationImages[work.OrganizationId] = await GetOrganizationImage(work.OrganizationId); + if (work.OrganizationId != Guid.Empty) + { + _organizationImages[work.OrganizationId] = await GetOrganizationImage(work.OrganizationId); + } } + + StateHasChanged(); // Ensure the UI updates after loading images } private string GetImage() @@ -431,7 +460,6 @@ else StateHasChanged(); } - private void AddWorkExperience() { var workList = StudentWithGalleryImagesDto.Student.Work.ToList(); @@ -449,7 +477,6 @@ else StateHasChanged(); } - private void RemoveWorkExperience(WorkDto work) { var workList = StudentWithGalleryImagesDto.Student.Work.ToList(); @@ -459,31 +486,29 @@ else } private async Task SaveProfile() -{ - var studentDto = StudentWithGalleryImagesDto.Student; - - try - { - // Log Education JSON - var educationJson = JsonSerializer.Serialize(studentDto.Education, new JsonSerializerOptions { WriteIndented = true }); - Console.WriteLine("Education Data (Before Sending):"); - Console.WriteLine(educationJson); - - // Log Work JSON - var workJson = JsonSerializer.Serialize(studentDto.Work, new JsonSerializerOptions { WriteIndented = true }); - Console.WriteLine("Work Data (Before Sending):"); - Console.WriteLine(workJson); - - // Proceed to save changes - await SaveChangesAsync.InvokeAsync(null); - } - catch (Exception ex) { - Console.WriteLine($"An error occurred: {ex.Message}"); - } -} - + var studentDto = StudentWithGalleryImagesDto.Student; + try + { + // Log Education JSON + var educationJson = JsonSerializer.Serialize(studentDto.Education, new JsonSerializerOptions { WriteIndented = true }); + Console.WriteLine("Education Data (Before Sending):"); + Console.WriteLine(educationJson); + + // Log Work JSON + var workJson = JsonSerializer.Serialize(studentDto.Work, new JsonSerializerOptions { WriteIndented = true }); + Console.WriteLine("Work Data (Before Sending):"); + Console.WriteLine(workJson); + + // Proceed to save changes + await SaveChangesAsync.InvokeAsync(null); + } + catch (Exception ex) + { + Console.WriteLine($"An error occurred: {ex.Message}"); + } + } private async Task OpenAssociateOrganizationDialog(string type, object entity) { @@ -512,10 +537,13 @@ else work.OrganizationId = organization.Id; work.Company = organization.Name; } + + // Reload organization images after updating the associations + await LoadOrganizationImagesAsync(); } } - private async Task GetOrganizationImage(Guid organizationId) + private async Task GetOrganizationImage(Guid organizationId) { if (organizationId == Guid.Empty) { diff --git a/MiniSpace.Web/src/Astravent.Web.Wasm/Pages/Events/Components/EventItem.razor b/MiniSpace.Web/src/Astravent.Web.Wasm/Pages/Events/Components/EventItem.razor index 77047692..401602c0 100644 --- a/MiniSpace.Web/src/Astravent.Web.Wasm/Pages/Events/Components/EventItem.razor +++ b/MiniSpace.Web/src/Astravent.Web.Wasm/Pages/Events/Components/EventItem.razor @@ -175,7 +175,7 @@ private void ShareEvent(string platform) { - var eventUrl = NavigationManager.Uri; + var eventUrl = NavigationManager.BaseUri + $"events/event/{Event.Id}"; var eventTitle = Uri.EscapeDataString(Event.Name); string shareUrl = platform switch @@ -194,6 +194,7 @@ } + private void InviteToEvent() { // Logic to invite others to the event diff --git a/MiniSpace.Web/src/Astravent.Web.Wasm/Shared/themes/MiniSpaceTheme.cs b/MiniSpace.Web/src/Astravent.Web.Wasm/Shared/themes/MiniSpaceTheme.cs index 01aae679..6de227d0 100644 --- a/MiniSpace.Web/src/Astravent.Web.Wasm/Shared/themes/MiniSpaceTheme.cs +++ b/MiniSpace.Web/src/Astravent.Web.Wasm/Shared/themes/MiniSpaceTheme.cs @@ -6,9 +6,9 @@ public static class MiniSpaceTheme { Palette = new PaletteLight() { - Primary = Colors.Indigo.Darken4, - Secondary = Colors.Indigo.Darken3, - AppbarText = Colors.Indigo.Darken4, + Primary = Colors.Blue.Darken4, + Secondary = Colors.Blue.Darken3, + AppbarText = Colors.Blue.Darken4, AppbarBackground = Colors.Shades.White, Background = Colors.Grey.Lighten5, Surface = "#FFFFFF", @@ -16,7 +16,7 @@ public static class MiniSpaceTheme DrawerText = Colors.Grey.Darken3, TextPrimary = Colors.Shades.Black, TextSecondary = Colors.Grey.Darken2, - ActionDefault = Colors.Indigo.Lighten1, + ActionDefault = Colors.Blue.Lighten1, ActionDisabled = Colors.Grey.Lighten2, Success = Colors.Green.Default, Warning = Colors.Orange.Default, @@ -26,7 +26,7 @@ public static class MiniSpaceTheme PaletteDark = new PaletteDark() { // Dark Mode Colors - Primary = Colors.Indigo.Darken1, + Primary = Colors.Blue.Darken1, Secondary = Colors.Blue.Darken4, AppbarBackground = "#1F1F1F", // Dark app bar Background = "#000", // Very dark background @@ -36,7 +36,7 @@ public static class MiniSpaceTheme DrawerText = Colors.Grey.Lighten2, TextPrimary = Colors.Shades.White, TextSecondary = Colors.Grey.Lighten2, - ActionDefault = Colors.Indigo.Accent2, + ActionDefault = Colors.Blue.Accent2, ActionDisabled = Colors.BlueGrey.Darken3, Success = Colors.Green.Accent3, Warning = Colors.Orange.Accent3,