| | | 1 | | using Chronicis.Client.Components.Dialogs; |
| | | 2 | | using Chronicis.Client.Services; |
| | | 3 | | using Chronicis.Shared.DTOs.Quests; |
| | | 4 | | using Microsoft.AspNetCore.Components; |
| | | 5 | | using MudBlazor; |
| | | 6 | | |
| | | 7 | | namespace Chronicis.Client.Components.Quests; |
| | | 8 | | |
| | | 9 | | public partial class ArcQuestList : ComponentBase |
| | | 10 | | { |
| | | 11 | | [Parameter, EditorRequired] |
| | 0 | 12 | | public Guid ArcId { get; set; } |
| | | 13 | | |
| | | 14 | | [Parameter] |
| | 0 | 15 | | public bool IsGm { get; set; } |
| | | 16 | | |
| | 0 | 17 | | [Inject] private IQuestApiService QuestApi { get; set; } = default!; |
| | 0 | 18 | | [Inject] private IDialogService DialogService { get; set; } = default!; |
| | 0 | 19 | | [Inject] private ISnackbar Snackbar { get; set; } = default!; |
| | 0 | 20 | | [Inject] private ILogger<ArcQuestList> Logger { get; set; } = default!; |
| | | 21 | | |
| | 0 | 22 | | private List<QuestDto> _quests = new(); |
| | | 23 | | private bool _isLoading; |
| | | 24 | | private bool _isCreating; |
| | | 25 | | private bool _isDeleting; |
| | | 26 | | private bool _isGm; |
| | | 27 | | private string? _loadingError; |
| | | 28 | | |
| | | 29 | | protected override async Task OnInitializedAsync() |
| | | 30 | | { |
| | 0 | 31 | | _isGm = IsGm; |
| | 0 | 32 | | await LoadQuestsAsync(); |
| | 0 | 33 | | } |
| | | 34 | | |
| | | 35 | | protected override async Task OnParametersSetAsync() |
| | | 36 | | { |
| | 0 | 37 | | _isGm = IsGm; |
| | | 38 | | |
| | | 39 | | // Reload if ArcId changes |
| | 0 | 40 | | if (ArcId != Guid.Empty) |
| | | 41 | | { |
| | 0 | 42 | | await LoadQuestsAsync(); |
| | | 43 | | } |
| | 0 | 44 | | } |
| | | 45 | | |
| | | 46 | | private async Task LoadQuestsAsync() |
| | | 47 | | { |
| | 0 | 48 | | _isLoading = true; |
| | 0 | 49 | | _loadingError = null; |
| | 0 | 50 | | StateHasChanged(); |
| | | 51 | | |
| | | 52 | | try |
| | | 53 | | { |
| | 0 | 54 | | _quests = await QuestApi.GetArcQuestsAsync(ArcId); |
| | 0 | 55 | | } |
| | 0 | 56 | | catch (Exception ex) |
| | | 57 | | { |
| | 0 | 58 | | Logger.LogError(ex, "Failed to load quests for arc {ArcId}", ArcId); |
| | 0 | 59 | | _loadingError = ex.Message; |
| | 0 | 60 | | _quests = new(); |
| | 0 | 61 | | } |
| | | 62 | | finally |
| | | 63 | | { |
| | 0 | 64 | | _isLoading = false; |
| | 0 | 65 | | StateHasChanged(); |
| | | 66 | | } |
| | 0 | 67 | | } |
| | | 68 | | |
| | | 69 | | private async Task CreateQuest() |
| | | 70 | | { |
| | 0 | 71 | | if (!_isGm || _isCreating) |
| | 0 | 72 | | return; |
| | | 73 | | |
| | 0 | 74 | | _isCreating = true; |
| | 0 | 75 | | StateHasChanged(); |
| | | 76 | | |
| | | 77 | | try |
| | | 78 | | { |
| | 0 | 79 | | var parameters = new DialogParameters |
| | 0 | 80 | | { |
| | 0 | 81 | | { "ArcId", ArcId } |
| | 0 | 82 | | }; |
| | | 83 | | |
| | 0 | 84 | | var dialog = await DialogService.ShowAsync<CreateQuestDialog>("Create Quest", parameters); |
| | 0 | 85 | | var result = await dialog.Result; |
| | | 86 | | |
| | 0 | 87 | | if (result != null && !result.Canceled) |
| | | 88 | | { |
| | 0 | 89 | | await LoadQuestsAsync(); |
| | 0 | 90 | | Snackbar.Add("Quest created successfully", Severity.Success); |
| | | 91 | | } |
| | 0 | 92 | | } |
| | 0 | 93 | | catch (Exception ex) |
| | | 94 | | { |
| | 0 | 95 | | Logger.LogError(ex, "Failed to create quest"); |
| | 0 | 96 | | Snackbar.Add($"Failed to create quest: {ex.Message}", Severity.Error); |
| | 0 | 97 | | } |
| | | 98 | | finally |
| | | 99 | | { |
| | 0 | 100 | | _isCreating = false; |
| | 0 | 101 | | StateHasChanged(); |
| | | 102 | | } |
| | 0 | 103 | | } |
| | | 104 | | |
| | | 105 | | private void EditQuest(QuestDto quest) |
| | | 106 | | { |
| | 0 | 107 | | if (!_isGm) |
| | 0 | 108 | | return; |
| | | 109 | | |
| | | 110 | | // This will be handled by the parent ArcDetail page |
| | | 111 | | // which will show the quest editor inline |
| | | 112 | | // For now, just show a placeholder |
| | 0 | 113 | | Snackbar.Add($"Editing quest: {quest.Title}", Severity.Info); |
| | 0 | 114 | | } |
| | | 115 | | |
| | | 116 | | private async Task DeleteQuest(QuestDto quest) |
| | | 117 | | { |
| | 0 | 118 | | if (!_isGm || _isDeleting) |
| | 0 | 119 | | return; |
| | | 120 | | |
| | 0 | 121 | | var confirmed = await DialogService.ShowMessageBox( |
| | 0 | 122 | | "Delete Quest", |
| | 0 | 123 | | $"Are you sure you want to delete '{quest.Title}'? This will also delete all quest updates. This action cann |
| | 0 | 124 | | yesText: "Delete", |
| | 0 | 125 | | cancelText: "Cancel"); |
| | | 126 | | |
| | 0 | 127 | | if (confirmed != true) |
| | 0 | 128 | | return; |
| | | 129 | | |
| | 0 | 130 | | _isDeleting = true; |
| | 0 | 131 | | StateHasChanged(); |
| | | 132 | | |
| | | 133 | | try |
| | | 134 | | { |
| | 0 | 135 | | var success = await QuestApi.DeleteQuestAsync(quest.Id); |
| | 0 | 136 | | if (success) |
| | | 137 | | { |
| | 0 | 138 | | Snackbar.Add("Quest deleted successfully", Severity.Success); |
| | 0 | 139 | | await LoadQuestsAsync(); |
| | | 140 | | } |
| | | 141 | | else |
| | | 142 | | { |
| | 0 | 143 | | Snackbar.Add("Failed to delete quest", Severity.Error); |
| | | 144 | | } |
| | 0 | 145 | | } |
| | 0 | 146 | | catch (Exception ex) |
| | | 147 | | { |
| | 0 | 148 | | Logger.LogError(ex, "Failed to delete quest {QuestId}", quest.Id); |
| | 0 | 149 | | Snackbar.Add($"Error deleting quest: {ex.Message}", Severity.Error); |
| | 0 | 150 | | } |
| | | 151 | | finally |
| | | 152 | | { |
| | 0 | 153 | | _isDeleting = false; |
| | 0 | 154 | | StateHasChanged(); |
| | | 155 | | } |
| | 0 | 156 | | } |
| | | 157 | | } |