Skip to content

Commit

Permalink
(#433) wasm: update my events raozr page to use component
Browse files Browse the repository at this point in the history
  • Loading branch information
SaintAngeLs committed Oct 14, 2024
1 parent 1554329 commit b3849cd
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -402,11 +402,9 @@ public async Task<HttpResponse<object>> ResetPasswordAsync(string token, string

try
{
// Decode token to extract user ID (pseudo-code, replace with your actual token decoding logic)
var userId = DecodeToken(token);
Console.WriteLine($"Decoded UserId: {userId}");

// Proceed with password reset
var response = await _httpClient.PostAsync<object, object>("identity/password/reset", new { UserId = userId, Token = token, Email = email, NewPassword = newPassword });

return response;
Expand Down
15 changes: 14 additions & 1 deletion MiniSpace.Web/src/Astravent.Web.Wasm/DTO/StudentDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,20 @@ public class StudentDto
public List<string> Interests { get; set; }
public IEnumerable<EducationDto> Education { get; set; }
public IEnumerable<WorkDto> Work { get; set; }
public WorkDto LastWorkExperience => Work?.OrderByDescending(w => w.StartDate).FirstOrDefault();

public WorkDto LastWorkExperience
{
get
{
// Get the work experiences with OrganizationId set (non-empty Guid)
var workWithOrganizationId = Work?.Where(w => w.OrganizationId != Guid.Empty)
.OrderByDescending(w => w.StartDate)
.FirstOrDefault();

// If found, return the one with OrganizationId, otherwise return the latest work experience
return workWithOrganizationId ?? Work?.OrderByDescending(w => w.StartDate).FirstOrDefault();
}
}
public bool IsTwoFactorEnabled { get; set; }
public string TwoFactorSecret { get; set; }
public IEnumerable<Guid> InterestedInEvents { get; set; }
Expand Down
94 changes: 64 additions & 30 deletions MiniSpace.Web/src/Astravent.Web.Wasm/Pages/Events/MyEvents.razor
Original file line number Diff line number Diff line change
@@ -1,53 +1,46 @@
@page "/events/my-events"
@inject IEventsService EventsService
@inject IIdentityService IdentityService
@using MudBlazor
@inject NavigationManager NavigationManager
@using Astravent.Web.Wasm.Pages.Events.Components
@inject ISnackbar Snackbar

<MudContainer MaxWidth="MaxWidth.Large" Class="mt-4">
<MudText Typo="Typo.h3" Align="Align.Center" Class="mb-4">My Events</MudText>

<MudGrid Spacing="3">
@if (events?.Any() ?? false)
{
@foreach (var eventDto in events)
@if (isLoading)
{
<!-- Show Skeletons while loading -->
<MudGrid Spacing="3">
@for (int i = 0; i < 6; i++) // Placeholder skeletons while loading
{
<MudItem xs="12" sm="6" md="4">
<MudCard Class="mud-card-hover" Style="height: 100%; border-radius: 15px;">
<MudCardMedia Image="@eventDto.BannerUrl" Alt="@eventDto.Name" Style="height: 180px;" />
<MudCard Class="my-2" Style="position:relative;">
<MudSkeleton SkeletonType="SkeletonType.Rectangle" Height="200px" />
<MudCardContent>
<MudText Typo="Typo.h6">@eventDto.Name</MudText>
<MudText Typo="Typo.body2" Color="Color.Secondary">@eventDto.Category</MudText>
<MudText Typo="Typo.body2">Starts: @eventDto.StartDate.ToString("MMMM dd, yyyy")</MudText>
<MudText Typo="Typo.body2">Ends: @eventDto.EndDate.ToString("MMMM dd, yyyy")</MudText>
<MudText Typo="Typo.body2">
<MudIcon Icon="@Icons.Material.Filled.HowToReg" Style="font-size: 1rem;" />
Signed Up: @eventDto.SignedUpStudents
</MudText>
<MudText Typo="Typo.body2">
<MudIcon Icon="@Icons.Material.Rounded.ThumbUp" Style="font-size: 1rem;" />
Interested: @eventDto.InterestedStudents
</MudText>
<MudSkeleton Width="30%" Height="42px;" />
<MudSkeleton Width="80%" />
<MudSkeleton Width="100%" />
</MudCardContent>
<MudCardActions>
<MudButton Variant="Variant.Filled" Color="Color.Primary" OnClick="() => ViewEvent(eventDto.Id)">
View Details
</MudButton>
<MudSkeleton Width="64px" Height="40px" />
<MudSkeleton Width="105px" Height="40px" />
</MudCardActions>
</MudCard>
</MudItem>
}
}
else
{
<MudText Typo="Typo.h6" Color="Color.Secondary" Align="Align.Center" Class="mt-6">No events found.</MudText>
}
</MudGrid>
</MudGrid>
}
else
{
<!-- Event List -->
<EventList Events="events" OnViewEvent="ViewEvent" OnSignUpToEvent="SignUpToEvent" OnShowInterestInEvent="ShowInterestInEvent" />
}

<MudDivider Class="my-4" />

<MudPagination @bind-SelectedPage="currentPage" PageSizeOptions="@pageSizeOptions" PageSize="pageSize"
<!-- Pagination -->
<MudPagination @bind-SelectedPage="currentPage" PageSizeOptions="@pageSizeOptions" PageSize="pageSize"
TotalItems="totalItems" OnPageChanged="OnPageChanged" />
</MudContainer>

Expand All @@ -59,17 +52,20 @@
private int currentPage = 1;
private int pageSize = 9;
private readonly int[] pageSizeOptions = { 6, 9, 12 };
private bool isLoading = false; // Loading indicator
protected override async Task OnInitializedAsync()
{
isLoading = true; // Start loading
await LoadEvents();
isLoading = false; // Stop loading
}

private async Task LoadEvents()
{
try
{
var organizerId = IdentityService.GetCurrentUserId();
var organizerId = await IdentityService.GetCurrentUserIdFromJwtAsync(); // Get user ID from JWT
var response = await EventsService.GetMyEventsAsync(organizerId, currentPage, pageSize);

events = response.Items.ToList();
Expand All @@ -91,4 +87,42 @@
{
NavigationManager.NavigateTo($"/events/event/{eventId}");
}

private async Task SignUpToEvent(Guid eventId)
{
try
{
var command = new SignUpToEventCommand
{
EventId = eventId,
StudentId = await IdentityService.GetCurrentUserIdFromJwtAsync() // Get user ID from JWT
};
await EventsService.SignUpToEventAsync(command);
Snackbar.Add("Successfully signed up for the event.", Severity.Success);
await LoadEvents(); // Reload to reflect sign-up changes
}
catch (Exception ex)
{
Snackbar.Add($"An error occurred while signing up: {ex.Message}", Severity.Error);
}
}

private async Task ShowInterestInEvent(Guid eventId)
{
try
{
var command = new ShowInterestInEventCommand
{
EventId = eventId,
StudentId = await IdentityService.GetCurrentUserIdFromJwtAsync() // Get user ID from JWT
};
await EventsService.ShowInterestInEventAsync(command);
Snackbar.Add("Your interest in the event has been noted.", Severity.Info);
await LoadEvents(); // Reload to reflect interest changes
}
catch (Exception ex)
{
Snackbar.Add($"An error occurred while showing interest: {ex.Message}", Severity.Error);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@
<MudItem xs="12">
<MudPaper Class="p-3 mb-2" Elevation="2" Style="border-radius: 10px; cursor: pointer;" @onclick="() => ViewDetails(student.Id)">
<MudGrid>
<MudItem xs="2" Class="d-flex justify-content-center align-items-center">
<MudItem xs="1" md="1" Class="d-flex justify-content-center align-items-center">
<MudAvatar Image="@GetProfileImageUrl(student.ProfileImageUrl)" Alt="Student Image" Size="Size.Large" Class="border border-primary" />
</MudItem>
<MudItem xs="10">
<MudItem xs="8" md="8">
<MudText Typo="Typo.h6" Class="mb-0" Style="font-weight: bold;">@($"{student.FirstName} {student.LastName}")</MudText>
@if (student.LastWorkExperience != null)
{
Expand All @@ -52,6 +52,8 @@
{
<MudText Typo="Typo.subtitle2"> </MudText>
}
</MudItem>
<MudItem xs="2" md="2">
<MudButtonGroup>
@if (student.Id != IdentityService.GetCurrentUserId() && !(sentRequests?.Any(r => r.InviteeId == student.Id) ?? false) && !(allFriends?.Any(f => f.FriendId == student.Id) ?? false))
{
Expand Down

0 comments on commit b3849cd

Please sign in to comment.