Skip to content

Commit

Permalink
Handle the case where a user does not have an identity on a share link
Browse files Browse the repository at this point in the history
  • Loading branch information
LiamMorrow committed Jan 6, 2024
1 parent 0ad933e commit afbf219
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 9 deletions.
8 changes: 6 additions & 2 deletions LiftLog.Ui/Pages/Feed/CreateFeedIdentityPage.razor
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
@if(FeedState.Value.Identity == null)
{
<div class="text-on-surface flex flex-col gap-4 p-4">
<span class="text-lg">Create a new identity to start publishing!</span>
<span class="text-lg">Create a new identity to start using the feed!</span>
<TextField Value="@(FeedState.Value.Identity?.Name ?? "")" label="Your name (optional)" OnChange=@SetName />
<div>
<Switch Label="Publish bodyweight" Value=@publishBodyweight OnSwitched="SetPublishBodyweight"/>
Expand Down Expand Up @@ -55,6 +55,10 @@ else
private bool publishBodyweight;
private bool publishPlan;
private Dialog? stopPublishingDialog;

[SupplyParameterFromQuery(Name="from")]
public string From { get; set; } = "";

protected override void OnInitialized()
{
Dispatcher.Dispatch(new SetPageTitleAction("Start Publishing"));
Expand All @@ -67,7 +71,7 @@ else

private void StartPublishing()
{
Dispatcher.Dispatch(new CreateFeedIdentityAction(Guid.NewGuid(), string.IsNullOrEmpty(name) ? null : name, null, publishBodyweight, publishPlan));
Dispatcher.Dispatch(new CreateFeedIdentityAction(Guid.NewGuid(), string.IsNullOrEmpty(name) ? null : name, null, publishBodyweight, publishPlan, From == null ? null : From));
}

private void UpdatePublishingDetails()
Expand Down
9 changes: 5 additions & 4 deletions LiftLog.Ui/Pages/Feed/FeedSharePage.razor
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
@inject IState<FeedState> FeedState
@inject IStringSharer StringSharer
@inject IDispatcher Dispatcher
@inject NavigationManager NavigationManager

@inherits Fluxor.Blazor.Web.Components.FluxorComponent

Expand Down Expand Up @@ -48,7 +47,9 @@ else
Dispatcher.Dispatch(new SetBackNavigationUrlAction("/feed"));
if(String.IsNullOrEmpty(PublicKey) || id == Guid.Empty)
{
NavigationManager.NavigateTo("/feed");
Dispatcher.Dispatch(new NavigateAction("/feed"));
}else if(FeedState.Value.Identity is null) {
Dispatcher.Dispatch(new NavigateAction("/feed/create-identity?from=" + Uri.EscapeDataString("/feed/share?pub=" + PublicKey + "&id=" + id + "&name=" + Name ?? "")));
}else
{
Dispatcher.Dispatch(new SetSharedFeedUserAction(FeedUser.FromShared(id, PublicKey.FromUrlSafeHexString(), Name)));
Expand All @@ -61,7 +62,7 @@ else
private void HandleNoThanksClick()
{
Dispatcher.Dispatch(new SetSharedFeedUserAction(null));
NavigationManager.NavigateTo("/feed");
Dispatcher.Dispatch(new NavigateAction("/feed"));
}

private void HandleSureClick()
Expand All @@ -72,7 +73,7 @@ else
}
Dispatcher.Dispatch(new RequestFollowSharedUserAction(FeedState.Value.SharedFeedUser));
Dispatcher.Dispatch(new SetSharedFeedUserAction(null));
NavigationManager.NavigateTo("/feed");
Dispatcher.Dispatch(new NavigateAction("/feed"));
}

private void UpdateNickname(string value)
Expand Down
2 changes: 2 additions & 0 deletions LiftLog.Ui/Store/App/AppActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ public record SetProTokenAction(string? ProToken);
public record SetReopenCurrentSessionAction(bool ReopenCurrentSession);

public record SetBackNavigationUrlAction(string? BackNavigationUrl);

public record NavigateAction(string Path);
12 changes: 11 additions & 1 deletion LiftLog.Ui/Store/App/AppEffects.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,21 @@

namespace LiftLog.Ui.Store.App;

public class AppEffects(PreferencesRepository preferencesRepository)
public class AppEffects(
PreferencesRepository preferencesRepository,
NavigationManager navigationManager
)
{
[EffectMethod]
public async Task HandleSetProTokenAction(SetProTokenAction action, IDispatcher dispatcher)
{
await preferencesRepository.SetProTokenAsync(action.ProToken);
}

[EffectMethod]
public Task HandleNavigateAction(NavigateAction action, IDispatcher dispatcher)
{
navigationManager.NavigateTo(action.Path);
return Task.CompletedTask;
}
}
3 changes: 2 additions & 1 deletion LiftLog.Ui/Store/Feed/FeedActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ public record CreateFeedIdentityAction(
string? Name,
byte[]? ProfilePicture,
bool PublishBodyweight,
bool PublishPlan
bool PublishPlan,
string? RedirectAfterCreation
);

public record UpdateFeedIdentityAction(
Expand Down
8 changes: 7 additions & 1 deletion LiftLog.Ui/Store/Feed/FeedEffects.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using LiftLog.Ui.Models;
using LiftLog.Ui.Models.SessionHistoryDao;
using LiftLog.Ui.Services;
using LiftLog.Ui.Store.App;
using LiftLog.Ui.Store.Program;
using LiftLog.Ui.Util;
using Microsoft.Extensions.Logging;
Expand Down Expand Up @@ -200,6 +201,10 @@ await GenerateAndPutFeedIdentityAsync(
action.PublishPlan
);
dispatcher.Dispatch(new SetIsLoadingIdentityAction(false));
if (action.RedirectAfterCreation is not null or "")
{
dispatcher.Dispatch(new NavigateAction(action.RedirectAfterCreation));
}
}

[EffectMethod]
Expand Down Expand Up @@ -678,7 +683,8 @@ await encryptionService.EncryptAesAsync(
name,
profilePicture,
publishBodyweight,
publishPlan
publishPlan,
null
)
);
return;
Expand Down

0 comments on commit afbf219

Please sign in to comment.