| | | 1 | | @using Chronicis.Shared.DTOs.Quests |
| | | 2 | | @using Chronicis.Shared.Enums |
| | | 3 | | @using MudBlazor |
| | | 4 | | @inject IQuestApiService QuestApi |
| | | 5 | | |
| | | 6 | | <MudDialog> |
| | | 7 | | <TitleContent> |
| | | 8 | | <MudText Typo="Typo.h6"> |
| | | 9 | | <MudIcon Icon="@Icons.Material.Filled.Flag" Class="mr-2" /> |
| | | 10 | | New Quest |
| | | 11 | | </MudText> |
| | | 12 | | </TitleContent> |
| | | 13 | | <DialogContent> |
| | | 14 | | <MudTextField @bind-Value="_title" |
| | | 15 | | Label="Quest Title" |
| | | 16 | | Variant="Variant.Outlined" |
| | | 17 | | Required="true" |
| | | 18 | | RequiredError="Title is required" |
| | | 19 | | Placeholder="e.g., Find the Lost Artifact" |
| | | 20 | | Class="mb-3" |
| | 0 | 21 | | @ref="_titleField" |
| | 0 | 22 | | Immediate="true" |
| | 0 | 23 | | OnKeyDown="@OnTitleKeyDown" /> |
| | 0 | 24 | | |
| | 0 | 25 | | <MudTextField @bind-Value="_description" |
| | 0 | 26 | | Label="Description (optional)" |
| | | 27 | | Variant="Variant.Outlined" |
| | | 28 | | Lines="3" |
| | | 29 | | Placeholder="Brief summary of the quest..." |
| | | 30 | | Class="mb-3" /> |
| | | 31 | | |
| | | 32 | | <MudSelect T="QuestStatus" |
| | | 33 | | @bind-Value="_status" |
| | | 34 | | Label="Status" |
| | | 35 | | Variant="Variant.Outlined" |
| | | 36 | | Class="mb-3"> |
| | | 37 | | <MudSelectItem T="QuestStatus" Value="QuestStatus.Active">Active</MudSelectItem> |
| | | 38 | | <MudSelectItem T="QuestStatus" Value="QuestStatus.Completed">Completed</MudSelectItem> |
| | | 39 | | <MudSelectItem T="QuestStatus" Value="QuestStatus.Failed">Failed</MudSelectItem> |
| | | 40 | | <MudSelectItem T="QuestStatus" Value="QuestStatus.Abandoned">Abandoned</MudSelectItem> |
| | | 41 | | </MudSelect> |
| | | 42 | | |
| | | 43 | | <MudSwitch @bind-Value="_isGmOnly" |
| | | 44 | | Label="GM Only" |
| | | 45 | | Color="Color.Warning" |
| | | 46 | | Class="mb-3" /> |
| | | 47 | | </DialogContent> |
| | | 48 | | <DialogActions> |
| | | 49 | | <MudButton OnClick="Cancel">Cancel</MudButton> |
| | | 50 | | <MudButton Color="Color.Primary" |
| | | 51 | | Variant="Variant.Filled" |
| | | 52 | | OnClick="Submit" |
| | | 53 | | Disabled="@(string.IsNullOrWhiteSpace(_title) || _isSubmitting)"> |
| | 0 | 54 | | @if (_isSubmitting) |
| | | 55 | | { |
| | | 56 | | <MudProgressCircular Size="Size.Small" Indeterminate="true" Class="mr-2" /> |
| | | 57 | | } |
| | | 58 | | Create |
| | | 59 | | </MudButton> |
| | | 60 | | </DialogActions> |
| | | 61 | | </MudDialog> |
| | | 62 | | |
| | | 63 | | @code { |
| | | 64 | | [CascadingParameter] |
| | 0 | 65 | | private MudDialogInstance? MudDialog { get; set; } |
| | | 66 | | |
| | | 67 | | [Parameter] |
| | 0 | 68 | | public Guid ArcId { get; set; } |
| | | 69 | | |
| | 0 | 70 | | private string _title = string.Empty; |
| | 0 | 71 | | private string _description = string.Empty; |
| | | 72 | | private QuestStatus _status = QuestStatus.Active; |
| | | 73 | | private bool _isGmOnly = false; |
| | | 74 | | private bool _isSubmitting; |
| | | 75 | | private MudTextField<string>? _titleField; |
| | | 76 | | |
| | | 77 | | protected override async Task OnAfterRenderAsync(bool firstRender) |
| | | 78 | | { |
| | 0 | 79 | | if (firstRender && _titleField != null) |
| | | 80 | | { |
| | 0 | 81 | | await _titleField.FocusAsync(); |
| | | 82 | | } |
| | 0 | 83 | | } |
| | | 84 | | |
| | | 85 | | private async Task OnTitleKeyDown(KeyboardEventArgs e) |
| | | 86 | | { |
| | 0 | 87 | | if (e.Key == "Enter" && !string.IsNullOrWhiteSpace(_title)) |
| | | 88 | | { |
| | 0 | 89 | | await Submit(); |
| | | 90 | | } |
| | 0 | 91 | | } |
| | | 92 | | |
| | | 93 | | private async Task Submit() |
| | | 94 | | { |
| | 0 | 95 | | if (string.IsNullOrWhiteSpace(_title) || _isSubmitting) |
| | | 96 | | { |
| | 0 | 97 | | return; |
| | | 98 | | } |
| | | 99 | | |
| | 0 | 100 | | _isSubmitting = true; |
| | | 101 | | |
| | 0 | 102 | | var createDto = new QuestCreateDto |
| | 0 | 103 | | { |
| | 0 | 104 | | Title = _title.Trim(), |
| | 0 | 105 | | Description = string.IsNullOrWhiteSpace(_description) ? null : _description.Trim(), |
| | 0 | 106 | | Status = _status, |
| | 0 | 107 | | IsGmOnly = _isGmOnly |
| | 0 | 108 | | }; |
| | | 109 | | |
| | 0 | 110 | | var result = await QuestApi.CreateQuestAsync(ArcId, createDto); |
| | | 111 | | |
| | 0 | 112 | | _isSubmitting = false; |
| | | 113 | | |
| | 0 | 114 | | if (result != null) |
| | | 115 | | { |
| | 0 | 116 | | MudDialog?.Close(DialogResult.Ok(result)); |
| | | 117 | | } |
| | 0 | 118 | | } |
| | | 119 | | |
| | | 120 | | private void Cancel() |
| | | 121 | | { |
| | 0 | 122 | | MudDialog?.Cancel(); |
| | 0 | 123 | | } |
| | | 124 | | } |