refactor: Refactoring of text creation
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="9.0.0" />
|
||||
<PackageReference Include="UnitsNet" Version="5.60.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -1,77 +0,0 @@
|
||||
@page "/test"
|
||||
@rendermode InteractiveWebAssembly
|
||||
@inject PersistentComponentState ApplicationState
|
||||
@inject ILogger<TestClientForm> Logger
|
||||
|
||||
<p>@Data - @RendererInfo.Name</p>
|
||||
|
||||
<EditForm Enhance FormName="TestForm" OnSubmit="Callback" Model="Item">
|
||||
<InputText @bind-Value="@Item.Text"/>
|
||||
<button class="btn " type="submit" disabled="@(doingStuff || !RendererInfo.IsInteractive)">
|
||||
@if (doingStuff || !RendererInfo.IsInteractive)
|
||||
{
|
||||
<span class="loading loading-spinner"></span>
|
||||
<a>Loading...</a>
|
||||
}
|
||||
else
|
||||
{
|
||||
<a>Test</a>
|
||||
}
|
||||
</button>
|
||||
</EditForm>
|
||||
|
||||
@code {
|
||||
|
||||
private bool doingStuff = false;
|
||||
|
||||
private PersistingComponentStateSubscription persistingSubscription;
|
||||
|
||||
public sealed class FormInput
|
||||
{
|
||||
public required string Text { get; set; }
|
||||
public required string[] Existing { get; set; }
|
||||
}
|
||||
|
||||
[SupplyParameterFromForm] public FormInput Item { get; set; } = new()
|
||||
{
|
||||
Text = string.Empty,
|
||||
Existing = []
|
||||
};
|
||||
|
||||
public Guid Data = Guid.NewGuid();
|
||||
|
||||
protected override Task OnInitializedAsync()
|
||||
{
|
||||
persistingSubscription =
|
||||
ApplicationState.RegisterOnPersisting(PersistData);
|
||||
|
||||
if (!ApplicationState.TryTakeFromJson<Guid>("TOKEN", out Data))
|
||||
{
|
||||
Data = Guid.NewGuid();
|
||||
Logger.LogInformation("Data needs to be persisted! {Data}", Data);
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.LogInformation("Using persisted DATA");
|
||||
}
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
private Task PersistData()
|
||||
{
|
||||
Logger.LogInformation("Persisting! {Data}", Data);
|
||||
ApplicationState.PersistAsJson("TOKEN", Data);
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
private async Task Callback()
|
||||
{
|
||||
Item = new FormInput
|
||||
{
|
||||
Text = string.Empty,
|
||||
Existing = [..Item.Existing, Item.Text, RendererInfo.Name]
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user