diff --git a/Components/EditPicDialog.razor b/Components/EditPicDialog.razor index 5006c61..7bc5639 100644 --- a/Components/EditPicDialog.razor +++ b/Components/EditPicDialog.razor @@ -3,7 +3,7 @@
- +
@@ -25,7 +25,7 @@ @code { private Pic? _pic; - [Parameter] + public Pic? Pic { get => _pic; set { diff --git a/Components/Pages/Person.razor b/Components/Pages/Person.razor index c3eb380..8ac49e4 100644 --- a/Components/Pages/Person.razor +++ b/Components/Pages/Person.razor @@ -56,7 +56,7 @@ @if(Editable){ } - +
@if(now != null){
diff --git a/Components/Pages/Pics.razor b/Components/Pages/Pics.razor index 284bf01..95351b1 100644 --- a/Components/Pages/Pics.razor +++ b/Components/Pages/Pics.razor @@ -21,112 +21,10 @@ - -
- @* *@ -
-
- -
- -
-
+
- - @code { - private List pics; - 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" - }); - } -} +} \ No newline at end of file diff --git a/Components/PicCardEditableTemplate.razor b/Components/PicCardEditableTemplate.razor new file mode 100644 index 0000000..ecc8b8f --- /dev/null +++ b/Components/PicCardEditableTemplate.razor @@ -0,0 +1,30 @@ + \ No newline at end of file diff --git a/Components/PicCardTemplate.razor b/Components/PicCardTemplate.razor new file mode 100644 index 0000000..c5e67bd --- /dev/null +++ b/Components/PicCardTemplate.razor @@ -0,0 +1,23 @@ + \ No newline at end of file diff --git a/Components/PicList.razor b/Components/PicList.razor index 2919ecd..dca2e78 100644 --- a/Components/PicList.razor +++ b/Components/PicList.razor @@ -1,22 +1,105 @@ @inject IJSRuntime JS - - - - - -
-
-
+ +@if (Editable) { + +} +else { + +} + +
+
+ +
+ +
+
+ + + @code { [Parameter] - public Func>> PicsFunc { get; set; } + public Func?>> PicsFunc { get; set; } [Parameter] public bool Editable { get; set; } = false; [Parameter] public EditPicDialog? Dialog { get; set; } - private async ValueTask> GetPics(ItemsProviderRequest request) { - return await this.PicsFunc(request); + private List pics; + 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("injectCSharp", objRef); + RestService api = new RestService(); + if (pics == null || pics.Count == 0) pics = await PicsFunc(); + + 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 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" + }); + } +} \ No newline at end of file diff --git a/Models/State.cs b/Models/State.cs index 60eeeb2..8adc086 100644 --- a/Models/State.cs +++ b/Models/State.cs @@ -143,6 +143,15 @@ namespace Neighbourhood.omg.lol.Models { return this.Pics; } + public async Task?> GetPics(string address, bool forceRefresh = false) { + CachedAddress = address; + if (forceRefresh || this.Pics == null || this.Pics.Count == 0) { + RestService api = new RestService(); + CachedAddressPics = (await api.SomePics(address)) ?? new List(); + } + return CachedAddressPics; + } + public async ValueTask> VirtualPics(ItemsProviderRequest request) { // TODO: request.cancellationToken var pics = (await this.GetPics()) ?? new List(); diff --git a/wwwroot/index.html b/wwwroot/index.html index bbfcd37..6c31dde 100644 --- a/wwwroot/index.html +++ b/wwwroot/index.html @@ -13,6 +13,7 @@ + diff --git a/wwwroot/js/csharp.js b/wwwroot/js/csharp.js new file mode 100644 index 0000000..7647a6e --- /dev/null +++ b/wwwroot/js/csharp.js @@ -0,0 +1,3 @@ +window.injectCSharp = async function (helper) { + window.CSHARP = helper +} \ No newline at end of file