< Summary

Information
Class: Chronicis.Client.Components.Dialogs.CreateArcDialog
Assembly: Chronicis.Client
File(s): /home/runner/work/chronicis/chronicis/src/Chronicis.Client/Components/Dialogs/CreateArcDialog.razor
Line coverage
100%
Covered lines: 3
Uncovered lines: 0
Coverable lines: 3
Total lines: 112
Line coverage: 100%
Branch coverage
100%
Covered branches: 2
Total branches: 2
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor()100%11100%
Cancel()100%22100%

File(s)

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

#LineLine coverage
 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"
 20                      @ref="_nameField"
 21                      Immediate="true"
 22                      OnKeyDown="@OnNameKeyDown" />
 23
 24        <MudTextField @bind-Value="_description"
 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)">
 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]
 53    private MudDialogInstance? MudDialog { get; set; }
 54
 55    [Parameter]
 56    public Guid CampaignId { get; set; }
 57
 1358    private string _name = string.Empty;
 1359    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    {
 66        if (firstRender && _nameField != null)
 67        {
 68            await Task.Delay(100);
 69            await _nameField.FocusAsync();
 70        }
 71    }
 72
 273    private void Cancel() => MudDialog?.Cancel();
 74
 75    private async Task OnNameKeyDown(KeyboardEventArgs e)
 76    {
 77        if (e.Key == "Enter" && !string.IsNullOrWhiteSpace(_name) && !_isSubmitting)
 78        {
 79            await Submit();
 80        }
 81    }
 82
 83    private async Task Submit()
 84    {
 85        if (string.IsNullOrWhiteSpace(_name) || _isSubmitting) return;
 86
 87        _isSubmitting = true;
 88        StateHasChanged();
 89
 90        try
 91        {
 92            var createDto = new ArcCreateDto
 93            {
 94                Name = _name.Trim(),
 95                Description = string.IsNullOrWhiteSpace(_description) ? null : _description.Trim(),
 96                CampaignId = CampaignId,
 97                SortOrder = _sortOrder
 98            };
 99
 100            var arc = await ArcApi.CreateArcAsync(createDto);
 101            MudDialog?.Close(DialogResult.Ok(arc));
 102        }
 103        catch
 104        {
 105            MudDialog?.Close(DialogResult.Cancel());
 106        }
 107        finally
 108        {
 109            _isSubmitting = false;
 110        }
 111    }
 112}

Methods/Properties

.ctor()
Cancel()