| | | 1 | | @using Chronicis.Shared.DTOs |
| | | 2 | | @inject IWorldApiService WorldApi |
| | | 3 | | |
| | | 4 | | <MudDialog> |
| | | 5 | | <TitleContent> |
| | | 6 | | <MudText Typo="Typo.h6"> |
| | | 7 | | <MudIcon Icon="@Icons.Material.Filled.Public" Class="mr-2" /> |
| | | 8 | | New World |
| | | 9 | | </MudText> |
| | | 10 | | </TitleContent> |
| | | 11 | | <DialogContent> |
| | | 12 | | <MudTextField @bind-Value="_name" |
| | | 13 | | Label="World Name" |
| | | 14 | | Variant="Variant.Outlined" |
| | | 15 | | Required="true" |
| | | 16 | | RequiredError="Name is required" |
| | | 17 | | Placeholder="e.g., Forgotten Realms, My Campaign World" |
| | | 18 | | Class="mb-3" |
| | 0 | 19 | | @ref="_nameField" |
| | 0 | 20 | | Immediate="true" /> |
| | 0 | 21 | | |
| | 0 | 22 | | <MudTextField @bind-Value="_description" |
| | 0 | 23 | | Label="Description (optional)" |
| | 0 | 24 | | Variant="Variant.Outlined" |
| | | 25 | | Lines="3" |
| | | 26 | | Placeholder="Describe your world..." /> |
| | | 27 | | </DialogContent> |
| | | 28 | | <DialogActions> |
| | | 29 | | <MudButton OnClick="Cancel">Cancel</MudButton> |
| | | 30 | | <MudButton Color="Color.Primary" |
| | | 31 | | Variant="Variant.Filled" |
| | | 32 | | OnClick="Submit" |
| | | 33 | | Disabled="@(string.IsNullOrWhiteSpace(_name) || _isSubmitting)"> |
| | 0 | 34 | | @if (_isSubmitting) |
| | | 35 | | { |
| | | 36 | | <MudProgressCircular Size="Size.Small" Indeterminate="true" Class="mr-2" /> |
| | | 37 | | } |
| | | 38 | | Create |
| | | 39 | | </MudButton> |
| | | 40 | | </DialogActions> |
| | | 41 | | </MudDialog> |
| | | 42 | | |
| | | 43 | | @code { |
| | | 44 | | [CascadingParameter] |
| | 0 | 45 | | private MudDialogInstance? MudDialog { get; set; } |
| | | 46 | | |
| | 0 | 47 | | private string _name = string.Empty; |
| | 0 | 48 | | private string _description = string.Empty; |
| | | 49 | | private bool _isSubmitting = false; |
| | | 50 | | private MudTextField<string>? _nameField; |
| | | 51 | | |
| | | 52 | | protected override async Task OnAfterRenderAsync(bool firstRender) |
| | | 53 | | { |
| | 0 | 54 | | if (firstRender && _nameField != null) |
| | | 55 | | { |
| | 0 | 56 | | await Task.Delay(100); |
| | 0 | 57 | | await _nameField.FocusAsync(); |
| | | 58 | | } |
| | 0 | 59 | | } |
| | | 60 | | |
| | 0 | 61 | | private void Cancel() => MudDialog?.Cancel(); |
| | | 62 | | |
| | | 63 | | private async Task Submit() |
| | | 64 | | { |
| | 0 | 65 | | if (string.IsNullOrWhiteSpace(_name) || _isSubmitting) return; |
| | | 66 | | |
| | 0 | 67 | | _isSubmitting = true; |
| | 0 | 68 | | StateHasChanged(); |
| | | 69 | | |
| | | 70 | | try |
| | | 71 | | { |
| | 0 | 72 | | var createDto = new WorldCreateDto |
| | 0 | 73 | | { |
| | 0 | 74 | | Name = _name.Trim(), |
| | 0 | 75 | | Description = string.IsNullOrWhiteSpace(_description) ? null : _description.Trim() |
| | 0 | 76 | | }; |
| | | 77 | | |
| | 0 | 78 | | var world = await WorldApi.CreateWorldAsync(createDto); |
| | 0 | 79 | | MudDialog?.Close(DialogResult.Ok(world)); |
| | 0 | 80 | | } |
| | 0 | 81 | | catch |
| | | 82 | | { |
| | 0 | 83 | | MudDialog?.Close(DialogResult.Cancel()); |
| | 0 | 84 | | } |
| | | 85 | | finally |
| | | 86 | | { |
| | 0 | 87 | | _isSubmitting = false; |
| | | 88 | | } |
| | 0 | 89 | | } |
| | | 90 | | } |