From dab3cb47b79fbf12d7ab2cacb4e90fb873fc195c Mon Sep 17 00:00:00 2001 From: BOT Alex <44818698+MagicBOTAlex@users.noreply.github.com> Date: Thu, 29 Jun 2023 12:47:18 +0200 Subject: [PATCH] Now shows how many CChars left in the list --- LearningChineseFixed/Client/Program.cs | 5 +++++ LearningChineseFixed/Pages/Learn.razor | 8 ++++++++ LearningChineseFixed/Shared/MainLayout.razor | 9 +++++++++ LearningChineseFixed/wwwroot/index.html | 2 +- 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/LearningChineseFixed/Client/Program.cs b/LearningChineseFixed/Client/Program.cs index 299efc7..a8d84ff 100644 --- a/LearningChineseFixed/Client/Program.cs +++ b/LearningChineseFixed/Client/Program.cs @@ -9,6 +9,9 @@ namespace LearningChineseFixed { public class Program { + public static int CCharsLeft = 0; + public static Action UpdateUiEvent; + public static async Task Main(string[] args) { var builder = WebAssemblyHostBuilder.CreateDefault(args); @@ -27,5 +30,7 @@ namespace LearningChineseFixed await builder.Build().RunAsync(); } + + public static void InvokeUiUpdate() => UpdateUiEvent?.Invoke(); } } \ No newline at end of file diff --git a/LearningChineseFixed/Pages/Learn.razor b/LearningChineseFixed/Pages/Learn.razor index 5f7c162..1b9584d 100644 --- a/LearningChineseFixed/Pages/Learn.razor +++ b/LearningChineseFixed/Pages/Learn.razor @@ -107,16 +107,22 @@ protected override async Task OnInitializedAsync() { + Program.UpdateUiEvent += OnUiUpdate; + int selectedChunk = await localStorage.GetItemAsync("SelectedChunk"); //Charecters = await httpClient.GetFromJsonAsync("Data/NormalizedDataset.json"); Charecters = await httpClient.GetFromJsonAsync($"Data/Normalized_chunk_{selectedChunk.ToString("000")}.json"); DontSkipTheseCChar = Charecters.ToList(); + Program.CCharsLeft = DontSkipTheseCChar.Count; + Program.InvokeUiUpdate(); GenerateQuestion(); } + void OnUiUpdate() => StateHasChanged(); + void GenerateQuestion() { if (DontSkipTheseCChar.Count < 3) throw new Exception("Finished this chunk of CChars"); @@ -190,6 +196,8 @@ CChar correctChar = GetCorrectCChar(); DontSkipTheseCChar.Remove(correctChar); Console.WriteLine("Remaining CChars: " + DontSkipTheseCChar); + Program.CCharsLeft = DontSkipTheseCChar.Count; + Program.InvokeUiUpdate(); GenerateQuestion(); } diff --git a/LearningChineseFixed/Shared/MainLayout.razor b/LearningChineseFixed/Shared/MainLayout.razor index 60ab79a..226cdfa 100644 --- a/LearningChineseFixed/Shared/MainLayout.razor +++ b/LearningChineseFixed/Shared/MainLayout.razor @@ -5,6 +5,10 @@ + @if (Program.CCharsLeft > 0) + { + @("CChars left: " + Program.CCharsLeft) + } @@ -17,5 +21,10 @@ @code { + protected override async Task OnInitializedAsync() + { + Program.UpdateUiEvent += OnUiUpdate; + } + void OnUiUpdate() => StateHasChanged(); } \ No newline at end of file diff --git a/LearningChineseFixed/wwwroot/index.html b/LearningChineseFixed/wwwroot/index.html index aa07e49..511dc28 100644 --- a/LearningChineseFixed/wwwroot/index.html +++ b/LearningChineseFixed/wwwroot/index.html @@ -8,7 +8,7 @@ - +