[frontend/components] Scroll to attachment that was clicked on (ISH-641)

This commit is contained in:
Lilian 2024-11-28 21:11:15 +01:00
parent 35c4babd63
commit 8a7bcde0c3
No known key found for this signature in database
3 changed files with 14 additions and 11 deletions

View file

@ -8,12 +8,13 @@
<div class="wrapper" @onclick="Open" @onclick:stopPropagation="true">
@if (Attachment.ContentType.StartsWith("image"))
{
<img class="attachment @(BlurImage ? "blur-image" : "")" src="@Attachment.Url" alt="@Attachment.AltText" fetchpriority="low"/>
<img class="attachment @(BlurImage ? "blur-image" : "")" src="@Attachment.Url" alt="@Attachment.AltText"
fetchpriority="low"/>
}
// else if (Attachment.ContentType == "audio/x-mod")
// {
// TODO: Module player
// }
// else if (Attachment.ContentType == "audio/x-mod")
// {
// TODO: Module player
// }
else if (Attachment.ContentType.StartsWith("audio"))
{
<audio controls class="attachment @(BlurImage ? "blur-image" : "")" src="@Attachment.Url"></audio>
@ -49,8 +50,8 @@
</div>
@code {
[Parameter] [EditorRequired] public required NoteAttachment Attachment { get; set; }
[Parameter] [EditorRequired] public required EventCallback OnOpen { get; set; }
[Parameter] [EditorRequired] public required NoteAttachment Attachment { get; set; }
[Parameter] [EditorRequired] public required EventCallback<NoteAttachment> OnOpen { get; set; }
private bool BlurImage { get; set; }
@ -63,7 +64,7 @@
}
else
{
OnOpen.InvokeAsync();
OnOpen.InvokeAsync(Attachment);
}
}

View file

@ -81,10 +81,12 @@
await Module.InvokeVoidAsync("scrollTo", _refs[Focused]);
}
public async Task OpenDialog()
public async Task OpenDialog(NoteAttachment attachment)
{
await Module.InvokeVoidAsync("openDialog", Dialog);
ScrollWidth = await Module.InvokeAsync<int>("getScrollWidth", Scroller);
var index = Attachments.IndexOf(attachment);
await Module.InvokeVoidAsync("scrollTo", _refs[index]);
}
private async Task CloseDialog()

View file

@ -11,8 +11,8 @@
[Parameter] [EditorRequired] public required IList<NoteAttachment> Attachments { get; set; }
private AttachmentView View { get; set; } = null!;
private async Task Open()
private async Task Open(NoteAttachment attachment)
{
await View.OpenDialog();
await View.OpenDialog(attachment);
}
}