[frontend/components] Allow uploading multiple attachments at a time

This commit is contained in:
pancakes 2025-03-08 23:38:53 +10:00
parent dcc6fd3a19
commit 9f1444740f
No known key found for this signature in database

View file

@ -61,7 +61,7 @@
<Icon Name="Icons.Upload" Size="1.3rem"></Icon> <Icon Name="Icons.Upload" Size="1.3rem"></Icon>
</button> </button>
<div class="file-input"> <div class="file-input">
<InputFile @ref="UploadInput" OnChange="Upload">Upload!</InputFile> <InputFile @ref="UploadInput" OnChange="Upload" multiple>Upload!</InputFile>
</div> </div>
<button class="btn" title="@Loc["Poll"]" @onclick="TogglePoll" aria-label="poll"> <button class="btn" title="@Loc["Poll"]" @onclick="TogglePoll" aria-label="poll">
<Icon Name="Icons.MicrophoneStage" Size="1.3rem"></Icon> <Icon Name="Icons.MicrophoneStage" Size="1.3rem"></Icon>
@ -396,7 +396,7 @@
SendButton.State = StateButton.StateEnum.Loading; SendButton.State = StateButton.StateEnum.Loading;
if (Attachments.Count > 0) if (Attachments.Count > 0)
{ {
NoteDraft.MediaIds = Attachments.Select(x => x.Id).ToList(); NoteDraft.MediaIds = Attachments.Select(x => x.Id).Distinct().ToList();
} }
NoteDraft.RenoteId ??= AttachedQuote; NoteDraft.RenoteId ??= AttachedQuote;
@ -471,12 +471,17 @@
private async Task Upload(InputFileChangeEventArgs e) private async Task Upload(InputFileChangeEventArgs e)
{ {
UploadingFiles += 1; UploadingFiles += e.FileCount;
var res = await ApiService.Drive.UploadFileAsync(e.File); foreach (var file in e.GetMultipleFiles())
{
var res = await ApiService.Drive.UploadFileAsync(file);
Attachments.Add(res); Attachments.Add(res);
UploadingFiles -= 1; UploadingFiles -= 1;
} }
Attachments = Attachments.DistinctBy(a => a.Id).ToList();
}
private void RemoveAttachment(string id) private void RemoveAttachment(string id)
{ {
var attachment = Attachments.FirstOrDefault(p => p.Id == id); var attachment = Attachments.FirstOrDefault(p => p.Id == id);