Skip to content

Commit b6a1cb9

Browse files
committed
Add bookmark toggle to home page
1 parent bc54b09 commit b6a1cb9

4 files changed

Lines changed: 39 additions & 40 deletions

File tree

PocketDDD.BlazorClient/PocketDDD.BlazorClient/Features/Home/Components/EventData.razor

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
@using PocketDDD.BlazorClient.Features.Home.Store;
2-
@using System.Text.Json;
3-
@using PocketDDD.BlazorClient.Features.Session.Store;
1+
@using PocketDDD.BlazorClient.Features.Home.Store
2+
@using Session = PocketDDD.BlazorClient.Features.Home.Store.Session
43
@inherits FluxorComponent
54

65
@inject NavigationManager NavigationManager
@@ -53,4 +52,20 @@
5352

5453
@code {
5554
void HandleViewSession(int sessionId) => NavigationManager.NavigateTo($"session/{sessionId}");
55+
56+
void HandleToggleSessionBookmarked(Session session)
57+
{
58+
Dispatcher.Dispatch(new ToggleBookmarkedAction(session.Id, !session.IsBookmarked));
59+
}
60+
61+
private static string GetTimeSpanDisplayText(TimeSpan timeSpan)
62+
{
63+
if (timeSpan < TimeSpan.FromHours(1))
64+
{
65+
return $"{timeSpan.Minutes} minutes";
66+
}
67+
68+
return timeSpan == TimeSpan.FromHours(1) ? "1 hour" : $"{timeSpan.TotalHours:F1} hours";
69+
}
70+
5671
}

PocketDDD.BlazorClient/PocketDDD.BlazorClient/Features/Home/Store/HomeActions.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ public record SetCurrentUser(LoginResultDTO Result);
77
public record LoadDataAction();
88
public record SetUserLoggedInAction();
99
public record SetEventMetaDataAction(EventDataResponseDTO EventData, ICollection<int> SessionBookmarks);
10+
public record ToggleBookmarkedAction(int SessionId, bool Bookmarked);

PocketDDD.BlazorClient/PocketDDD.BlazorClient/Features/Home/Store/HomeEffects.cs

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,18 @@
11
using Fluxor;
22
using MudBlazor;
3-
using PocketDDD.BlazorClient.Features.Session.Store;
4-
using PocketDDD.BlazorClient.Features.Sync.Store;
53
using PocketDDD.BlazorClient.Services;
6-
using PocketDDD.Shared.API.RequestDTOs;
7-
using System.Collections.ObjectModel;
84

95
namespace PocketDDD.BlazorClient.Features.Home.Store;
106

117
public class HomeEffects
128
{
13-
private readonly IState<HomeState> _state;
9+
private readonly IDialogService _dialog;
1410
private readonly LocalStorageContext _localStorage;
1511
private readonly IPocketDDDApiService _pocketDDDAPI;
16-
private readonly IDialogService _dialog;
12+
private readonly IState<HomeState> _state;
1713

18-
public HomeEffects(IState<HomeState> state, IDispatcher dispatcher, LocalStorageContext localStorage,
19-
IPocketDDDApiService pocketDDDAPI, IDialogService dialog)
14+
public HomeEffects(IState<HomeState> state, IDispatcher dispatcher, LocalStorageContext localStorage,
15+
IPocketDDDApiService pocketDDDAPI, IDialogService dialog)
2016
{
2117
_state = state;
2218
_localStorage = localStorage;
@@ -38,4 +34,17 @@ public async Task OnLoadData(LoadDataAction action, IDispatcher dispatcher)
3834
if (eventData is not null)
3935
dispatcher.Dispatch(new SetEventMetaDataAction(eventData, sessionBookmarks));
4036
}
37+
38+
[EffectMethod]
39+
public async Task OnToggleSessionBookmarked(ToggleBookmarkedAction action, IDispatcher dispatcher)
40+
{
41+
var bookmarks = await _localStorage.SessionBookmarks.GetOrDefaultAsync();
42+
43+
if (action.Bookmarked && !bookmarks.Contains(action.SessionId))
44+
bookmarks.Add(action.SessionId);
45+
else if (!action.Bookmarked && bookmarks.Contains(action.SessionId))
46+
bookmarks.Remove(action.SessionId);
47+
48+
await _localStorage.SessionBookmarks.SetAsync(bookmarks);
49+
}
4150
}
Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
using Fluxor;
2-
using MudBlazor;
3-
using System.Collections.Immutable;
1+
using System.Collections.Immutable;
2+
using Fluxor;
43

54
namespace PocketDDD.BlazorClient.Features.Home.Store;
65

@@ -30,30 +29,5 @@ public record Session
3029
public string TrackName { get; init; } = string.Empty;
3130
public string RoomName { get; init; } = string.Empty;
3231
public bool IsBookmarked { get; set; } = false;
33-
34-
public string? BookmarkIconIfBookmarked => IsBookmarked
35-
? Icons.Material.Filled.Bookmark
36-
: null;
32+
public TimeSpan Length { get; init; }
3733
}
38-
39-
//export interface SessionItemVM
40-
//{
41-
// session: SessionDTO,
42-
// track: TrackDTO
43-
// isBookmarked: boolean;
44-
//}
45-
46-
//export interface MetaDataVM
47-
//{
48-
// timeSlots: TimeSlotVM[];
49-
//}
50-
51-
//export interface TimeSlotVM
52-
//{
53-
// id: number;
54-
// from: Date;
55-
// to: Date;
56-
// info: string;
57-
58-
// sessions: SessionItemVM[];
59-
//}

0 commit comments

Comments
 (0)