@using Iceshrimp.Assets.PhosphorIcons @using Iceshrimp.Shared.Schemas.Web @inject IJSRuntime Js @if (Focused < _refs.Count - 1) { } @if (Focused > 0) { }
@foreach (var element in Attachments) {
@element.AltText
}
@code { [Parameter] [EditorRequired] public required IList Attachments { get; set; } private ElementReference Dialog { get; set; } private IJSObjectReference Module { get; set; } = null!; private int Focused { get; set; } private List _refs = []; public ElementReference Ref { set => _refs.Add(value); } private ElementReference Scroller { get; set; } private int ScrollWidth { get; set; } private int ScrollLeft { get; set; } protected override void OnParametersSet() { Focused = 0; } private async Task Scroll() { // This should probably be moved to floating point. // So the state transition happens sooner, i.e. at 2.5 vs 3? ScrollLeft = await Module.InvokeAsync("getScrollLeft", Scroller); var fraction = ScrollWidth / _refs.Count; var section = ScrollLeft / fraction; Focused = section; } private async Task Next() { if (Focused >= _refs.Count) { return; } Focused += 1; await Module.InvokeVoidAsync("scrollTo", _refs[Focused]); } private async Task Prev() { if (Focused <= 0) { return; } Focused -= 1; await Module.InvokeVoidAsync("scrollTo", _refs[Focused]); } public async Task OpenDialog() { await Module.InvokeVoidAsync("openDialog", Dialog); ScrollWidth = await Module.InvokeAsync("getScrollWidth", Scroller); } private async Task CloseDialog() { await Module.InvokeVoidAsync("closeDialog", Dialog); } protected override async Task OnAfterRenderAsync(bool firstRender) { if (firstRender) { Module = await Js.InvokeAsync("import", "./Components/AttachmentView.razor.js"); } } }