Skip to content

Commit

Permalink
[Add] 11 Attachment Delete With Single Click (#142)
Browse files Browse the repository at this point in the history
* [Add] 11 Attachment Delete With Single Click

- added single click delete with warning

---------

Co-authored-by: Timo Schauties <[email protected]>
  • Loading branch information
Conundraah and Timo Schauties authored Aug 6, 2024
1 parent 53045a3 commit 698b064
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions src/Nexus.UI/Components/AttachmentView.razor
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
@if (Catalog.Info.IsWritable)
{
<span class="hidden group-hover:inline text-xl ml-auto mr-1 mdi mdi-close hover:text-orange-500 hover:scale-125"
@ondblclick="() => DeleteAttachmentAsync(attachment)" @onclick:preventDefault="true">
@onclick="() => DeleteAttachmentAsync(attachment)" @onclick:preventDefault="true">
</span>
}
</a>
Expand Down Expand Up @@ -102,25 +102,37 @@
[Inject]
public INexusClient Client { get; set; } = default!;

[Inject]
private IDialogService DialogService { get; set; } = default!;

[Parameter]
public ResourceCatalogViewModel Catalog { get; set; } = default!;

private async Task DeleteAttachmentAsync(string attachment)
{
_attachments = default;
StateHasChanged();
bool? result = await DialogService.ShowMessageBox(
"Warning",
"Do you really want to delete the selected attachment?",
yesText:"Delete!", cancelText:"Cancel");
bool deleteConfirmed = result == null ? false : true;

try
{
await Client.Catalogs.DeleteAttachmentAsync(Catalog.Id, attachment);
await GetAttachmentsAsync();
if (deleteConfirmed)
{
await Client.Catalogs.DeleteAttachmentAsync(Catalog.Id, attachment);
_attachments = default;
StateHasChanged();
await GetAttachmentsAsync();
}
}
catch (Exception ex)
{
AppState.AddError(ex, Snackbar);
}
}


private async Task UploadAttachmentsAsync(IReadOnlyList<IBrowserFile> files)
{
var cts = new CancellationTokenSource();
Expand Down Expand Up @@ -191,7 +203,7 @@
}
}

private void OpenAttachmentModal()
private void OpenAttachmentModal()
{
_attachments = default;
_isAttachmentDialogOpen = true;
Expand Down

0 comments on commit 698b064

Please sign in to comment.