@inject IJSRuntime JS @inject State State @if (Editable) { } else { }
@code { [Parameter] public Func?>> PicsFunc { get; set; } [Parameter] public bool Editable { get; set; } = false; [Parameter] public EditPicDialog? Dialog { get; set; } private List pics; private DotNetObjectReference? objRef; protected override void OnInitialized() { base.OnInitialized(); objRef = DotNetObjectReference.Create(this); State.CurrentPage = Page.Pics; } protected override async Task OnAfterRenderAsync(bool firstRender) { await base.OnAfterRenderAsync(firstRender); if (firstRender) { await JS.InvokeVoidAsync("injectCSharp", objRef); if (State.CurrentPage != Page.Pics) return; if (pics == null || pics.Count == 0) pics = await PicsFunc(); if (State.CurrentPage != Page.Pics) return; int page_size = 1; for (int i = 0; i < pics.Count; i += page_size) { if (State.CurrentPage != Page.Pics) return; await JS.InvokeVoidAsync("renderPics", pics.Skip(i * page_size).Take(page_size)); if (State.CurrentPage != Page.Pics) return; } if (State.CurrentPage != Page.Pics) return; await JS.InvokeVoidAsync("clearLoading"); } } [JSInvokable] public async Task EditClick(string? id) { if (Editable && Dialog != null) { Pic? pic = pics.FirstOrDefault(p => p.Id == id); Dialog.Pic = pic; // await InvokeAsync(StateHasChanged); await JS.InvokeVoidAsync("ui", "#" + Dialog?.id); } } [JSInvokable] public async Task ShareClick(string? url, string? description) { await Share.Default.RequestAsync(new ShareTextRequest { Uri = url, Text = description, Title = "I saw this on some.pics", Subject = "I saw this on some.pics" }); } }