Added continue learning support!!!
This commit is contained in:
parent
b5870a4279
commit
2264087322
3 changed files with 106 additions and 14 deletions
|
@ -15,7 +15,17 @@
|
||||||
}
|
}
|
||||||
</MudSelect>
|
</MudSelect>
|
||||||
<MudContainer Class="justify-center d-flex pb-16 pt-4">
|
<MudContainer Class="justify-center d-flex pb-16 pt-4">
|
||||||
<MudButton Variant="Variant.Filled" OnClick=StartLearning Color="Color.Primary">Start learning!</MudButton>
|
<MudButton Variant="Variant.Filled" OnClick=StartLearning Color="Color.Primary">@((!continueDataExists) ? "Start learning!" : "Start new!")</MudButton>
|
||||||
|
<MudStack Spacing="0" Class="pa-0 pl-2 ma-0">
|
||||||
|
<MudButton Variant="Variant.Filled" Color="Color.Success" OnClick="ContinueLearning" Disabled="@(!continueDataExists)">Continue</MudButton>
|
||||||
|
@if (continueDataExists)
|
||||||
|
{
|
||||||
|
<MudStack Row=true Spacing="0">
|
||||||
|
<MudText Class="pa-0 ma-0" Typo="Typo.body1">@($"CChars left: {continueCharectersLeft}")</MudText>
|
||||||
|
<MudIconButton Class="pa-0 ma-0" OnClick="DeleteContinueData" Color="Color.Error" Icon="@Icons.Material.Filled.Close"></MudIconButton>
|
||||||
|
</MudStack>
|
||||||
|
}
|
||||||
|
</MudStack>
|
||||||
</MudContainer>
|
</MudContainer>
|
||||||
|
|
||||||
<MudContainer Class="justify-center d-flex">
|
<MudContainer Class="justify-center d-flex">
|
||||||
|
@ -63,9 +73,13 @@
|
||||||
int numOfChunks = 197; //Exclusive index 0
|
int numOfChunks = 197; //Exclusive index 0
|
||||||
int selectedChunk = 0;
|
int selectedChunk = 0;
|
||||||
int savedChunks = 0;
|
int savedChunks = 0;
|
||||||
|
const int chunkSize = 50;
|
||||||
|
|
||||||
bool isLoading = false;
|
bool isLoading = false;
|
||||||
bool isSavedLocally = false;
|
bool isSavedLocally = false;
|
||||||
|
bool continueDataExists = false;
|
||||||
|
int continueCharectersLeft = -1;
|
||||||
|
|
||||||
|
|
||||||
protected async override Task OnInitializedAsync()
|
protected async override Task OnInitializedAsync()
|
||||||
{
|
{
|
||||||
|
@ -79,9 +93,25 @@
|
||||||
async void StartLearning()
|
async void StartLearning()
|
||||||
{
|
{
|
||||||
await localStorage.SetItemAsync("SelectedChunk", selectedChunk);
|
await localStorage.SetItemAsync("SelectedChunk", selectedChunk);
|
||||||
|
await localStorage.SetItemAsync("ContinueLearning", false);
|
||||||
navigator.NavigateTo("/Learn");
|
navigator.NavigateTo("/Learn");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async void ContinueLearning()
|
||||||
|
{
|
||||||
|
await localStorage.SetItemAsync("ContinueLearning", true);
|
||||||
|
navigator.NavigateTo("/Learn");
|
||||||
|
}
|
||||||
|
|
||||||
|
async void DeleteContinueData()
|
||||||
|
{
|
||||||
|
string[] continueDataKeys = { "ContinueLearning", "ContinueData", "ContinueCharectersLeft" };
|
||||||
|
await localStorage.RemoveItemsAsync(continueDataKeys);
|
||||||
|
continueDataExists = false;
|
||||||
|
|
||||||
|
StateHasChanged();
|
||||||
|
}
|
||||||
|
|
||||||
CChar[]? Charecters;
|
CChar[]? Charecters;
|
||||||
async void SelectedChunk()
|
async void SelectedChunk()
|
||||||
{
|
{
|
||||||
|
@ -142,4 +172,17 @@
|
||||||
isSavedLocally = true;
|
isSavedLocally = true;
|
||||||
StateHasChanged();
|
StateHasChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||||
|
{
|
||||||
|
if (firstRender)
|
||||||
|
{
|
||||||
|
continueDataExists = await localStorage.ContainKeyAsync("ContinueData");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (continueDataExists)
|
||||||
|
{
|
||||||
|
continueCharectersLeft = await localStorage.GetItemAsync<int>("ContinueCharectersLeft");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -26,12 +26,16 @@
|
||||||
|
|
||||||
<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">
|
@*True if debug, false for not debug. (TODO: Use an extensíonMethod: https://stackoverflow.com/questions/4696175/preprocessor-directives-in-razor)*@
|
||||||
@if (!Answers.Any(x => x == null))
|
@if (true)
|
||||||
{
|
{
|
||||||
<MudButton Disabled="@(!(Answers.Any(x=>x.isSelected)))" OnClick="()=>RemoveCCharFromSelection()" Variant="Variant.Outlined">Avoid</MudButton>
|
<MudStack Row=true Class="pt-2 d-flex justify-center">
|
||||||
}
|
@if (!Answers.Any(x => x == null))
|
||||||
</MudStack>*@
|
{
|
||||||
|
<MudButton Disabled="@(!(Answers.Any(x=>x.isSelected)))" OnClick="()=>RemoveCCharFromSelection()" Variant="Variant.Outlined">Avoid</MudButton>
|
||||||
|
}
|
||||||
|
</MudStack>
|
||||||
|
}
|
||||||
<MudContainer Class="pt-12">
|
<MudContainer Class="pt-12">
|
||||||
<MudPaper Class="pa-16 ma-2 rounded-xl mud-dark" Elevation="1">
|
<MudPaper Class="pa-16 ma-2 rounded-xl mud-dark" Elevation="1">
|
||||||
<MudContainer Style="width: 100px; height: 100px" Class="pa-8 ma-4 d-flex justify-center align-center">
|
<MudContainer Style="width: 100px; height: 100px" Class="pa-8 ma-4 d-flex justify-center align-center">
|
||||||
|
@ -118,6 +122,28 @@
|
||||||
{
|
{
|
||||||
Program.UpdateUiEvent += OnUiUpdate;
|
Program.UpdateUiEvent += OnUiUpdate;
|
||||||
|
|
||||||
|
bool continueLast =
|
||||||
|
await localStorage.ContainKeyAsync("ContinueLearning")
|
||||||
|
&& await localStorage.ContainKeyAsync("ContinueData")
|
||||||
|
&& await localStorage.GetItemAsync<bool>("ContinueLearning");
|
||||||
|
|
||||||
|
if (continueLast)
|
||||||
|
{
|
||||||
|
await LoadCharectersFromContinue();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
await LoadCharectersFromChunk();
|
||||||
|
}
|
||||||
|
|
||||||
|
Program.CCharsLeft = DontSkipTheseCChar.Count;
|
||||||
|
Program.InvokeUiUpdate();
|
||||||
|
|
||||||
|
GenerateQuestion();
|
||||||
|
}
|
||||||
|
|
||||||
|
async Task LoadCharectersFromChunk()
|
||||||
|
{
|
||||||
isSavedLocally = await localStorage.ContainKeyAsync("Normalized_chunk_001.json");
|
isSavedLocally = await localStorage.ContainKeyAsync("Normalized_chunk_001.json");
|
||||||
|
|
||||||
int selectedChunk = await localStorage.GetItemAsync<int>("SelectedChunk");
|
int selectedChunk = await localStorage.GetItemAsync<int>("SelectedChunk");
|
||||||
|
@ -130,11 +156,15 @@
|
||||||
Charecters = JsonConvert.DeserializeObject<CChar[]>(json);
|
Charecters = JsonConvert.DeserializeObject<CChar[]>(json);
|
||||||
}
|
}
|
||||||
|
|
||||||
DontSkipTheseCChar = Charecters.Select(x=>new CCharStats(x)).ToList();
|
DontSkipTheseCChar = Charecters.Select(x => new CCharStats(x)).ToList();
|
||||||
Program.CCharsLeft = DontSkipTheseCChar.Count;
|
}
|
||||||
Program.InvokeUiUpdate();
|
|
||||||
|
|
||||||
GenerateQuestion();
|
async Task LoadCharectersFromContinue()
|
||||||
|
{
|
||||||
|
string continueDataJson = await localStorage.GetItemAsStringAsync("ContinueData");
|
||||||
|
CCharStats[] charectersLeft = JsonConvert.DeserializeObject<CCharStats[]>(continueDataJson);
|
||||||
|
|
||||||
|
DontSkipTheseCChar = charectersLeft.ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnUiUpdate() => StateHasChanged();
|
void OnUiUpdate() => StateHasChanged();
|
||||||
|
@ -170,9 +200,11 @@
|
||||||
|
|
||||||
Answers[i].isCorrect = true;
|
Answers[i].isCorrect = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
StateHasChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void FinishAndKickBackToLearn()
|
async void FinishAndKickBackToLearn()
|
||||||
{
|
{
|
||||||
Snackbar.Add("Congrats, you have compleated this chunk!", Severity.Success, config =>
|
Snackbar.Add("Congrats, you have compleated this chunk!", Severity.Success, config =>
|
||||||
{
|
{
|
||||||
|
@ -182,6 +214,8 @@
|
||||||
Program.UpdateUiEvent -= OnUiUpdate;
|
Program.UpdateUiEvent -= OnUiUpdate;
|
||||||
Program.CCharsLeft = 0;
|
Program.CCharsLeft = 0;
|
||||||
|
|
||||||
|
await localStorage.RemoveItemAsync("ContinueData");
|
||||||
|
|
||||||
navigator.NavigateTo("");
|
navigator.NavigateTo("");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -221,9 +255,20 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await SaveContinueData();
|
||||||
|
|
||||||
GenerateQuestion();
|
GenerateQuestion();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async Task SaveContinueData()
|
||||||
|
{
|
||||||
|
CCharStats[] charectersLeft = DontSkipTheseCChar.ToArray();
|
||||||
|
string continueDataJson = JsonConvert.SerializeObject(charectersLeft);
|
||||||
|
|
||||||
|
await localStorage.SetItemAsStringAsync("ContinueData", continueDataJson);
|
||||||
|
await localStorage.SetItemAsync("ContinueCharectersLeft", charectersLeft.Length);
|
||||||
|
}
|
||||||
|
|
||||||
public class Answer
|
public class Answer
|
||||||
{
|
{
|
||||||
public Answer()
|
public Answer()
|
||||||
|
@ -260,6 +305,7 @@
|
||||||
CCharStats correctCCharStats = DontSkipTheseCChar.First(x => x.cchar == correctChar);
|
CCharStats correctCCharStats = DontSkipTheseCChar.First(x => x.cchar == correctChar);
|
||||||
return correctCCharStats;
|
return correctCCharStats;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void increaseCCharStat(CCharStats stats, StatType statType)
|
public void increaseCCharStat(CCharStats stats, StatType statType)
|
||||||
{
|
{
|
||||||
int correctStatsIndex = DontSkipTheseCChar.IndexOf(stats);
|
int correctStatsIndex = DontSkipTheseCChar.IndexOf(stats);
|
||||||
|
@ -275,7 +321,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RemoveCCharFromSelection(bool ignoreSelection = false)
|
public async void RemoveCCharFromSelection(bool ignoreSelection = false)
|
||||||
{
|
{
|
||||||
CCharStats correctCCharStats = GetCorrectCCharStats();
|
CCharStats correctCCharStats = GetCorrectCCharStats();
|
||||||
|
|
||||||
|
@ -294,6 +340,9 @@
|
||||||
Console.WriteLine("Remaining CChars: " + DontSkipTheseCChar);
|
Console.WriteLine("Remaining CChars: " + DontSkipTheseCChar);
|
||||||
Program.CCharsLeft = DontSkipTheseCChar.Count;
|
Program.CCharsLeft = DontSkipTheseCChar.Count;
|
||||||
Program.InvokeUiUpdate();
|
Program.InvokeUiUpdate();
|
||||||
|
|
||||||
|
await SaveContinueData();
|
||||||
|
|
||||||
GenerateQuestion();
|
GenerateQuestion();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
</div>
|
</div>
|
||||||
<script src="_framework/blazor.webassembly.js"></script>
|
<script src="_framework/blazor.webassembly.js"></script>
|
||||||
<script src="_content/MudBlazor/MudBlazor.min.js"></script>
|
<script src="_content/MudBlazor/MudBlazor.min.js"></script>
|
||||||
<!--<script>navigator.serviceWorker.register('service-worker.js');</script>-->
|
<script>navigator.serviceWorker.register('service-worker.js');</script>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue