Able to download whole data to local
This commit is contained in:
parent
d2ab28372f
commit
059088121e
|
@ -12,6 +12,7 @@
|
|||
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="6.0.19" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="6.0.19" PrivateAssets="all" />
|
||||
<PackageReference Include="MudBlazor" Version="6.5.0" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
<MudContainer Class="justify-center d-flex">
|
||||
@if (Charecters != null)
|
||||
{
|
||||
<MudPaper Class="overflow-scroll rounded-0" Style="height: 60vh;" Elevation="1">
|
||||
<MudPaper Class="overflow-scroll rounded-0" Style="height: 50vh;" Elevation="1">
|
||||
<MudDataGrid FixedHeader=true Items="@Charecters">
|
||||
<Columns>
|
||||
<PropertyColumn Property="x => x.charcter" Title="CChar" />
|
||||
|
@ -31,15 +31,47 @@
|
|||
</MudPaper>
|
||||
}
|
||||
</MudContainer>
|
||||
|
||||
<MudContainer Class="justify-center d-flex pt-4">
|
||||
<MudButton Class="mt-1 mb-7" Variant="Variant.Filled" Color="Color.Secondary" Disabled="@(isLoading || isSavedLocally)" OnClick="LoadAllChunksIntoLocalStorage">
|
||||
@if (!isSavedLocally)
|
||||
{
|
||||
@if (isLoading)
|
||||
{
|
||||
<MudText>@($"{savedChunks}/{numOfChunks}")</MudText>
|
||||
<MudProgressCircular Class="pl-8 ms-n1 mr-2" Size="Size.Small" Indeterminate="true" />
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudText>Load chunks to local storage</MudText>
|
||||
<MudIcon Icon="@Icons.Material.Rounded.Send" Class="mr-1" />
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudText>Chunks are saved locally</MudText>
|
||||
}
|
||||
</MudButton>
|
||||
</MudContainer>
|
||||
<MudContainer Class="justify-center d-flex pt-4">
|
||||
<MudButton OnClick="async ()=>{await localStorage.ClearAsync(); navigator.NavigateTo(string.Empty, true);}" Variant="Variant.Outlined" Color="Color.Tertiary">Delete local storage</MudButton>
|
||||
</MudContainer>
|
||||
</MudContainer>
|
||||
</MudContainer>
|
||||
|
||||
@code{
|
||||
int numOfChunks = 197; //Exclusive index 0
|
||||
int selectedChunk = 0;
|
||||
int savedChunks = 0;
|
||||
|
||||
protected override void OnInitialized()
|
||||
bool isLoading = false;
|
||||
bool isSavedLocally = false;
|
||||
|
||||
protected async override Task OnInitializedAsync()
|
||||
{
|
||||
if (await localStorage.ContainKeyAsync("Normalized_chunk_001.json"))
|
||||
isSavedLocally = true;
|
||||
|
||||
SelectedChunk();
|
||||
StateHasChanged();
|
||||
}
|
||||
|
@ -53,7 +85,34 @@
|
|||
CChar[]? Charecters;
|
||||
async void SelectedChunk()
|
||||
{
|
||||
if (await localStorage.ContainKeyAsync("Normalized_chunk_001.json"))
|
||||
isSavedLocally = true;
|
||||
|
||||
if (!isSavedLocally)
|
||||
Charecters = await httpClient.GetFromJsonAsync<CChar[]>($"Data/Normalized_chunk_{selectedChunk.ToString("000")}.json");
|
||||
else
|
||||
{
|
||||
string json = await localStorage.GetItemAsync<string>($"Normalized_chunk_{selectedChunk.ToString("000")}.json");
|
||||
Charecters = JsonConvert.DeserializeObject<CChar[]>(json);
|
||||
}
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
async void LoadAllChunksIntoLocalStorage()
|
||||
{
|
||||
isLoading = true;
|
||||
for (int i = 0; i < numOfChunks; i++)
|
||||
{
|
||||
string? jsonChunk = await httpClient.GetStringAsync($"Data/Normalized_chunk_{i.ToString("000")}.json");
|
||||
|
||||
if (string.IsNullOrEmpty(jsonChunk)) continue;
|
||||
|
||||
await localStorage.SetItemAsync($"Normalized_chunk_{i.ToString("000")}.json", jsonChunk);
|
||||
savedChunks = i + 1;
|
||||
StateHasChanged();
|
||||
}
|
||||
isLoading = false;
|
||||
isSavedLocally = true;
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
|
@ -76,6 +76,8 @@
|
|||
@code {
|
||||
public bool ShowOverlay = false;
|
||||
|
||||
bool isSavedLocally = false;
|
||||
|
||||
public Answer[] Answers = new Answer[4];
|
||||
public void SelectButton(int selectedIndex)
|
||||
{
|
||||
|
@ -109,10 +111,17 @@
|
|||
{
|
||||
Program.UpdateUiEvent += OnUiUpdate;
|
||||
|
||||
isSavedLocally = await localStorage.ContainKeyAsync("Normalized_chunk_001.json");
|
||||
|
||||
int selectedChunk = await localStorage.GetItemAsync<int>("SelectedChunk");
|
||||
|
||||
//Charecters = await httpClient.GetFromJsonAsync<CChar[]>("Data/NormalizedDataset.json");
|
||||
if (!isSavedLocally)
|
||||
Charecters = await httpClient.GetFromJsonAsync<CChar[]>($"Data/Normalized_chunk_{selectedChunk.ToString("000")}.json");
|
||||
else
|
||||
{
|
||||
string json = await localStorage.GetItemAsync<string>($"Normalized_chunk_{selectedChunk.ToString("000")}.json");
|
||||
Charecters = JsonConvert.DeserializeObject<CChar[]>(json);
|
||||
}
|
||||
|
||||
DontSkipTheseCChar = Charecters.ToList();
|
||||
Program.CCharsLeft = DontSkipTheseCChar.Count;
|
||||
|
|
|
@ -7,7 +7,8 @@
|
|||
<MudAppBar Elevation="0">
|
||||
@if (Program.CCharsLeft > 0)
|
||||
{
|
||||
<MudText>@("CChars left: " + Program.CCharsLeft)</MudText>
|
||||
<MudButton OnClick="()=>navigator.NavigateTo(string.Empty)" Variant="Variant.Outlined" Color="Color.Primary">Back</MudButton>
|
||||
<MudText Class="pl-8">@("CChars left: " + Program.CCharsLeft)</MudText>
|
||||
}
|
||||
<MudSpacer />
|
||||
<MudIconButton Icon="@Icons.Custom.Brands.MudBlazor" Color="Color.Inherit" Link="https://mudblazor.com/" Target="_blank" />
|
||||
|
|
|
@ -10,3 +10,4 @@
|
|||
@using LearningChineseFixed.Shared
|
||||
@using MudBlazor
|
||||
@using Blazored.LocalStorage
|
||||
@using Newtonsoft.Json
|
Loading…
Reference in New Issue