From 8442e3d7b0e23c9dbf7bac5653c69d5ec5c45d24 Mon Sep 17 00:00:00 2001 From: NICK BRAIN Date: Sun, 1 Dec 2024 13:45:18 +0200 Subject: [PATCH] Add/remove sample sentence works --- My1kWordsEe/Components/Layout/SampleV2.razor | 40 ++++++++++++------- My1kWordsEe/Components/Pages/WordPage.razor | 25 +++++++----- .../Cqs/RemoveFromFavoritesCommand.cs | 10 +++++ My1kWordsEe/wwwroot/app.css | 4 ++ 4 files changed, 56 insertions(+), 23 deletions(-) diff --git a/My1kWordsEe/Components/Layout/SampleV2.razor b/My1kWordsEe/Components/Layout/SampleV2.razor index c7d026ac..df1e0873 100644 --- a/My1kWordsEe/Components/Layout/SampleV2.razor +++ b/My1kWordsEe/Components/Layout/SampleV2.razor @@ -21,6 +21,15 @@ [Parameter] public required SampleSentence Sample { get; init; } + [Parameter] + public required Func AddToFavorites { get; init; } + + [Parameter] + public required Func RemoveFromFavorites { get; init; } + + [Parameter] + public bool IsFavorite { get; init; } + private ConfirmDialog DeleteSampleDialog = default!; [Inject] protected ToastService ToastService { get; set; } = default!; @@ -108,27 +117,30 @@ - @if (IsAdmin) + @if (IsLoggedIn) {
  • - + @if (IsFavorite) + { + + } + else + { + + }
  • } - @if (IsLoggedIn) + @if (IsAdmin) { - // todo add phrase to favorites - @*
  • - -
  • - -
  • *@ + } diff --git a/My1kWordsEe/Components/Pages/WordPage.razor b/My1kWordsEe/Components/Pages/WordPage.razor index 7d2a7afb..ffa3fad6 100644 --- a/My1kWordsEe/Components/Pages/WordPage.razor +++ b/My1kWordsEe/Components/Pages/WordPage.razor @@ -65,20 +65,22 @@ return await commonSample; } - private async Task AddToFavorites() + private async Task AddToFavorites(dynamic favorite) { PreloadService.Show(SpinnerColor.Light, "Saving data..."); var user = await UserAccessor.GetRequiredUserAsync(User); - Favorites = await AddToFavoritesCommand.Invoke(user.Id, Value); + Favorites = await AddToFavoritesCommand.Invoke(user.Id, favorite); PreloadService.Hide(); + StateHasChanged(); } - private async Task RemoveFromFavorites() + private async Task RemoveFromFavorites(dynamic favorite) { PreloadService.Show(SpinnerColor.Light, "Saving data..."); var user = await UserAccessor.GetRequiredUserAsync(User); - Favorites = await RemoveFromFavoritesCommand.Invoke(user.Id, Value); + Favorites = await RemoveFromFavoritesCommand.Invoke(user.Id, favorite); PreloadService.Hide(); + StateHasChanged(); } private bool IsSampleGenerationInProgress = false; @@ -108,7 +110,9 @@ private bool IsLoggedIn => User?.Identity?.IsAuthenticated ?? false; - private bool IsFavorite => IsDataLoadedOk && IsLoggedIn && Favorites.HasValue && Favorites.Value.IsSuccess && Favorites.Value.Value.Words.ContainsKey(EeWord.ToLower()); + private bool IsFavorite() => IsDataLoadedOk && IsLoggedIn && Favorites.HasValue && Favorites.Value.IsSuccess && Favorites.Value.Value.Words.ContainsKey(EeWord.ToLower()); + + private bool IsFavorite(SampleSentence sentence) => IsDataLoadedOk && IsLoggedIn && Favorites.HasValue && Favorites.Value.IsSuccess && Favorites.Value.Value.Sentences.ContainsKey(sentence.EeSentence.ToLower()); }