|
| 1 | +@using TelegramDownloader.Data.db |
| 2 | +@inject IDbService DbService |
| 3 | +@inject NavigationManager NavigationManager |
| 4 | + |
| 5 | +<Modal @ref="modal" Title="Delete Channel Database" Size="ModalSize.Regular"> |
| 6 | + <BodyTemplate> |
| 7 | + <div class="alert alert-danger" role="alert"> |
| 8 | + <i class="bi bi-exclamation-triangle-fill me-2"></i> |
| 9 | + <strong>Warning!</strong> This action cannot be undone. All files and folders in this channel's database will be permanently deleted. |
| 10 | + </div> |
| 11 | + |
| 12 | + <div class="mb-3"> |
| 13 | + <label class="form-label fw-bold">Channel ID:</label> |
| 14 | + <div class="form-control bg-light">@ChannelId</div> |
| 15 | + </div> |
| 16 | + |
| 17 | + <div class="mb-3"> |
| 18 | + <label class="form-label fw-bold">Channel Name:</label> |
| 19 | + <div class="form-control bg-light">@ChannelName</div> |
| 20 | + </div> |
| 21 | + |
| 22 | + <hr /> |
| 23 | + |
| 24 | + <div class="mb-3"> |
| 25 | + <label class="form-label">To confirm deletion, type the channel ID: <strong>@ChannelId</strong></label> |
| 26 | + <input type="text" class="form-control @(IsInputValid ? "" : "is-invalid")" |
| 27 | + @bind="ConfirmationInput" |
| 28 | + @bind:event="oninput" |
| 29 | + placeholder="Enter channel ID to confirm" /> |
| 30 | + @if (!string.IsNullOrEmpty(ConfirmationInput) && !IsInputValid) |
| 31 | + { |
| 32 | + <div class="invalid-feedback"> |
| 33 | + The channel ID does not match. |
| 34 | + </div> |
| 35 | + } |
| 36 | + </div> |
| 37 | + </BodyTemplate> |
| 38 | + <FooterTemplate> |
| 39 | + <Button Color="ButtonColor.Secondary" @onclick="OnHideModalClick">Cancel</Button> |
| 40 | + <Button Color="ButtonColor.Danger" |
| 41 | + @onclick="OnDeleteClick" |
| 42 | + Disabled="@(!IsInputValid || isDeleting)"> |
| 43 | + @if (isDeleting) |
| 44 | + { |
| 45 | + <Spinner Type="SpinnerType.Border" Size="SpinnerSize.Small" Class="me-2" /> |
| 46 | + <span>Deleting...</span> |
| 47 | + } |
| 48 | + else |
| 49 | + { |
| 50 | + <i class="bi bi-trash me-2"></i> |
| 51 | + <span>Delete Database</span> |
| 52 | + } |
| 53 | + </Button> |
| 54 | + </FooterTemplate> |
| 55 | +</Modal> |
| 56 | + |
| 57 | +@code { |
| 58 | + [Parameter] public string ChannelId { get; set; } = string.Empty; |
| 59 | + [Parameter] public string ChannelName { get; set; } = string.Empty; |
| 60 | + [Inject] protected ToastService ToastService { get; set; } = default!; |
| 61 | + |
| 62 | + private Modal modal = default!; |
| 63 | + private string ConfirmationInput { get; set; } = string.Empty; |
| 64 | + private bool isDeleting = false; |
| 65 | + |
| 66 | + private bool IsInputValid => !string.IsNullOrEmpty(ConfirmationInput) && |
| 67 | + ConfirmationInput.Trim() == ChannelId; |
| 68 | + |
| 69 | + public async Task ShowAsync() |
| 70 | + { |
| 71 | + ConfirmationInput = string.Empty; |
| 72 | + isDeleting = false; |
| 73 | + await modal.ShowAsync(); |
| 74 | + } |
| 75 | + |
| 76 | + private async Task OnHideModalClick() |
| 77 | + { |
| 78 | + await modal.HideAsync(); |
| 79 | + } |
| 80 | + |
| 81 | + private async Task OnDeleteClick() |
| 82 | + { |
| 83 | + if (!IsInputValid || isDeleting) |
| 84 | + return; |
| 85 | + |
| 86 | + isDeleting = true; |
| 87 | + StateHasChanged(); |
| 88 | + |
| 89 | + try |
| 90 | + { |
| 91 | + await DbService.deleteDatabase(ChannelId); |
| 92 | + await modal.HideAsync(); |
| 93 | + |
| 94 | + ToastService.Notify(new ToastMessage(ToastType.Success, $"Database for channel '{ChannelName}' has been deleted successfully.") |
| 95 | + { |
| 96 | + Title = "Database Deleted", |
| 97 | + AutoHide = true |
| 98 | + }); |
| 99 | + |
| 100 | + // Navigate to home page |
| 101 | + NavigationManager.NavigateTo("/fetchdata", forceLoad: true); |
| 102 | + } |
| 103 | + catch (Exception ex) |
| 104 | + { |
| 105 | + ToastService.Notify(new ToastMessage(ToastType.Danger, $"Error deleting database: {ex.Message}") |
| 106 | + { |
| 107 | + Title = "Error", |
| 108 | + AutoHide = true |
| 109 | + }); |
| 110 | + isDeleting = false; |
| 111 | + StateHasChanged(); |
| 112 | + } |
| 113 | + } |
| 114 | +} |
0 commit comments