Skip to content

Commit

Permalink
(#57) update follow events page to handle GetStudentEvents update
Browse files Browse the repository at this point in the history
  • Loading branch information
an2508374 committed May 17, 2024
1 parent 40fc658 commit fb640ea
Show file tree
Hide file tree
Showing 6 changed files with 198 additions and 102 deletions.
5 changes: 3 additions & 2 deletions MiniSpace.Web/src/MiniSpace.Web/Areas/Events/EventsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ public Task<EventDto> GetEventAsync(Guid eventId)
return _httpClient.GetAsync<EventDto>($"events/{eventId}");
}

public Task<PagedResponseDto<IEnumerable<EventDto>>> GetStudentEventsAsync(Guid studentId, int numberOfResults)
public Task<PagedResponseDto<IEnumerable<EventDto>>> GetStudentEventsAsync(Guid studentId,
string engagementType, int page, int numberOfResults)
{
_httpClient.SetAccessToken(_identityService.JwtDto.AccessToken);
return _httpClient.GetAsync<PagedResponseDto<IEnumerable<EventDto>>>(
$"events/student/{studentId}?numberOfResults={numberOfResults}");
$"events/student/{studentId}?engagementType={engagementType}&page={page}&numberOfResults={numberOfResults}");
}

public Task<HttpResponse<object>> AddEventAsync(Guid eventId, string name, Guid organizerId, Guid organizationId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ namespace MiniSpace.Web.Areas.Events
public interface IEventsService
{
Task<EventDto> GetEventAsync(Guid eventId);
Task<PagedResponseDto<IEnumerable<EventDto>>> GetStudentEventsAsync(Guid studentId, int numberOfResults);
Task<PagedResponseDto<IEnumerable<EventDto>>> GetStudentEventsAsync(Guid studentId,
string engagementType, int page, int numberOfResults);
Task<HttpResponse<object>> AddEventAsync(Guid eventId, string name, Guid organizerId, Guid organizationId,
string startDate, string endDate, string buildingName, string street, string buildingNumber,
string apartmentNumber, string city, string zipCode, string description, int capacity, decimal fee,
Expand Down
96 changes: 0 additions & 96 deletions MiniSpace.Web/src/MiniSpace.Web/Pages/Events/Events.razor

This file was deleted.

192 changes: 192 additions & 0 deletions MiniSpace.Web/src/MiniSpace.Web/Pages/Events/EventsFollow.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
@page "/events/follow"
@using MiniSpace.Web.Areas.Students
@using MiniSpace.Web.DTO
@using MiniSpace.Web.Areas.Events
@using MiniSpace.Web.Components
@using MiniSpace.Web.Pages.Events.Dialogs
@using MudBlazor
@using Radzen
@using DialogOptions = Radzen.DialogOptions
@using DialogService = Radzen.DialogService
@using Orientation = Radzen.Orientation
@inject DialogService DialogService
@inject IIdentityService IdentityService
@inject IEventsService EventsService
@inject NavigationManager NavigationManager

<h1>Follow events</h1>

@if (!pageInitialized)
{
<h3 class="rz-p-12">Loading...</h3>
}

@if (pageInitialized && studentId != Guid.Empty)
{
<RadzenStack class="rz-pt-12" Gap="1rem" Style="height: 100%">
<RadzenTabs Change="@OnChange" TabPosition="TabPosition.Top" RenderMode="TabRenderMode.Server">
<Tabs>
<RadzenTabsItem Text="Signed up">
@if (signedUpTotalElements == 0)
{
<h3>You haven't been signed up for any event yet.</h3>
}
else
{
<RadzenStack Orientation="Orientation.Horizontal" JustifyContent="JustifyContent.End">
<MudPagination Count="@signedUpTotalPages" SelectedChanged="@SignedUpSelectedPageChanged"
Selected="@signedUpPageNumber" Rectangular="true" ShowFirstButton="true"
ShowLastButton="true"/>
</RadzenStack>

<RadzenDataList AllowPaging="false" Data="@signedUpEvents" TItem="EventDto">
<Template Context="ev">
<RadzenEventCard Event="ev" />
</Template>
</RadzenDataList>

<RadzenStack Orientation="Orientation.Horizontal" JustifyContent="JustifyContent.End">
<MudPagination Count="@signedUpTotalPages" SelectedChanged="@SignedUpSelectedPageChanged"
Selected="@signedUpPageNumber" Rectangular="true" ShowFirstButton="true"
ShowLastButton="true"/>
</RadzenStack>
}
</RadzenTabsItem>

<RadzenTabsItem Text="Interested in">
@if (interestedInTotalElements == 0)
{
<h3>You haven't been interested in any event yet.</h3>
}
else
{
<RadzenStack Orientation="Orientation.Horizontal" JustifyContent="JustifyContent.End">
<MudPagination Count="@interestedInTotalPages" SelectedChanged="@InterestedInSelectedPageChanged"
Selected="@interestedInPageNumber" Rectangular="true" ShowFirstButton="true"
ShowLastButton="true"/>
</RadzenStack>

<RadzenDataList AllowPaging="false" Data="@interestedInEvents" TItem="EventDto">
<Template Context="ev">
<RadzenEventCard Event="ev" />
</Template>
</RadzenDataList>

<RadzenStack Orientation="Orientation.Horizontal" JustifyContent="JustifyContent.End">
<MudPagination Count="@interestedInTotalPages" SelectedChanged="@InterestedInSelectedPageChanged"
Selected="@interestedInPageNumber" Rectangular="true" ShowFirstButton="true"
ShowLastButton="true"/>
</RadzenStack>
}
</RadzenTabsItem>
</Tabs>
</RadzenTabs>
</RadzenStack>
}

@code {
private Guid studentId;
private bool pageInitialized = false;

int signedUpPageNumber = 1;
int signedUpPageSize = 5;
int signedUpTotalPages = 0;
int signedUpTotalElements = 0;
IEnumerable<EventDto> signedUpEvents;

int interestedInPageNumber = 1;
int interestedInPageSize = 5;
int interestedInTotalPages = 0;
int interestedInTotalElements = 0;
IEnumerable<EventDto> interestedInEvents;

protected override async Task OnInitializedAsync()
{
if (IdentityService.IsAuthenticated)
{
studentId = IdentityService.GetCurrentUserId();

var tmp = await EventsService.GetStudentEventsAsync(studentId, "SignedUp",
signedUpPageNumber, signedUpPageSize);
if (tmp != null)
{
signedUpTotalPages = tmp.TotalPages;
signedUpTotalElements = tmp.TotalElements;
signedUpEvents = tmp.Content;
}
else
{
signedUpTotalPages = 0;
signedUpTotalElements = 0;
signedUpEvents = new List<EventDto>();
}
}

pageInitialized = true;
}

private async void OnChange(int index)
{
if (!IdentityService.IsAuthenticated)
{
return;
}

switch (index)
{
case 0:
var tmp = await EventsService.GetStudentEventsAsync(studentId, "SignedUp",
signedUpPageNumber, signedUpPageSize);
if (tmp != null)
{
signedUpTotalPages = tmp.TotalPages;
signedUpTotalElements = tmp.TotalElements;
signedUpEvents = tmp.Content;
}
else
{
signedUpTotalPages = 0;
signedUpTotalElements = 0;
signedUpEvents = new List<EventDto>();
}
break;
case 1:
tmp = await EventsService.GetStudentEventsAsync(studentId, "InterestedIn",
interestedInPageNumber, interestedInPageSize);
if (tmp != null)
{
interestedInTotalPages = tmp.TotalPages;
interestedInTotalElements = tmp.TotalElements;
interestedInEvents = tmp.Content;
}
else
{
interestedInTotalPages = 0;
interestedInTotalElements = 0;
interestedInEvents = new List<EventDto>();
}
break;
}
StateHasChanged();
}

private async void SignedUpSelectedPageChanged(int pageNumber)
{
signedUpPageNumber = pageNumber;

var tmp = await EventsService.GetStudentEventsAsync(studentId, "SignedUp",
signedUpPageNumber, signedUpPageSize);
signedUpEvents = tmp.Content;
StateHasChanged();
}

private async void InterestedInSelectedPageChanged(int pageNumber)
{
interestedInPageNumber = pageNumber;

var tmp = await EventsService.GetStudentEventsAsync(studentId, "InterestedIn",
interestedInPageNumber, interestedInPageSize);
interestedInEvents = tmp.Content;
StateHasChanged();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@
}

@code {
private const string dateFormat = "dd/MM/yyyy HH:mm";

private SearchEventsModel searchEventsModel = new()
{
Name = "",
Expand Down
2 changes: 1 addition & 1 deletion MiniSpace.Web/src/MiniSpace.Web/Shared/MainLayout.razor
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@

<RadzenPanelMenuItem Text="Events" Icon="event">
<RadzenPanelMenuItem Text="Follow" Icon="bookmark"
Click="@(() => NavigationManager.NavigateTo("events/"))"/>
Click="@(() => NavigationManager.NavigateTo("events/follow"))"/>
<RadzenPanelMenuItem Text="Search" Icon="find_in_page"
Click="@(() => NavigationManager.NavigateTo("events/search"))"/>
@if (IdentityService.GetCurrentUserRole() == "organizer")
Expand Down

0 comments on commit fb640ea

Please sign in to comment.