Skip to content

Commit

Permalink
Merge pull request #200 from LiamMorrow/feed
Browse files Browse the repository at this point in the history
  • Loading branch information
LiamMorrow authored Jul 17, 2024
2 parents 30e2039 + 33550c3 commit fd565bb
Show file tree
Hide file tree
Showing 18 changed files with 159 additions and 53 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,5 @@
#*.RTF diff=astextplain
*.cs linguist-language=C#
*.razor linguist-language=C#

LiftLog.Ui/wwwroot/tailwind.js linguist-vendored
1 change: 0 additions & 1 deletion LiftLog.Ui/LiftLog.Ui.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
<Content Remove="wwwroot\load-tailwind.js" />
<Content Remove="wwwroot\tailwind.js" />
<Content Remove="wwwroot\twconf.json" />
<Content Remove="wwwroot\export.liftlogbackup.gz" />
<Content Remove="Pages\Screenshot\ScreenshotCollectorPage.razor" />
</ItemGroup>

Expand Down
7 changes: 5 additions & 2 deletions LiftLog.Ui/Models/ExportedDataDao/ExportedDataDaoV2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ internal partial class ExportedDataDaoV2
public ExportedDataDaoV2(
IEnumerable<SessionDaoV2> sessions,
IDictionary<string, ProgramBlueprintDaoV1> savedPrograms,
Guid activeProgramId
Guid activeProgramId,
FeedStateDaoV1? feedState
)
{
Sessions.AddRange(sessions);
ActiveProgramId = activeProgramId.ToString();
SavedPrograms.Add(savedPrograms);
FeedState = feedState;
}

public static ExportedDataDaoV2 FromV1(ExportedDataDaoV1 v1)
Expand All @@ -36,7 +38,8 @@ public static ExportedDataDaoV2 FromV1(ExportedDataDaoV1 v1)
return new ExportedDataDaoV2(
v1.Sessions.Select(x => x.ToModel()).Select(SessionDaoV2.FromModel),
plans,
activePlanId
activePlanId,
null
);
}
}
2 changes: 2 additions & 0 deletions LiftLog.Ui/Models/ExportedDataDao/ExportedDataDaoV2.proto
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ package LiftLog.Ui.Models.ExportedDataDao;
import "Models/SessionHistoryDao/SessionHistoryDaoV2.proto";
import "Models/SessionBlueprintDao/SessionBlueprintDaoV2.proto";
import "Models/ProgramBlueprintDao/ProgramBlueprintDaoV1.proto";
import "Models/FeedStateDao.proto";
import "google/protobuf/wrappers.proto";

message ExportedDataDaoV2 {
repeated LiftLog.Ui.Models.SessionHistoryDao.SessionDaoV2 sessions = 1;
repeated LiftLog.Ui.Models.SessionBlueprintDao.SessionBlueprintDaoV2 program = 2;
map<string, LiftLog.Ui.Models.ProgramBlueprintDao.ProgramBlueprintDaoV1> saved_programs = 3;
google.protobuf.StringValue active_program_id = 4;
LiftLog.Ui.Models.FeedStateDaoV1 feed_state = 5;
}
29 changes: 11 additions & 18 deletions LiftLog.Ui/Pages/Feed/FeedPage.razor
Original file line number Diff line number Diff line change
Expand Up @@ -111,22 +111,15 @@
}


<Dialog @ref="deleteUserDialog">
<span slot="headline">Unfollow user</span>
<span slot="content" class="block text-left">This will unfollow <span class="text-primary font-bold">@(userToDelete?.Nickname ?? userToDelete?.Name ?? "Anonymous User")</span> and remove all their content on your device.</span>
<div slot="actions">
<AppButton Type="AppButtonType.Text" OnClick="@(() => deleteUserDialog?.Close())">Cancel</AppButton>
<AppButton Type="AppButtonType.Text" OnClick="DeleteUser">Unfollow</AppButton>
</div>
</Dialog>
<Dialog @ref="removeFollowerDialog">
<span slot="headline">Remove follower</span>
<span slot="content" class="block text-left">This will stop <span class="text-primary font-bold">@(userToDelete?.Nickname ?? userToDelete?.Name ?? "Anonymous User")</span> from following you and remove all your content from their device.</span>
<div slot="actions">
<AppButton Type="AppButtonType.Text" OnClick="@(() => removeFollowerDialog?.Close())">Cancel</AppButton>
<AppButton Type="AppButtonType.Text" OnClick="RemoveFollower">Unfollow</AppButton>
</div>
</Dialog>
<ConfirmationDialog @ref="deleteUserDialog" OkText="Unfollow" OnOk="DeleteUser">
<Headline>Unfollow user</Headline>
<TextContent>This will unfollow <span class="text-primary font-bold">@(userToDelete?.Nickname ?? userToDelete?.Name ?? "Anonymous User")</span> and remove all their content on your device.</TextContent>
</ConfirmationDialog>

<ConfirmationDialog @ref="removeFollowerDialog" OkText="Remove" OnOk="RemoveFollower">
<Headline>Remove follower</Headline>
<TextContent>This will stop <span class="text-primary font-bold">@(userToDelete?.Nickname ?? userToDelete?.Name ?? "Anonymous User")</span> from following you and remove all your content from their device.</TextContent>
</ConfirmationDialog>

@code
{
Expand All @@ -139,8 +132,8 @@


private ElementReference tabs;
private Dialog? deleteUserDialog;
private Dialog? removeFollowerDialog;
private ConfirmationDialog? deleteUserDialog;
private ConfirmationDialog? removeFollowerDialog;
private FeedUser? userToDelete;
private FullScreenDialog? settingsDialog;
private FeedIdentityManager? feedIdentityManager;
Expand Down
16 changes: 6 additions & 10 deletions LiftLog.Ui/Pages/Index.razor
Original file line number Diff line number Diff line change
Expand Up @@ -88,21 +88,17 @@ else
</Fab>
</FloatingBottomContainer>
<Dialog @ref="replaceCurrentSesisonDialog">
<span slot="headline">Replace current session</span>
<span slot="content" class="block text-left">
<ConfirmationDialog @ref="replaceCurrentSesisonDialog" OkText="Replace" OnOk="ReplaceSession">
<Headline>Replace current session</Headline>
<TextContent>
There is already a current session in progress, start a new one without
saving?
</span>
<div slot="actions">
<AppButton Type="AppButtonType.Text" OnClick="@(() => replaceCurrentSesisonDialog?.Close())">Cancel</AppButton>
<AppButton Type="AppButtonType.Text" OnClick="ReplaceSession">Replace</AppButton>
</div>
</Dialog>
</TextContent>
</ConfirmationDialog>

@code {

private Dialog? replaceCurrentSesisonDialog;
private ConfirmationDialog? replaceCurrentSesisonDialog;
private Session? selectedSession;

protected override async Task OnInitializedAsync()
Expand Down
46 changes: 44 additions & 2 deletions LiftLog.Ui/Pages/Settings/BackupAndRestorePage.razor
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
@inherits Fluxor.Blazor.Web.Components.FluxorComponent

<md-list>
<md-list-item type="button" class="text-left" multi-line-supporting-text @onclick="ExportData">
<md-list-item type="button" class="text-left" multi-line-supporting-text @onclick="()=>exportFeedDialog?.Open()">
<md-icon slot="start">backup</md-icon>
<span slot="headline">Export data</span>
<span slot="supporting-text">Export your data to a file for backup or transfer</span>
Expand All @@ -16,11 +16,35 @@
</md-list-item>
</md-list>


<ConfirmationDialog @ref="importFeedDialog" OkText="Import" CancelText="No" OnOk="ImportFeedData">
<Headline>Import Feed Data?</Headline>
<TextContent>
<p>This backup includes a feed account. Would you like to import it?</p>
<p>You will lose access to your current account without a backup.</p>
<p class="text-error font-bold">This will replace your current account and cannot be undone!</p>
</TextContent>
</ConfirmationDialog>

<ConfirmationDialog @ref="exportFeedDialog" OkText="Include Feed" CancelText="Just my data" OnOk="()=>ExportData(true)" OnCancel="()=>ExportData(false)">
<Headline>Backup Feed Account</Headline>
<TextContent>
<p>Include your feed account and followed users in this backup?</p>
<p class="text-error font-bold">Caution: This would allow anyone with this backup to post feed content with your account</p>
</TextContent>
</ConfirmationDialog>


@code {

private FeedState? importedFeedState;
private ConfirmationDialog? importFeedDialog;
private ConfirmationDialog? exportFeedDialog;
protected override void OnInitialized()
{
Dispatcher.Dispatch(new SetPageTitleAction("Backup and Restore"));
Dispatcher.Dispatch(new SetBackNavigationUrlAction("/settings"));
SubscribeToAction<BeginFeedImportAction>(OnBeginFeedImport);
base.OnInitialized();
}

Expand All @@ -31,5 +55,23 @@
Dispatcher.Dispatch(new SetStatsIsDirtyAction(true));
}

private void ExportData() => Dispatcher.Dispatch(new ExportDataAction());
private void ExportData(bool includeFeed) => Dispatcher.Dispatch(new ExportDataAction(includeFeed));

private void OnBeginFeedImport(BeginFeedImportAction action)
{
importedFeedState = action.FeedState;
importFeedDialog?.Open();
}

private void ImportFeedData()
{
if (importedFeedState is null)
{
return;
}

Dispatcher.Dispatch(new SetFeedStateAction(importedFeedState));
importedFeedState = null;
importFeedDialog?.Close();
}
}
2 changes: 1 addition & 1 deletion LiftLog.Ui/Pages/Settings/NotificationsPage.razor
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<ListSwitch Headline="Rest notifications" SupportingText="Show a notification when the rest timer is up" Value="@SettingsState.Value.RestNotifications" OnSwitched="SetRestNotifications" />
</md-list>

<AndroidNotificationAlert ForceShow="true" />
<AndroidNotificationAlert />

@code {
protected override void OnInitialized()
Expand Down
2 changes: 1 addition & 1 deletion LiftLog.Ui/Shared/MainLayout.razor
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@

<Microsoft.AspNetCore.Components.Sections.SectionOutlet SectionName="FullscreenDialog"></Microsoft.AspNetCore.Components.Sections.SectionOutlet>
<Microsoft.AspNetCore.Components.Sections.SectionOutlet SectionName="Dialog"></Microsoft.AspNetCore.Components.Sections.SectionOutlet>

<Microsoft.AspNetCore.Components.Sections.SectionOutlet SectionName="AndroidNotificationDialog"></Microsoft.AspNetCore.Components.Sections.SectionOutlet>
<div class="hidden">
<ApexChart
TItem="DummyChartType"
Expand Down
51 changes: 51 additions & 0 deletions LiftLog.Ui/Shared/Presentation/ConfirmationDialog.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@

<Dialog @ref="dialog" @ondialog-cancel="OnCancel">
<span slot="headline">@Headline</span>
<span slot="content" class="block text-left">
@TextContent
</span>
<div slot="actions">
<AppButton Type="AppButtonType.Text" OnClick="async () => { dialog?.Close(); await OnCancel.InvokeAsync(); }">@CancelText</AppButton>
<AppButton Type="AppButtonType.Text" OnClick="async () => { dialog?.Close(); await OnOk.InvokeAsync(); }">@OkText</AppButton>
</div>
</Dialog>

@code {
[Parameter]
[EditorRequired]
public RenderFragment Headline {get;set;} = null!;
[Parameter]
[EditorRequired]
public RenderFragment TextContent {get;set;} = null!;

[Parameter]
public string CancelText {get;set;} = "Cancel";

[Parameter]
public EventCallback OnCancel { get; set; }

[Parameter]
public string OkText { get; set; } = "Ok";

[Parameter]
public EventCallback OnOk { get; set; }

[Parameter] public string SectionName { get; set; } = "Dialog";

private Dialog? dialog;

public void Open()
{
dialog?.Open();
}

public void Close()
{
dialog?.Close();
}

public Task CloseWait()
{
return dialog?.CloseWait() ?? Task.CompletedTask;
}
}
4 changes: 3 additions & 1 deletion LiftLog.Ui/Shared/Presentation/Dialog.razor
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
@if (opened)
{
@* Put the dialog into a section in the main layout so that the scrim covers parent elements on ios *@
<Microsoft.AspNetCore.Components.Sections.SectionContent SectionName="Dialog">
<Microsoft.AspNetCore.Components.Sections.SectionContent SectionName="@SectionName">
<md-dialog
@ondialog-close="HandleDialogClose"
@ondialog-cancel="HandleDialogCancel"
Expand All @@ -28,6 +28,8 @@

[Parameter] public RenderFragment? ChildContent { get; set; }

[Parameter] public string SectionName { get; set; } = "Dialog";

public async void Open()
{
opened = true;
Expand Down
24 changes: 11 additions & 13 deletions LiftLog.Ui/Shared/Smart/AndroidNotificationAlert.razor
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,22 @@

@inject IDeviceService DeviceService

<Dialog @ref="androidNotificationDialog" OnCancel="DisableNotifications">
<span slot="headline">Enable Notifications?</span>
<span slot="content" class="block text-left">Newer Android devices require an additional permission to ensure that rest notifications are delivered on time.
<ConfirmationDialog @ref="androidNotificationDialog"
OkText="Grant"
OnOk="DeviceService.RequestExactNotificationPermission"
CancelText="Disable Notifications"
OnCancel="DisableNotifications"
SectionName="AndroidNotificationDialog">
<Headline>Enable Notifications?</Headline>
<TextContent>Newer Android devices require an additional permission to ensure that rest notifications are delivered on time.
Without this permission, they will arrive late and largely be useless.
On the next screen, please grant LiftLog the permission.</span>
<div slot="actions">
<AppButton Type="AppButtonType.Text" OnClick="() => { androidNotificationDialog?.Close(); DisableNotifications(); }">Disable Notifications</AppButton>
<AppButton Type="AppButtonType.Text" OnClick="() => { androidNotificationDialog?.Close(); DeviceService.RequestExactNotificationPermission(); }">Grant</AppButton>
</div>
</Dialog>
On the next screen, please grant LiftLog the permission.</TextContent>
</ConfirmationDialog>

@code
{
[Parameter]
public bool ForceShow { get; set; }

private Dialog? androidNotificationDialog;

private ConfirmationDialog? androidNotificationDialog;

protected override void OnAfterRender(bool firstRender)
{
Expand Down
2 changes: 2 additions & 0 deletions LiftLog.Ui/Store/Feed/FeedActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public record PutFollowedUsersAction(FeedUser User);

public record SetSharedFeedUserAction(FeedUser? User);

public record SetFeedStateAction(FeedState FeedState);

public record FetchAndSetSharedFeedUserAction(
string IdOrLookup,
string? Name,
Expand Down
4 changes: 4 additions & 0 deletions LiftLog.Ui/Store/Feed/FeedReducers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,8 @@ state with
{
SharedItem = action.SharedItem
};

[ReducerMethod]
public static FeedState SetFeedState(FeedState state, SetFeedStateAction action) =>
action.FeedState;
}
5 changes: 4 additions & 1 deletion LiftLog.Ui/Store/Settings/SettingsActions.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
using LiftLog.Lib;
using LiftLog.Lib.Models;
using LiftLog.Ui.Services;
using LiftLog.Ui.Store.Feed;

namespace LiftLog.Ui.Store.Settings;

public record ExportDataAction();
public record ExportDataAction(bool ExportFeed);

public record ImportDataAction();

public record ImportDataBytesAction(byte[] Bytes);

public record BeginFeedImportAction(FeedState FeedState);

public record GenerateAiPlanAction(AiWorkoutAttributes Attributes);

public record SetAiPlanAction(AiWorkoutPlan? Plan);
Expand Down
Loading

0 comments on commit fd565bb

Please sign in to comment.