| | | 1 | | @using Chronicis.Shared.DTOs |
| | | 2 | | @using MudBlazor |
| | | 3 | | @inject IArcApiService ArcApi |
| | | 4 | | |
| | | 5 | | <MudDialog> |
| | | 6 | | <TitleContent> |
| | | 7 | | <MudText Typo="Typo.h6"> |
| | | 8 | | <MudIcon Icon="@Icons.Material.Filled.Bookmark" Class="mr-2" /> |
| | | 9 | | New Arc |
| | | 10 | | </MudText> |
| | | 11 | | </TitleContent> |
| | | 12 | | <DialogContent> |
| | | 13 | | <MudTextField @bind-Value="_name" |
| | | 14 | | Label="Arc Name" |
| | | 15 | | Variant="Variant.Outlined" |
| | | 16 | | Required="true" |
| | | 17 | | RequiredError="Name is required" |
| | | 18 | | Placeholder="e.g., Act 1, Chapter 1, The Beginning" |
| | | 19 | | Class="mb-3" |
| | 0 | 20 | | @ref="_nameField" |
| | 0 | 21 | | Immediate="true" |
| | 0 | 22 | | OnKeyDown="@OnNameKeyDown" /> |
| | 0 | 23 | | |
| | 0 | 24 | | <MudTextField @bind-Value="_description" |
| | 0 | 25 | | Label="Description (optional)" |
| | | 26 | | Variant="Variant.Outlined" |
| | | 27 | | Lines="3" |
| | | 28 | | Class="mb-3" /> |
| | | 29 | | |
| | | 30 | | <MudNumericField @bind-Value="_sortOrder" |
| | | 31 | | Label="Sort Order" |
| | | 32 | | Variant="Variant.Outlined" |
| | | 33 | | Min="0" |
| | | 34 | | HelperText="Lower numbers appear first" /> |
| | | 35 | | </DialogContent> |
| | | 36 | | <DialogActions> |
| | | 37 | | <MudButton OnClick="Cancel">Cancel</MudButton> |
| | | 38 | | <MudButton Color="Color.Primary" |
| | | 39 | | Variant="Variant.Filled" |
| | | 40 | | OnClick="Submit" |
| | | 41 | | Disabled="@(string.IsNullOrWhiteSpace(_name) || _isSubmitting)"> |
| | 0 | 42 | | @if (_isSubmitting) |
| | | 43 | | { |
| | | 44 | | <MudProgressCircular Size="Size.Small" Indeterminate="true" Class="mr-2" /> |
| | | 45 | | } |
| | | 46 | | Create |
| | | 47 | | </MudButton> |
| | | 48 | | </DialogActions> |
| | | 49 | | </MudDialog> |
| | | 50 | | |
| | | 51 | | @code { |
| | | 52 | | [CascadingParameter] |
| | 0 | 53 | | private MudDialogInstance? MudDialog { get; set; } |
| | | 54 | | |
| | | 55 | | [Parameter] |
| | 0 | 56 | | public Guid CampaignId { get; set; } |
| | | 57 | | |
| | 0 | 58 | | private string _name = string.Empty; |
| | 0 | 59 | | private string _description = string.Empty; |
| | | 60 | | private int _sortOrder = 0; |
| | | 61 | | private bool _isSubmitting = false; |
| | | 62 | | private MudTextField<string>? _nameField; |
| | | 63 | | |
| | | 64 | | protected override async Task OnAfterRenderAsync(bool firstRender) |
| | | 65 | | { |
| | 0 | 66 | | if (firstRender && _nameField != null) |
| | | 67 | | { |
| | 0 | 68 | | await Task.Delay(100); |
| | 0 | 69 | | await _nameField.FocusAsync(); |
| | | 70 | | } |
| | 0 | 71 | | } |
| | | 72 | | |
| | 0 | 73 | | private void Cancel() => MudDialog?.Cancel(); |
| | | 74 | | |
| | | 75 | | private async Task OnNameKeyDown(KeyboardEventArgs e) |
| | | 76 | | { |
| | 0 | 77 | | if (e.Key == "Enter" && !string.IsNullOrWhiteSpace(_name) && !_isSubmitting) |
| | | 78 | | { |
| | 0 | 79 | | await Submit(); |
| | | 80 | | } |
| | 0 | 81 | | } |
| | | 82 | | |
| | | 83 | | private async Task Submit() |
| | | 84 | | { |
| | 0 | 85 | | if (string.IsNullOrWhiteSpace(_name) || _isSubmitting) return; |
| | | 86 | | |
| | 0 | 87 | | _isSubmitting = true; |
| | 0 | 88 | | StateHasChanged(); |
| | | 89 | | |
| | | 90 | | try |
| | | 91 | | { |
| | 0 | 92 | | var createDto = new ArcCreateDto |
| | 0 | 93 | | { |
| | 0 | 94 | | Name = _name.Trim(), |
| | 0 | 95 | | Description = string.IsNullOrWhiteSpace(_description) ? null : _description.Trim(), |
| | 0 | 96 | | CampaignId = CampaignId, |
| | 0 | 97 | | SortOrder = _sortOrder |
| | 0 | 98 | | }; |
| | | 99 | | |
| | 0 | 100 | | var arc = await ArcApi.CreateArcAsync(createDto); |
| | 0 | 101 | | MudDialog?.Close(DialogResult.Ok(arc)); |
| | 0 | 102 | | } |
| | 0 | 103 | | catch |
| | | 104 | | { |
| | 0 | 105 | | MudDialog?.Close(DialogResult.Cancel()); |
| | 0 | 106 | | } |
| | | 107 | | finally |
| | | 108 | | { |
| | 0 | 109 | | _isSubmitting = false; |
| | | 110 | | } |
| | 0 | 111 | | } |
| | | 112 | | } |