Compare commits

...

5 Commits

Author SHA1 Message Date
BOT Alex ebdb75e38e Tweaked duration of snackbar 2023-06-29 13:27:58 +02:00
BOT Alex 1a0c59af3a Now resets and kicks user back to chunk selection if the chunk has been learnt 2023-06-29 13:19:27 +02:00
BOT Alex 2a49117995 Now it doesn't show the same CChar pinyin in selection 2023-06-29 13:13:04 +02:00
BOT Alex dab3cb47b7 Now shows how many CChars left in the list 2023-06-29 12:47:18 +02:00
BOT Alex f634474923 Fixed some things 2023-06-29 10:28:51 +02:00
8 changed files with 68 additions and 60 deletions

View File

@ -9,6 +9,9 @@ namespace LearningChineseFixed
{ {
public class Program public class Program
{ {
public static int CCharsLeft = 0;
public static Action UpdateUiEvent;
public static async Task Main(string[] args) public static async Task Main(string[] args)
{ {
var builder = WebAssemblyHostBuilder.CreateDefault(args); var builder = WebAssemblyHostBuilder.CreateDefault(args);
@ -20,10 +23,14 @@ namespace LearningChineseFixed
{ {
config.SnackbarConfiguration.ShowTransitionDuration = 100; config.SnackbarConfiguration.ShowTransitionDuration = 100;
config.SnackbarConfiguration.HideTransitionDuration = 100; config.SnackbarConfiguration.HideTransitionDuration = 100;
config.SnackbarConfiguration.VisibleStateDuration = 7500;
config.SnackbarConfiguration.PositionClass = Defaults.Classes.Position.BottomCenter;
}); });
builder.Services.AddBlazoredLocalStorage(); builder.Services.AddBlazoredLocalStorage();
await builder.Build().RunAsync(); await builder.Build().RunAsync();
} }
public static void InvokeUiUpdate() => UpdateUiEvent?.Invoke();
} }
} }

View File

@ -35,7 +35,7 @@
</MudContainer> </MudContainer>
@code{ @code{
int numOfChunks = 100; //Exclusive index 0 int numOfChunks = 197; //Exclusive index 0
int selectedChunk = 0; int selectedChunk = 0;
protected override void OnInitialized() protected override void OnInitialized()

View File

@ -27,7 +27,9 @@
<MudContainer Class="justify-center d-flex ma-0" Style="height: 100%;"> <MudContainer Class="justify-center d-flex ma-0" Style="height: 100%;">
<MudStack Class="d-flex"> <MudStack Class="d-flex">
<MudStack Row=true Class="pt-2 d-flex justify-center"> <MudStack Row=true Class="pt-2 d-flex justify-center">
<MudButton Color="Color.Default" OnClick="RemoveCCharFromSelection" Variant="Variant.Outlined">Skip</MudButton> <MudButton Color="Color.Default" OnClick="RemoveCCharFromSelection" Variant="Variant.Outlined">Avoid</MudButton>
<MudButton Color="Color.Default" Variant="Variant.Outlined" OnClick="ShowMeaning">Meaning</MudButton>
<MudButton Color="Color.Default" Variant="Variant.Outlined" OnClick="ShowPinyin">Pinyin</MudButton>
</MudStack> </MudStack>
<MudContainer> <MudContainer>
<MudPaper Class="pa-16 ma-2 rounded-xl mud-dark" Elevation="1"> <MudPaper Class="pa-16 ma-2 rounded-xl mud-dark" Elevation="1">
@ -105,29 +107,58 @@
protected override async Task OnInitializedAsync() protected override async Task OnInitializedAsync()
{ {
Program.UpdateUiEvent += OnUiUpdate;
int selectedChunk = await localStorage.GetItemAsync<int>("SelectedChunk"); int selectedChunk = await localStorage.GetItemAsync<int>("SelectedChunk");
//Charecters = await httpClient.GetFromJsonAsync<CChar[]>("Data/NormalizedDataset.json"); //Charecters = await httpClient.GetFromJsonAsync<CChar[]>("Data/NormalizedDataset.json");
Charecters = await httpClient.GetFromJsonAsync<CChar[]>($"Data/Normalized_chunk_{selectedChunk.ToString("000")}.json"); Charecters = await httpClient.GetFromJsonAsync<CChar[]>($"Data/Normalized_chunk_{selectedChunk.ToString("000")}.json");
DontSkipTheseCChar = Charecters.ToList(); DontSkipTheseCChar = Charecters.ToList();
Program.CCharsLeft = DontSkipTheseCChar.Count;
Program.InvokeUiUpdate();
GenerateQuestion(); GenerateQuestion();
} }
void OnUiUpdate() => StateHasChanged();
void GenerateQuestion() void GenerateQuestion()
{ {
if (DontSkipTheseCChar.Count < 3) throw new Exception("Finished this chunk of CChars"); if (DontSkipTheseCChar.Count < 5)
{
FinishAndKickBackToLearn();
return;
}
int correctIndex = Random.Shared.Next(0, Answers.Length); int correctIndex = Random.Shared.Next(0, Answers.Length);
for (int i = 0; i < Answers.Length; i++) for (int i = 0; i < Answers.Length; i++)
{ {
bool isCorrect = i == correctIndex; bool isCorrect = i == correctIndex;
Answers[i] = new Answer(DontSkipTheseCChar[Random.Shared.Next(0, DontSkipTheseCChar.Count)], isCorrect); CChar randomCChar;
repickRandomCChar:
randomCChar = DontSkipTheseCChar[Random.Shared.Next(0, DontSkipTheseCChar.Count)];
if (Answers.Any(x =>x != null && x.cchar == randomCChar)) goto repickRandomCChar;
Answers[i] = new Answer(randomCChar, isCorrect);
} }
} }
void FinishAndKickBackToLearn()
{
Snackbar.Add("Congrats, you have compleated this chunk!", Severity.Success, config =>
{
config.RequireInteraction = true;
config.CloseAfterNavigation = false;
});
Program.UpdateUiEvent -= OnUiUpdate;
Program.CCharsLeft = 0;
navigator.NavigateTo("");
}
async void Submit() async void Submit()
{ {
bool isCorrect = Answers.Any(x => x.isCorrect && x.isSelected); bool isCorrect = Answers.Any(x => x.isCorrect && x.isSelected);
@ -146,8 +177,8 @@
<li>Correct answer: @correctCChar.pinyin.ToTitleCase()</li> <li>Correct answer: @correctCChar.pinyin.ToTitleCase()</li>
<li>Meaning: @correctCChar.definition</li> <li>Meaning: @correctCChar.definition</li>
</ul> </ul>
</div> </div>
, Severity.Error); , Severity.Error);
} }
GenerateQuestion(); GenerateQuestion();
@ -188,6 +219,18 @@
CChar correctChar = GetCorrectCChar(); CChar correctChar = GetCorrectCChar();
DontSkipTheseCChar.Remove(correctChar); DontSkipTheseCChar.Remove(correctChar);
Console.WriteLine("Remaining CChars: " + DontSkipTheseCChar); Console.WriteLine("Remaining CChars: " + DontSkipTheseCChar);
Program.CCharsLeft = DontSkipTheseCChar.Count;
Program.InvokeUiUpdate();
GenerateQuestion(); GenerateQuestion();
} }
public void ShowMeaning()
{
Snackbar.Add($"<b>Definition:</b> {GetCorrectCChar().definition}", Severity.Info);
}
public void ShowPinyin()
{
Snackbar.Add($"<b>Pinyin:</b> {GetCorrectCChar().pinyin.ToTitleCase()}", Severity.Info);
}
} }

View File

@ -8,7 +8,7 @@
}, },
"dotnetRunMessages": true, "dotnetRunMessages": true,
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}", "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
"applicationUrl": "http://localhost:5198;http:/0.0.0.0:420/" "applicationUrl": "http://localhost:5198;http://0.0.0.0:420/"
}, },
"IIS Express": { "IIS Express": {
"commandName": "IISExpress", "commandName": "IISExpress",
@ -23,7 +23,7 @@
"windowsAuthentication": false, "windowsAuthentication": false,
"anonymousAuthentication": true, "anonymousAuthentication": true,
"iisExpress": { "iisExpress": {
"applicationUrl": "http://localhost:24989", "applicationUrl": "http://localhost:7860",
"sslPort": 0 "sslPort": 0
} }
} }

View File

@ -5,6 +5,10 @@
<MudLayout> <MudLayout>
<MudAppBar Elevation="0"> <MudAppBar Elevation="0">
@if (Program.CCharsLeft > 0)
{
<MudText>@("CChars left: " + Program.CCharsLeft)</MudText>
}
<MudSpacer /> <MudSpacer />
<MudIconButton Icon="@Icons.Custom.Brands.MudBlazor" Color="Color.Inherit" Link="https://mudblazor.com/" Target="_blank" /> <MudIconButton Icon="@Icons.Custom.Brands.MudBlazor" Color="Color.Inherit" Link="https://mudblazor.com/" Target="_blank" />
<MudIconButton Icon="@Icons.Custom.Brands.LinkedIn" Color="Color.Inherit" Link="https://www.linkedin.com/in/zhentao-wei-3a3a0a182/" Target="_blank" /> <MudIconButton Icon="@Icons.Custom.Brands.LinkedIn" Color="Color.Inherit" Link="https://www.linkedin.com/in/zhentao-wei-3a3a0a182/" Target="_blank" />
@ -17,5 +21,10 @@
</MudLayout> </MudLayout>
@code { @code {
protected override async Task OnInitializedAsync()
{
Program.UpdateUiEvent += OnUiUpdate;
}
void OnUiUpdate() => StateHasChanged();
} }

View File

@ -8,7 +8,7 @@
<base href="/" /> <base href="/" />
<link href="css/bootstrap/bootstrap.min.css" rel="stylesheet" /> <link href="css/bootstrap/bootstrap.min.css" rel="stylesheet" />
<link href="css/app.css" rel="stylesheet" /> <link href="css/app.css" rel="stylesheet" />
<link href="LearningChineseFixed.styles.css" rel="stylesheet" /> <!--<link href="LearningChineseFixed.styles.css" rel="stylesheet" />-->
<link href="manifest.json" rel="manifest" /> <link href="manifest.json" rel="manifest" />
<link rel="apple-touch-icon" sizes="512x512" href="icon-512.png" /> <link rel="apple-touch-icon" sizes="512x512" href="icon-512.png" />
<link rel="apple-touch-icon" sizes="192x192" href="icon-192.png" /> <link rel="apple-touch-icon" sizes="192x192" href="icon-192.png" />

View File

@ -1,21 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<ServiceWorkerAssetsManifest>service-worker-assets.js</ServiceWorkerAssetsManifest>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Blazored.LocalStorage" Version="4.3.0" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="6.0.19" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="6.0.19" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="6.0.19" />
<PackageReference Include="MudBlazor" Version="6.5.0" />
</ItemGroup>
<ItemGroup>
<ServiceWorker Include="wwwroot\service-worker.js" PublishedContent="wwwroot\service-worker.published.js" />
</ItemGroup>
</Project>

View File

@ -1,30 +0,0 @@
{
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}"
},
"Mudblazor.Template": {
"commandName": "Project",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"dotnetRunMessages": "true",
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
"applicationUrl": "https://localhost:5001;http://0.0.0.0:420"
}
},
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:65283",
"sslPort": 44398
}
}
}