Files
decePubClient/Components/ActDialog.razor
T
thepraandClaude Opus 5.5 3827d903a3
Build / Build (push) Successful in 33s
House rules: numbers through one formatter, no made-up server errors, and the rules fail the build
- Every number shown on a page goes through NumbersExtensions: counts,
  percentages, the nerd readouts and the values written into a style.
- A failure the client builds itself (offline, timeout, retries run out, an
  answer it can't read) is a 400 that names its kind; only a server's own 5XX
  passes through.
- Login, sign-up, recovery and password confirmations leave autocomplete to
  the browser, so it can offer the saved login.
- The Daisy components start with empty lists and attributes, and a
  decorative image still renders alt="".
- Arasaka.HouseRules.Analyzers checks all of this in every build, together
  with PrivaPub.ClientModels.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01W4YtEJrgxG12Pc39Fai8Bd
2026-11-10 01:26:39 +01:00

114 lines
5.3 KiB
Plaintext

@inherits LocalizableComponentBase
@* Asks before an act that takes words or a password: what it does, then the fields it needs, then a confirm button. The
staff's acts (Staff) take a note only the staff read (data-moderate-note), a warning the persona is told
(data-moderate-warning) and, to delete, the administrator's own password (data-admin-password); the dialog is
data-moderate-confirm="{act}". A login's own deletions take its password (data-own-password) in data-own-confirm="{act}".
OnConfirm does the act: a failure stays in the dialog (a wrong password is typed again), a success closes it. *@
<DModal Placement="DModalPlacement.ResponsiveBottom" IsOpen="true" IsOpenChanged="Closed" CloseText="@Localizer["Close"]"
data-moderate-confirm="@(Staff ? Act : null)" data-own-confirm="@(Staff ? null : Act)">
<Heading>@Question</Heading>
<ChildContent>
<div class="flex flex-col gap-3 mt-2 text-sm">
@if (Text is { Length: > 0 })
{
<p class="whitespace-pre-line">@Text</p>
}
@if (AskNote)
{
<label class="flex flex-col gap-1">
<span class="font-semibold">@Localizer["A note for the staff (optional)"]</span>
<DTextarea TValue="string" class="w-full" @bind-Value="note" Immediate="true" rows="2" autocomplete="off" maxlength="1000"
aria-label="@Localizer["A note for the staff (optional)"]" data-moderate-note />
<span class="text-xs opacity-70">@Localizer["Only the staff read it, in the moderation log."]</span>
</label>
}
@if (AskWarning)
{
<label class="flex flex-col gap-1">
<span class="font-semibold">@Localizer["What the persona is told (optional)"]</span>
<DTextarea TValue="string" class="w-full" @bind-Value="warning" Immediate="true" rows="3" autocomplete="off" maxlength="1000"
aria-label="@Localizer["What the persona is told (optional)"]" data-moderate-warning />
<span class="text-xs opacity-70">@(WarningHint ?? Localizer["It reaches the persona as a warning from this server's staff."])</span>
</label>
}
@if (AskPassword)
{
<DInput TValue="string" Type="password" class="w-full" @bind-Value="password" Immediate="true" maxlength="200"
placeholder="@(Staff ? Localizer["Your password"] : Localizer["Current password"])"
aria-label="@(Staff ? Localizer["Your password"] : Localizer["Current password"])"
data-admin-password="@(Staff ? "" : null)" data-own-password="@(Staff ? null : "")" />
}
<ErrorViewer AdditionalError="@error" />
</div>
</ChildContent>
<Actions>
<DButton class="max-md:flex-1" OnClick="Cancel" data-act-cancel>@Localizer["Cancel"]</DButton>
<DButton class="max-md:flex-1" Color="@(Danger ? DColor.Error : DColor.Primary)"
Disabled="@(IsDefaultDisabled || isActing || (AskPassword && string.IsNullOrEmpty(password)))" OnClick="Confirm" data-act-submit>
@if (isActing)
{
<DLoading Size="DSize.Sm" LabelText="@Localizer["loading"]" />
}
<span>@ConfirmText</span>
</DButton>
</Actions>
</DModal>
@code {
/// <summary>The question the dialog asks, its heading.</summary>
[Parameter, EditorRequired] public string Question { get; set; }
/// <summary>What the act does, in words.</summary>
[Parameter] public string Text { get; set; }
[Parameter, EditorRequired] public string ConfirmText { get; set; }
/// <summary>The confirm button shows as a danger (it deletes or cuts something off).</summary>
[Parameter] public bool Danger { get; set; }
/// <summary>The act's name in the dialog's data attribute (silence, persona-delete, ...).</summary>
[Parameter, EditorRequired] public string Act { get; set; }
/// <summary>A staff act (data-moderate-confirm, the administrator's password) or the login's own (data-own-confirm).</summary>
[Parameter] public bool Staff { get; set; }
[Parameter] public bool AskNote { get; set; }
[Parameter] public bool AskWarning { get; set; }
/// <summary>Who reads the warning, when it isn't simply the persona (an account elsewhere is told nothing).</summary>
[Parameter] public string WarningHint { get; set; }
[Parameter] public bool AskPassword { get; set; }
/// <summary>Does the act with what was typed; an invalid result stays in the dialog, a valid one closes it.</summary>
[Parameter, EditorRequired] public Func<Answer, Task<WebResult>> OnConfirm { get; set; }
[Parameter] public EventCallback OnClosed { get; set; }
/// <summary>What was typed: the note and the warning trimmed, null when empty; the password as typed.</summary>
public sealed record Answer(string Note, string Warning, string Password);
string note;
string warning;
string password;
string error;
bool isActing;
protected override void OnInitialized() => IsLoading = false;
async Task Confirm()
{
error = default;
isActing = true;
var result = await OnConfirm(new Answer(Trimmed(note), Trimmed(warning), password));
isActing = false;
if (result.IsInvalid)
{
// a cancelled request says nothing; anything else is said here, where it can be fixed
if (result.StatusCode is not 410)
error = result.ErrorMessage;
password = default;
return;
}
await OnClosed.InvokeAsync();
}
static string Trimmed(string text) => string.IsNullOrWhiteSpace(text) ? null : text.Trim();
Task Cancel() => OnClosed.InvokeAsync();
Task Closed(bool open) => open ? Task.CompletedTask : OnClosed.InvokeAsync();
}