Skip to content

Commit

Permalink
[Add] 11 Attachment Delete With Single Click
Browse files Browse the repository at this point in the history
- added single click delete with warning
  • Loading branch information
Timo Schauties committed Jul 31, 2024
1 parent 53045a3 commit a9c7766
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 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,6 +102,9 @@
[Inject]
public INexusClient Client { get; set; } = default!;

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

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

Expand All @@ -110,14 +113,23 @@
_attachments = default;
StateHasChanged();

try
{
await Client.Catalogs.DeleteAttachmentAsync(Catalog.Id, attachment);
await GetAttachmentsAsync();
}
catch (Exception ex)
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;

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

Expand Down Expand Up @@ -191,7 +203,7 @@
}
}

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

0 comments on commit a9c7766

Please sign in to comment.