< Summary

Information
Class: Chronicis.Client.Components.Dialogs.JoinWorldDialog
Assembly: Chronicis.Client
File(s): /home/runner/work/chronicis/chronicis/src/Chronicis.Client/Components/Dialogs/JoinWorldDialog.razor
Line coverage
0%
Covered lines: 0
Uncovered lines: 35
Coverable lines: 35
Total lines: 123
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 30
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%
GoToWorld()0%620%
Submit()0%110100%

File(s)

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

#LineLine coverage
 1@using Chronicis.Shared.DTOs
 2@inject IWorldApiService WorldApi
 3@inject ISnackbar Snackbar
 4
 5<MudDialog>
 6    <TitleContent>
 7        <MudText Typo="Typo.h6">
 8            <MudIcon Icon="@Icons.Material.Filled.GroupAdd" Class="mr-2" />
 9            Join a World
 10        </MudText>
 11    </TitleContent>
 12    <DialogContent>
 13        <MudText Typo="Typo.body2" Class="mb-4">
 14            Enter the invitation code shared by the world's GM to join their world.
 15        </MudText>
 16
 17        <MudTextField @bind-Value="_code"
 18                      Label="Invitation Code"
 19                      Variant="Variant.Outlined"
 20                      Required="true"
 21                      RequiredError="Code is required"
 22                      Placeholder="e.g., FROG-AXLE"
 23                      Class="mb-3"
 024                      @ref="_codeField"
 025                      Immediate="true"
 026                      Style="font-family: monospace; font-size: 1.2em; letter-spacing: 2px;"
 027                      Error="@(!string.IsNullOrEmpty(_error))"
 028                      ErrorText="@_error" />
 029
 030        @if (_result != null && _result.Success)
 31        {
 32            <MudAlert Severity="Severity.Success" Class="mt-3">
 33                <MudText Typo="Typo.body1">
 034                    Successfully joined <strong>@_result.WorldName</strong> as <strong>@_result.AssignedRole</strong>!
 35                </MudText>
 36            </MudAlert>
 37        }
 38    </DialogContent>
 39    <DialogActions>
 040        @if (_result?.Success == true)
 41        {
 42            <MudButton Color="Color.Primary"
 43                       Variant="Variant.Filled"
 44                       OnClick="GoToWorld">
 45                Go to World
 46            </MudButton>
 47        }
 48        else
 49        {
 50            <MudButton OnClick="Cancel">Cancel</MudButton>
 51            <MudButton Color="Color.Primary"
 52                       Variant="Variant.Filled"
 53                       OnClick="Submit"
 54                       Disabled="@(string.IsNullOrWhiteSpace(_code) || _isSubmitting)">
 055                @if (_isSubmitting)
 56                {
 57                    <MudProgressCircular Size="Size.Small" Indeterminate="true" Class="mr-2" />
 58                }
 59                Join
 60            </MudButton>
 61        }
 62    </DialogActions>
 63</MudDialog>
 64
 65@code {
 66    [CascadingParameter]
 067    private MudDialogInstance? MudDialog { get; set; }
 68
 069    private string _code = string.Empty;
 70    private string? _error = null;
 71    private bool _isSubmitting = false;
 72    private WorldJoinResultDto? _result = null;
 73    private MudTextField<string>? _codeField;
 74
 75    protected override async Task OnAfterRenderAsync(bool firstRender)
 76    {
 077        if (firstRender && _codeField != null)
 78        {
 079            await Task.Delay(100);
 080            await _codeField.FocusAsync();
 81        }
 082    }
 83
 084    private void Cancel() => MudDialog?.Cancel();
 85
 86    private void GoToWorld()
 87    {
 088        MudDialog?.Close(DialogResult.Ok(_result));
 089    }
 90
 91    private async Task Submit()
 92    {
 093        if (string.IsNullOrWhiteSpace(_code) || _isSubmitting) return;
 94
 095        _isSubmitting = true;
 096        _error = null;
 097        StateHasChanged();
 98
 99        try
 100        {
 0101            _result = await WorldApi.JoinWorldAsync(_code.Trim());
 102
 0103            if (_result == null)
 104            {
 0105                _error = "Failed to join world. Please try again.";
 106            }
 0107            else if (!_result.Success)
 108            {
 0109                _error = _result.ErrorMessage ?? "Failed to join world.";
 110            }
 111            // Success case is handled by the UI showing the success message
 0112        }
 0113        catch (Exception ex)
 114        {
 0115            _error = $"Error: {ex.Message}";
 0116        }
 117        finally
 118        {
 0119            _isSubmitting = false;
 0120            StateHasChanged();
 121        }
 0122    }
 123}