From ff54c4c613408a17a2f7a5062a26d98f8f3edaa5 Mon Sep 17 00:00:00 2001 From: Gordon Pedersen Date: Tue, 11 Jun 2024 15:01:49 +1000 Subject: [PATCH] revamped pics so they don't freeze or jump --- Components/Pages/Pics.razor | 111 +++++++++++++++++++++++++++++++++--- 1 file changed, 104 insertions(+), 7 deletions(-) diff --git a/Components/Pages/Pics.razor b/Components/Pages/Pics.razor index 256f593..284bf01 100644 --- a/Components/Pages/Pics.razor +++ b/Components/Pages/Pics.razor @@ -1,5 +1,7 @@ @page "/pics" @inject State State +@inject IJSRuntime JS +

@@ -19,17 +21,112 @@ + +
- + @* *@ +
+
+ +
+ +
+
+ + @code { private List pics; - private async ValueTask> GetPics(ItemsProviderRequest request) { - // TODO: request.cancellationToken - RestService api = new RestService(); - if(pics == null || pics.Count == 0) pics = await api.SomePics(); - var numPics = Math.Min(request.Count, pics.Count - request.StartIndex); - return new ItemsProviderResult(pics.Skip(request.StartIndex).Take(numPics), pics.Count); + private DotNetObjectReference? objRef; + + protected override void OnInitialized() { + objRef = DotNetObjectReference.Create(this); + } + + protected override async Task OnAfterRenderAsync(bool firstRender) { + await base.OnAfterRenderAsync(firstRender); + if (firstRender) { + await JS.InvokeVoidAsync("setDotNetHelper", objRef); + RestService api = new RestService(); + if (pics == null || pics.Count == 0) pics = await api.SomePics(); + + int page_size = 1; + for(int i = 0; i < pics.Count; i += page_size) { + await JS.InvokeVoidAsync("renderPics", pics.Skip(i * page_size).Take(page_size)); + } + await JS.InvokeVoidAsync("clearLoading"); + } + } + + [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" + }); } }