Skip to content

Commit

Permalink
+ Fav sentences Tabs (#116)
Browse files Browse the repository at this point in the history
* + Sentences model
* Add/remove sample sentence works
  • Loading branch information
NicklausBrain authored Dec 1, 2024
1 parent 08a0b4d commit 1046cda
Show file tree
Hide file tree
Showing 12 changed files with 248 additions and 153 deletions.
14 changes: 4 additions & 10 deletions My1kWordsEe/Components/Layout/GameComposite.razor
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
{
public string Title { get; set; }
}

class GameCompositeModel
{
public Slide[] Slides { get; set; } = new Slide[] { };
Expand All @@ -24,19 +25,19 @@

public Slide CurrentSlide { get; set; }
}

GameCompositeModel Game = new();

private void OnNext() { }// Game.NextSlide();
private void OnNext() { } // Game.NextSlide();
private void OnPrevious() { } //Game.PrevSlide();
private void OnSelectSlide(ushort index) { } // Game.GoToSlide(index);
private Task OnSubmit()
{

return Task.CompletedTask;
} //=> { }; Game.CurrentSlide.Submit(CheckEnTranslationCommand);
}
}


Expand All @@ -49,13 +50,6 @@
})
</script>

<style>
.img-max-w-256 {
max-width: 256px;
width: 100%;
}
</style>

<h3>GameComposite</h3>

<div class="text-left">
Expand Down
87 changes: 27 additions & 60 deletions My1kWordsEe/Components/Layout/SampleV2.razor
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,24 @@

@inject IdentityUserAccessor UserAccessor
@inject AuthenticationStateProvider AuthenticationStateProvider
@inject DeleteSampleSentenceCommand DeleteSampleSentenceCommand
@inject NavigationManager NavigationManager
@inject IJSRuntime JS

@code {
[Parameter]
public required SampleSentence Sample { get; init; }

private ConfirmDialog DeleteSampleDialog = default!;
[Parameter]
public Func<SampleSentence, Task>? AddToFavorites { get; init; }

[Parameter]
public Func<SampleSentence, Task>? RemoveFromFavorites { get; init; }

[Inject] protected ToastService ToastService { get; set; } = default!;
[Parameter]
public Func<SampleSentence, Task>? DeleteSample { get; init; }

[Parameter]
public bool IsFavorite { get; init; }

private bool IsAdmin { get; set; } = false;

Expand All @@ -43,39 +50,6 @@
{
await JS.InvokeVoidAsync("playAudioSample", Sample.EeAudioUrl);
}

private async Task ShowDeleteConfirmationAsync()
{
var options = new ConfirmDialogOptions
{
IsScrollable = true,
Dismissable = true,
IsVerticallyCentered = true,
AutoFocusYesButton = false,
};

var confirmation = await DeleteSampleDialog.ShowAsync(
title: "Are you sure you want to delete this?",
message1: "This will delete the record. Once deleted can not be rolled back.",
message2: "Do you want to proceed?", options);

if (confirmation)
{
var deletionResult = await this.DeleteSampleSentenceCommand.Invoke(Sample);
if (deletionResult.IsSuccess)
{
this.NavigationManager.Refresh(true);
}
else
{
ToastService.Notify(new ToastMessage(ToastType.Warning, deletionResult.Error));
}
}
else
{
ToastService.Notify(new ToastMessage(ToastType.Secondary, $"Delete action canceled."));
}
}
}

<script>
Expand All @@ -85,13 +59,6 @@
};
</script>

<style>
.img-max-w-256 {
max-width: 256px;
width: 100%;
}
</style>

<Card>
<CardBody>
<table class="table">
Expand All @@ -108,27 +75,30 @@
</Button>
<audio id="@Sample.EeAudioUrl" src="@Sample.EeAudioUrl"></audio>
</li>
@if (IsAdmin)
@if (IsLoggedIn)
{
<li class="list-group-item border-0">
<Button Color="ButtonColor.Danger" Size="ButtonSize.Small" @onclick="ShowDeleteConfirmationAsync">
<i class="bi bi-trash3-fill"></i>
</Button>
@if (IsFavorite && RemoveFromFavorites != null)
{
<Button Color="ButtonColor.Primary" Outline="true" Size="ButtonSize.Small" @onclick="() => RemoveFromFavorites(Sample)">
<i role="button" class="bi bi-star-fill"></i>
</Button>
}
else if (AddToFavorites != null)
{
<Button Color="ButtonColor.Primary" Outline="true" Size="ButtonSize.Small" @onclick="() => AddToFavorites(Sample)">
<i role="button" class="bi bi-star"></i>
</Button>
}
</li>
}
@if (IsLoggedIn)
@if (IsAdmin && DeleteSample != null)
{
// todo add phrase to favorites
@* <li class="list-group-item border-0">
<Button Color="ButtonColor.Secondary" Size="ButtonSize.Small">
<i class="bi bi-star"></i>
</Button>
</li>
<li class="list-group-item border-0">
<Button Color="ButtonColor.Secondary" Size="ButtonSize.Small">
<i class="bi bi-star-fill"></i>
<Button Color="ButtonColor.Danger" Size="ButtonSize.Small" @onclick="() => DeleteSample(Sample)">
<i class="bi bi-trash3-fill"></i>
</Button>
</li> *@
</li>
}
</ul>
</td>
Expand All @@ -147,6 +117,3 @@
</table>
</CardBody>
</Card>

<ConfirmDialog @ref="DeleteSampleDialog" />
<Toasts class="p-3" AutoHide="true" StackLength="3" Placement="ToastsPlacement.TopRight" />
145 changes: 102 additions & 43 deletions My1kWordsEe/Components/Pages/FavoritesPage.razor
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@page "/favorites"
@rendermode InteractiveServer
@rendermode @(new InteractiveServerRenderMode(prerender: true))

@using BlazorBootstrap
@using CSharpFunctionalExtensions
Expand All @@ -14,71 +14,130 @@
@inject GetFavoritesQuery GetFavoritesQuery
@inject AuthenticationStateProvider AuthenticationStateProvider
@inject IdentityUserAccessor UserAccessor
@inject AddToFavoritesCommand AddToFavoritesCommand
@inject RemoveFromFavoritesCommand RemoveFromFavoritesCommand

@code {
[Inject] protected PreloadService PreloadService { get; set; } = default!;

private ClaimsPrincipal? User;

private Maybe<Result<Favorites>> Favorites;

protected override async Task OnParametersSetAsync()
{
var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
if (authState != null)
{
User = authState.User;
var user = await UserAccessor.GetRequiredUserAsync(authState.User);
Favorites = await GetFavoritesQuery.Invoke(user.Id);
}

await base.OnParametersSetAsync();
}

private async Task AddToFavorites(dynamic favorite)
{
PreloadService.Show(SpinnerColor.Light, "Saving data...");
var user = await UserAccessor.GetRequiredUserAsync(User);

Check warning on line 43 in My1kWordsEe/Components/Pages/FavoritesPage.razor

View workflow job for this annotation

GitHub Actions / test

Possible null reference argument for parameter 'user' in 'Task<ApplicationUser> IdentityUserAccessor.GetRequiredUserAsync(ClaimsPrincipal user)'.

Check warning on line 43 in My1kWordsEe/Components/Pages/FavoritesPage.razor

View workflow job for this annotation

GitHub Actions / build

Possible null reference argument for parameter 'user' in 'Task<ApplicationUser> IdentityUserAccessor.GetRequiredUserAsync(ClaimsPrincipal user)'.
Favorites = await AddToFavoritesCommand.Invoke(user.Id, favorite);
PreloadService.Hide();
StateHasChanged();
}

private async Task RemoveFromFavorites(dynamic favorite)
{
PreloadService.Show(SpinnerColor.Light, "Saving data...");
var user = await UserAccessor.GetRequiredUserAsync(User);
Favorites = await RemoveFromFavoritesCommand.Invoke(user.Id, favorite);
PreloadService.Hide();
StateHasChanged();
}

private IDictionary<string, SampleWord> FavoriteWords => Favorites.Value.Value.Words;

private IDictionary<string, SampleSentence> FavoriteSentences => Favorites.Value.Value.Sentences;
}

<PageTitle>Favorites | Lemmikud</PageTitle>

<h1>Favorites | Lemmikud</h1>

<div class="text-center">
<div class="row">
@if (Favorites.HasValue && Favorites.Value.IsSuccess)
{
var favorites = Favorites.Value.Value;

@if (favorites.Words.Any())
{
foreach (var wordPair in favorites.Words)
{
var word = wordPair.Value;
<div class="col col-12 col-sm-6 p-1">
<Card>
<CardBody>
<CardTitle>
@word.EeWord
</CardTitle>
<CardSubTitle>@word.EnWord</CardSubTitle>
<CardText>@word.EnExplanation</CardText>
<CardLink To="@($"/word/{word.EeWord}")">
<i role="link" class="bi bi-box-arrow-up-right"></i>
</CardLink>
</CardBody>
</Card>
@if (Favorites.HasValue && Favorites.Value.IsSuccess)
{
<Tabs EnableFadeEffect="true">
<Tab Title="Words" Active="true">
<Content>
<div class="row">
@if (FavoriteWords.Any())
{
foreach (var wordPair in FavoriteWords)
{
var word = wordPair.Value;
<div class="col col-12 col-sm-4 p-1">
<Card>
<CardBody>
<CardTitle>
@word.EeWord
</CardTitle>
<CardSubTitle>@word.EnWord</CardSubTitle>
<CardText>@word.EnExplanation</CardText>
<CardLink To="@($"/word/{word.EeWord}")">
<i role="link" class="bi bi-box-arrow-up-right"></i>
</CardLink>
</CardBody>
</Card>
</div>
}
}
else
{
<p class="mt-3">No favorite words yet</p>
}
</div>
</Content>
</Tab>
<Tab Title="Sentences">
<Content>
<div class="row">
@if (FavoriteSentences.Any())
{
@foreach (var sentencePair in FavoriteSentences)
{
var sentence = sentencePair.Value;
<div class="col col-12 col-sm-6 p-1">
<SampleV2 Sample="sentence"
AddToFavorites="AddToFavorites"
RemoveFromFavorites="RemoveFromFavorites"
IsFavorite="true">
</SampleV2>
</div>
}
}
else
{
<p class="mt-3">No favorite sentences yet</p>
}
</div>
</Content>
</Tab>
</Tabs>
}

}
}
else
{
<h3>No favorites yet!</h3>
}
}
@if (Favorites.HasNoValue)
{
<div class="text-center">
<Spinner />
</div>
}

@if (Favorites.HasNoValue)
{
<div class="text-center">
<Spinner />
</div>
}
@if (Favorites.HasValue && Favorites.Value.IsFailure)
{
<h3 class="alert-warning">@Favorites.Value.Error</h3>
}
</div>

@if (Favorites.HasValue && Favorites.Value.IsFailure)
{
<h3 class="alert-warning">@Favorites.Value.Error</h3>
}
</div>
</div>

<Preload LoadingText="Loading..." />
8 changes: 0 additions & 8 deletions My1kWordsEe/Components/Pages/Games/ListenToEeGamePage.razor
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,6 @@
};
</script>

@* todo: extract style *@
<style>
.img-max-w-256 {
max-width: 256px;
width: 100%;
}
</style>

<div class="text-left">
<div class="row">
<div class="col-7">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,6 @@
};
</script>

@* todo: extract style *@
<style>
.img-max-w-256 {
max-width: 256px;
width: 100%;
}
</style>

<div class="text-left">
<div class="row">
<div class="col-7">
Expand Down
Loading

0 comments on commit 1046cda

Please sign in to comment.