@inherits LocalizableComponentBase @* A post's pictures, one at a time, in the app (a picture used to open its file in a new tab, leaving it): the whole screen on a phone, a large dialog from md, with its alt text, the previous and next one (buttons, or the arrow keys), and the original in a new tab for whoever wants the file. *@ @Localizer["Picture {0} of {1}", index + 1, Pictures.Count]
@Current.Description @if (Current.Description is { Length: > 0 } description) {
@description
}
@if (Pictures.Count > 1) { } @Localizer["Open original"] @if (Pictures.Count > 1) { }
@code { /// The post's pictures, in its order. [Parameter, EditorRequired] public List Pictures { get; set; } = []; /// The one opened. [Parameter] public int Start { get; set; } [Parameter] public EventCallback OnClose { get; set; } int index; MediaAttachment Current => Pictures[Math.Clamp(index, 0, Pictures.Count - 1)]; protected override void OnInitialized() { index = Math.Clamp(Start, 0, Math.Max(0, Pictures.Count - 1)); IsLoading = false; } void Previous() => index = Math.Max(0, index - 1); void Next() => index = Math.Min(Pictures.Count - 1, index + 1); void OnKeyDown(KeyboardEventArgs e) { if (e.Key == "ArrowLeft") Previous(); else if (e.Key == "ArrowRight") Next(); } Task Closed(bool open) => open ? Task.CompletedTask : OnClose.InvokeAsync(); }