77 lines
1.9 KiB
Plaintext
77 lines
1.9 KiB
Plaintext
@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]
|
|
};
|
|
}
|
|
} |