Skip to content

Commit

Permalink
Merge pull request #298 from LiamMorrow/remember-history-and-feed-ses…
Browse files Browse the repository at this point in the history
…sion-pages
  • Loading branch information
LiamMorrow authored Oct 15, 2024
2 parents bbefa78 + 4f613d1 commit 7917b74
Show file tree
Hide file tree
Showing 12 changed files with 63 additions and 22 deletions.
1 change: 1 addition & 0 deletions LiftLog.Ui/Pages/Feed/FeedPage.razor
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@
Dispatcher.Dispatch(new SetBackNavigationUrlAction(null));
Dispatcher.Dispatch(new FetchSessionFeedItemsAction(FromUserAction: false));
Dispatcher.Dispatch(new FetchInboxItemsAction(FromUserAction: false));
Dispatcher.Dispatch(new SetReopenCurrentSessionAction(SessionTarget.FeedSession, false));
Dispatcher.Dispatch(new PublishUnpublishedSessionsAction());
if (FeedState.Value.Identity is null)
{
Expand Down
1 change: 1 addition & 0 deletions LiftLog.Ui/Pages/Feed/ViewFeedSessionPage.razor
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
{
Dispatcher.Dispatch(new SetPageTitleAction("Feed Session"));
Dispatcher.Dispatch(new SetBackNavigationUrlAction("/feed"));
Dispatcher.Dispatch(new SetReopenCurrentSessionAction(SessionTarget.FeedSession, true));

var hasSession = false;

Expand Down
1 change: 1 addition & 0 deletions LiftLog.Ui/Pages/History/HistoryEditPage.razor
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
{
Dispatcher.Dispatch(new SetPageTitleAction("Session"));
Dispatcher.Dispatch(new SetBackNavigationUrlAction("/history"));
Dispatcher.Dispatch(new SetReopenCurrentSessionAction(SessionTarget.HistorySession, true));
if (CurrentSessionState.Value.HistorySession is null)
{
NavigationManager.NavigateTo("/history");
Expand Down
1 change: 1 addition & 0 deletions LiftLog.Ui/Pages/History/HistoryPage.razor
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ else
var sw = System.Diagnostics.Stopwatch.StartNew();
Dispatcher.Dispatch(new SetPageTitleAction("History"));
Dispatcher.Dispatch(new SetBackNavigationUrlAction(null));
Dispatcher.Dispatch(new SetReopenCurrentSessionAction(SessionTarget.HistorySession, false));
this._latestSessions = await SessionService
.GetLatestSessionsAsync()
.ToListAsync();
Expand Down
2 changes: 1 addition & 1 deletion LiftLog.Ui/Pages/Index.razor
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ else
{
Dispatcher.Dispatch(new SetPageTitleAction("Upcoming Workouts"));
Dispatcher.Dispatch(new FetchUpcomingSessionsAction());
Dispatcher.Dispatch(new SetReopenCurrentSessionAction(false));
Dispatcher.Dispatch(new SetReopenCurrentSessionAction(SessionTarget.WorkoutSession, false));
Dispatcher.Dispatch(new SetBackNavigationUrlAction(null));
Dispatcher.Dispatch(new PublishUnpublishedSessionsAction());
Dispatcher.Dispatch(new ExecuteRemoteBackupAction(SettingsState.Value.RemoteBackupSettings));
Expand Down
2 changes: 1 addition & 1 deletion LiftLog.Ui/Pages/PostSessionPage.razor
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
}

Dispatcher.Dispatch(new SetPageTitleAction("Session Summary"));
Dispatcher.Dispatch(new SetReopenCurrentSessionAction(false));
Dispatcher.Dispatch(new SetReopenCurrentSessionAction(SessionTarget.WorkoutSession, false));
Dispatcher.Dispatch(new SetBackNavigationUrlAction(null));
Session = await ProgressRepository.GetSessionAsync(id);
if (Session is null)
Expand Down
2 changes: 1 addition & 1 deletion LiftLog.Ui/Pages/SessionPage.razor
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
protected override async Task OnInitializedAsync()
{
Dispatcher.Dispatch(new SetPageTitleAction("Session"));
Dispatcher.Dispatch(new SetReopenCurrentSessionAction(true));
Dispatcher.Dispatch(new SetReopenCurrentSessionAction(SessionTarget.WorkoutSession, true));
Dispatcher.Dispatch(new SetBackNavigationUrlAction("/"));
if (CurrentSessionState.Value.WorkoutSession is null)
{
Expand Down
22 changes: 21 additions & 1 deletion LiftLog.Ui/Shared/Smart/NavBar.razor
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
private void NavigateToWorkout()
{
if (CurrentSessionState.Value.WorkoutSession != null
&& AppState.Value.ReopenCurrentSession
&& AppState.Value.ReopenCurrentSessionTargets.Contains(SessionTarget.WorkoutSession)
&& !IsRouteMatch("/session/?$"))
{
Dispatcher.Dispatch(new NavigateAction("/session", ClearPageStack: false));
Expand All @@ -71,12 +71,32 @@

private void NavigateToFeed()
{
if (CurrentSessionState.Value.FeedSession != null
&& AppState.Value.ReopenCurrentSessionTargets.Contains(SessionTarget.FeedSession)
&& !IsRouteMatch("/feed/?.*$"))
{
var feedItem = FeedState.Value.Feed.OfType<SessionFeedItem>().FirstOrDefault(x => x.Session.Id == CurrentSessionState.Value.FeedSession.Id);
if (feedItem != null)
{
Dispatcher.Dispatch(new NavigateAction("feed/view-session/"+feedItem.EventId, ClearPageStack: false));
StateHasChanged();
return;
}
}
Dispatcher.Dispatch(new NavigateAction("/feed", ClearPageStack: false));
StateHasChanged();
}

private void NavigateToHistory()
{
if (CurrentSessionState.Value.HistorySession != null
&& AppState.Value.ReopenCurrentSessionTargets.Contains(SessionTarget.HistorySession)
&& !IsRouteMatch("/history/?.*$"))
{
Dispatcher.Dispatch(new NavigateAction("/history/edit", ClearPageStack: false));
StateHasChanged();
return;
}
Dispatcher.Dispatch(new NavigateAction("/history", ClearPageStack: false));
StateHasChanged();
}
Expand Down
3 changes: 2 additions & 1 deletion LiftLog.Ui/Store/App/AppActions.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
using System.Text.RegularExpressions;
using LiftLog.Lib.Models;
using LiftLog.Ui.Models;
using LiftLog.Ui.Store.CurrentSession;

namespace LiftLog.Ui.Store.App;

public record SetPageTitleAction(string Title);

public record SetProTokenAction(string? ProToken);

public record SetReopenCurrentSessionAction(bool ReopenCurrentSession);
public record SetReopenCurrentSessionAction(SessionTarget SessionTarget, bool ReopenSession);

public record ToastAction(string Message);

Expand Down
15 changes: 1 addition & 14 deletions LiftLog.Ui/Store/App/AppFeature.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,5 @@ public class AppFeature : Feature<AppState>
{
public override string GetName() => nameof(AppFeature);

protected override AppState GetInitialState() =>
new(
Title: "LiftLog",
IsHydrated: false,
ProState: new ProState(ProToken: null),
ReopenCurrentSession: true,
BackNavigationUrl: null,
LatestSettingsUrl: null,
HasRequestedNotificationPermission: false,
ColorScheme: new AppColorScheme<uint>(),
AppLaunchCount: 0,
AppRatingResult: AppRatingResult.NotRated,
HistoryYearMonth: null
);
protected override AppState GetInitialState() => AppState.InitialState;
}
8 changes: 7 additions & 1 deletion LiftLog.Ui/Store/App/AppReducers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,13 @@ state with
public static AppState SetReopenCurrentSession(
AppState state,
SetReopenCurrentSessionAction action
) => state with { ReopenCurrentSession = action.ReopenCurrentSession };
) =>
state with
{
ReopenCurrentSessionTargets = action.ReopenSession
? state.ReopenCurrentSessionTargets.Add(action.SessionTarget)
: state.ReopenCurrentSessionTargets.Remove(action.SessionTarget),
};

[ReducerMethod]
public static AppState SetBackNavigationUrl(
Expand Down
27 changes: 25 additions & 2 deletions LiftLog.Ui/Store/App/AppState.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,46 @@
using System.Collections.Immutable;
using System.Diagnostics.CodeAnalysis;
using LiftLog.Lib;
using LiftLog.Lib.Models;
using LiftLog.Ui.Models;
using LiftLog.Ui.Store.CurrentSession;

namespace LiftLog.Ui.Store.App;

public record AppState(
string Title,
ProState ProState,
bool IsHydrated,
bool ReopenCurrentSession,
ImmutableHashSet<SessionTarget> ReopenCurrentSessionTargets,
string? BackNavigationUrl,
string? LatestSettingsUrl,
bool HasRequestedNotificationPermission,
AppColorScheme<uint> ColorScheme,
int AppLaunchCount,
AppRatingResult AppRatingResult,
(int Year, int Month)? HistoryYearMonth
);
)
{
public static readonly AppState InitialState =
new(
Title: "LiftLog",
IsHydrated: false,
ProState: new ProState(ProToken: null),
ReopenCurrentSessionTargets:
[
SessionTarget.WorkoutSession,
SessionTarget.HistorySession,
SessionTarget.FeedSession,
],
BackNavigationUrl: null,
LatestSettingsUrl: null,
HasRequestedNotificationPermission: false,
ColorScheme: new AppColorScheme<uint>(),
AppLaunchCount: 0,
AppRatingResult: AppRatingResult.NotRated,
HistoryYearMonth: null
);
};

public enum AppRatingResult
{
Expand Down

0 comments on commit 7917b74

Please sign in to comment.