< Summary

Information
Class: Chronicis.Client.Components.Dialogs.CreateWorldDialog
Assembly: Chronicis.Client
File(s): /home/runner/work/chronicis/chronicis/src/Chronicis.Client/Components/Dialogs/CreateWorldDialog.razor
Line coverage
0%
Covered lines: 0
Uncovered lines: 31
Coverable lines: 31
Total lines: 90
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 18
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_MudDialog()100%210%
.ctor()100%210%
OnAfterRenderAsync()0%2040%
Cancel()0%620%
Submit()0%110100%

File(s)

/home/runner/work/chronicis/chronicis/src/Chronicis.Client/Components/Dialogs/CreateWorldDialog.razor

#LineLine coverage
 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"
 019                      @ref="_nameField"
 020                      Immediate="true" />
 021
 022        <MudTextField @bind-Value="_description"
 023                      Label="Description (optional)"
 024                      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)">
 034            @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]
 045    private MudDialogInstance? MudDialog { get; set; }
 46
 047    private string _name = string.Empty;
 048    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    {
 054        if (firstRender && _nameField != null)
 55        {
 056            await Task.Delay(100);
 057            await _nameField.FocusAsync();
 58        }
 059    }
 60
 061    private void Cancel() => MudDialog?.Cancel();
 62
 63    private async Task Submit()
 64    {
 065        if (string.IsNullOrWhiteSpace(_name) || _isSubmitting) return;
 66
 067        _isSubmitting = true;
 068        StateHasChanged();
 69
 70        try
 71        {
 072            var createDto = new WorldCreateDto
 073            {
 074                Name = _name.Trim(),
 075                Description = string.IsNullOrWhiteSpace(_description) ? null : _description.Trim()
 076            };
 77
 078            var world = await WorldApi.CreateWorldAsync(createDto);
 079            MudDialog?.Close(DialogResult.Ok(world));
 080        }
 081        catch
 82        {
 083            MudDialog?.Close(DialogResult.Cancel());
 084        }
 85        finally
 86        {
 087            _isSubmitting = false;
 88        }
 089    }
 90}