Skip to content

Commit

Permalink
(#433) wasm: add lazy images loading for te work and education associ…
Browse files Browse the repository at this point in the history
…ated with organizations
  • Loading branch information
SaintAngeLs committed Oct 12, 2024
1 parent 6eb78f1 commit 93b5e9d
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,21 @@ else

<!-- Action Buttons -->
<MudItem xs="12" Class="d-flex justify-content-end">
<MudButton Variant="Variant.Outlined" StartIcon="@Icons.Material.Filled.Business" OnClick="@(() => OpenAssociateOrganizationDialog("Education", education))"
Disabled="@(education.OrganizationId != Guid.Empty)" Class="mr-2">
Associate with Organization
</MudButton>
@if (education.OrganizationId != Guid.Empty)
{
<MudButton Variant="Variant.Outlined" StartIcon="@Icons.Material.Filled.Edit" OnClick="@(() => OpenAssociateOrganizationDialog("Education", education))"
Class="mr-2">
Edit Association
</MudButton>
}
else
{
<MudButton Variant="Variant.Outlined" StartIcon="@Icons.Material.Filled.Business" OnClick="@(() => OpenAssociateOrganizationDialog("Education", education))"
Class="mr-2">
Associate with Organization
</MudButton>
}

<MudButton Color="Color.Error" StartIcon="@Icons.Material.Filled.Delete" OnClick="() => RemoveEducation(education)">
Remove
</MudButton>
Expand Down Expand Up @@ -171,10 +182,21 @@ else

<!-- Action Buttons -->
<MudItem xs="12" Class="d-flex justify-content-end">
<MudButton Variant="Variant.Outlined" StartIcon="@Icons.Material.Filled.Business" OnClick="@(() => OpenAssociateOrganizationDialog("Work", work))"
Disabled="@(work.OrganizationId != Guid.Empty)" Class="mr-2">
Associate with Organization
</MudButton>
@if (work.OrganizationId != Guid.Empty)
{
<MudButton Variant="Variant.Outlined" StartIcon="@Icons.Material.Filled.Edit" OnClick="@(() => OpenAssociateOrganizationDialog("Work", work))"
Class="mr-2">
Edit Association
</MudButton>
}
else
{
<MudButton Variant="Variant.Outlined" StartIcon="@Icons.Material.Filled.Business" OnClick="@(() => OpenAssociateOrganizationDialog("Work", work))"
Class="mr-2">
Associate with Organization
</MudButton>
}

<MudButton Color="Color.Error" StartIcon="@Icons.Material.Filled.Delete" OnClick="() => RemoveWorkExperience(work)">
Remove
</MudButton>
Expand All @@ -187,6 +209,7 @@ else
</MudButton>
</MudItem>


</MudItem>
</MudGrid>

Expand Down Expand Up @@ -251,33 +274,39 @@ 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<Guid, string> _organizationImages = new();

protected override async Task OnAfterRenderAsync(bool firstRender)
{
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()
Expand Down Expand Up @@ -431,7 +460,6 @@ else
StateHasChanged();
}


private void AddWorkExperience()
{
var workList = StudentWithGalleryImagesDto.Student.Work.ToList();
Expand All @@ -449,7 +477,6 @@ else
StateHasChanged();
}


private void RemoveWorkExperience(WorkDto work)
{
var workList = StudentWithGalleryImagesDto.Student.Work.ToList();
Expand All @@ -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)
{
Expand Down Expand Up @@ -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<string> GetOrganizationImage(Guid organizationId)
private async Task<string> GetOrganizationImage(Guid organizationId)
{
if (organizationId == Guid.Empty)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -194,6 +194,7 @@
}



private void InviteToEvent()
{
// Logic to invite others to the event
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ 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",
DrawerBackground = Colors.Grey.Lighten3,
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,
Expand All @@ -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
Expand All @@ -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,
Expand Down

0 comments on commit 93b5e9d

Please sign in to comment.