@using Iceshrimp.Frontend.Core.Services @using Iceshrimp.Frontend.Localization @using Iceshrimp.Shared.Schemas.Web @using Microsoft.Extensions.Localization @using Iceshrimp.Assets.PhosphorIcons @using Iceshrimp.Frontend.Core.Miscellaneous @inject ApiService Api; @inject GlobalComponentSvc Global; @inject IJSRuntime Js; @inject IStringLocalizer Loc;
@if (File.ContentType.StartsWith("image") || Constants.CommonImageExtensions.Any(e => File.Filename.EndsWith(e))) { @File.Description } else if (File.ContentType.StartsWith("audio") || Constants.CommonAudioExtensions.Any(e => File.Filename.EndsWith(e))) { } else if (File.ContentType.StartsWith("video") || Constants.CommonVideoExtensions.Any(e => File.Filename.EndsWith(e))) { } else { } @if (!File.ContentType.StartsWith("image") && Constants.CommonImageExtensions.All(e => !File.Filename.EndsWith(e))) { @File.Filename }
@if (File.Description != null) { } else { } @if (File.Sensitive) { }
@Loc["Open"] @* TODO: Uncomment when FE supports media node *@ @* @if (File.ContentType.StartsWith("image")) *@ @* { *@ @* *@ @* @Loc["Insert inline"] *@ @* *@ @* } *@ @if (File.Sensitive) { @Loc["Mark as not sensitive"] } else { @Loc["Mark as sensitive"] } @Loc["Set alt text"] @Loc["Remove"]
@code { [Parameter, EditorRequired] public required DriveFileResponse File { get; set; } [Parameter] [EditorRequired] public required EventCallback AddInlineMedia { get; set; } [Parameter, EditorRequired] public required EventCallback RemoveAttachment { get; set; } private ElementReference Attachment { get; set; } private Menu AttachmentMenu { get; set; } = null!; private void Select() => AttachmentMenu.Toggle(Attachment, false); private void Open() => Js.InvokeVoidAsync("open", File.Url, "_blank"); // TODO: Uncomment when FE supports media node // private async Task InsertInline() // { // if (!File.ContentType.StartsWith("image/")) return; // await AddInlineMedia.InvokeAsync(File.Url); // } private async Task MarkSensitive(bool sensitive) { try { var res = await Api.Drive.UpdateFileAsync(File.Id, new UpdateDriveFileRequest { Sensitive = sensitive }); if (res != null) { File.Sensitive = res.Sensitive; StateHasChanged(); } } catch (ApiException e) { await Global.NoticeDialog?.Display(e.Response.Message ?? Loc["An unknown error occurred"], NoticeDialog.NoticeType.Error)!; } } private async Task MarkNotSensitive() => await MarkSensitive(false); private async Task MarkAsSensitive() => await MarkSensitive(true); private async Task SetAltText() => await Global.PromptDialog?.Prompt(new EventCallback(this, SetAltTextCallback), Loc["Set alt text"], "", File.Description, true, true)!; private async Task SetAltTextCallback(string? alt) { if (alt == null) return; try { var res = await Api.Drive.UpdateFileAsync(File.Id, new UpdateDriveFileRequest { Description = string.IsNullOrWhiteSpace(alt) ? null : alt }); if (res != null) { File.Description = res.Description; StateHasChanged(); } } catch (ApiException e) { await Global.NoticeDialog?.Display(e.Response.Message ?? Loc["An unknown error occurred"], NoticeDialog.NoticeType.Error)!; } } private async Task Remove() => await Global.ConfirmDialog?.Confirm(new EventCallback(this, RemoveCallback), Loc["Remove attachment?"], buttonText: Loc["Remove"])!; private async Task RemoveCallback(bool remove) { if (remove) await RemoveAttachment.InvokeAsync(File.Id); } }