@inject IJSRuntime JS
@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() {
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"
});
}
}