| | | 1 | | @page "/arc/{ArcId:guid}" |
| | | 2 | | @attribute [Authorize] |
| | | 3 | | @using Chronicis.Shared.DTOs |
| | | 4 | | @using Chronicis.Shared.DTOs.Quests |
| | | 5 | | @using Chronicis.Shared.Enums |
| | | 6 | | @using Chronicis.Client.Components.Dialogs |
| | | 7 | | @using Chronicis.Client.Components.Shared |
| | | 8 | | @using Chronicis.Client.Components.Quests |
| | | 9 | | @using Chronicis.Client.Utilities |
| | | 10 | | @inject IArcApiService ArcApi |
| | | 11 | | @inject ICampaignApiService CampaignApi |
| | | 12 | | @inject IWorldApiService WorldApi |
| | | 13 | | @inject IArticleApiService ArticleApi |
| | | 14 | | @inject IQuestApiService QuestApi |
| | | 15 | | @inject IAuthService AuthService |
| | | 16 | | @inject ITreeStateService TreeState |
| | | 17 | | @inject IBreadcrumbService BreadcrumbService |
| | | 18 | | @inject ISnackbar Snackbar |
| | | 19 | | @inject IDialogService DialogService |
| | | 20 | | @inject NavigationManager Navigation |
| | | 21 | | @inject IJSRuntime JSRuntime |
| | | 22 | | |
| | 0 | 23 | | @if (_isLoading) |
| | | 24 | | { |
| | | 25 | | <LoadingSkeleton /> |
| | | 26 | | } |
| | 0 | 27 | | else if (_arc != null) |
| | | 28 | | { |
| | | 29 | | <MudPaper Elevation="2" Class="chronicis-article-card chronicis-fade-in"> |
| | | 30 | | <DetailPageHeader Breadcrumbs="_breadcrumbs" |
| | | 31 | | Icon="@Icons.Material.Filled.Bookmark" |
| | | 32 | | @bind-Title="_editName" |
| | | 33 | | Placeholder="Arc Name" |
| | | 34 | | OnTitleEdited="OnNameChanged" |
| | | 35 | | OnEnterPressed="SaveArc" /> |
| | | 36 | | |
| | | 37 | | <!-- Description --> |
| | | 38 | | <MudTextField @bind-Value="_editDescription" |
| | | 39 | | Label="Description" |
| | | 40 | | Variant="Variant.Outlined" |
| | | 41 | | Lines="3" |
| | | 42 | | Placeholder="Describe this arc..." |
| | | 43 | | Class="mb-4" |
| | | 44 | | Immediate="true" |
| | | 45 | | @onkeyup="OnDescriptionChanged" /> |
| | | 46 | | |
| | | 47 | | <!-- Sort Order --> |
| | | 48 | | <MudNumericField @bind-Value="_editSortOrder" |
| | | 49 | | Label="Sort Order" |
| | | 50 | | Variant="Variant.Outlined" |
| | | 51 | | Min="0" |
| | | 52 | | Class="mb-4" |
| | | 53 | | Style="max-width: 150px;" |
| | | 54 | | Immediate="true" |
| | | 55 | | @onkeyup="OnSortOrderChanged" /> |
| | | 56 | | |
| | | 57 | | <!-- Sessions Section --> |
| | | 58 | | <div class="d-flex align-center justify-space-between mb-3"> |
| | | 59 | | <MudText Typo="Typo.h6" Style="color: var(--chronicis-beige-gold);"> |
| | | 60 | | <MudIcon Icon="@Icons.Material.Filled.EventNote" Size="Size.Small" Class="mr-2" /> |
| | | 61 | | Sessions |
| | | 62 | | </MudText> |
| | | 63 | | <MudButton Variant="Variant.Filled" |
| | | 64 | | Color="Color.Primary" |
| | | 65 | | Size="Size.Small" |
| | | 66 | | StartIcon="@Icons.Material.Filled.Add" |
| | | 67 | | OnClick="CreateSession"> |
| | | 68 | | New Session |
| | | 69 | | </MudButton> |
| | | 70 | | </div> |
| | | 71 | | |
| | 0 | 72 | | @if (_sessions.Any()) |
| | | 73 | | { |
| | | 74 | | <MudList T="ArticleTreeDto" Dense="true" Class="mb-4"> |
| | 0 | 75 | | @foreach (var session in _sessions.OrderBy(s => s.Title)) |
| | | 76 | | { |
| | | 77 | | <EntityListItem Icon="@Icons.Material.Filled.EventNote" |
| | | 78 | | Title="@(string.IsNullOrEmpty(session.Title) ? "Untitled Session" : session.Title)" |
| | 0 | 79 | | OnClick="@(() => NavigateToSession(session))" /> |
| | | 80 | | } |
| | | 81 | | </MudList> |
| | | 82 | | } |
| | | 83 | | else |
| | | 84 | | { |
| | | 85 | | <MudAlert Severity="Severity.Info" Class="mb-4"> |
| | | 86 | | No sessions yet. Create your first session to start documenting your adventures! |
| | | 87 | | </MudAlert> |
| | | 88 | | } |
| | | 89 | | |
| | | 90 | | <!-- Quests Section --> |
| | | 91 | | <ArcQuestList ArcId="@ArcId" IsGm="_isCurrentUserGM" /> |
| | | 92 | | |
| | 0 | 93 | | @if (_selectedQuest != null) |
| | | 94 | | { |
| | | 95 | | <MudDivider Class="my-4" /> |
| | | 96 | | |
| | | 97 | | <!-- Quest Editor --> |
| | | 98 | | <ArcQuestEditor Quest="_selectedQuest" |
| | | 99 | | OnQuestUpdated="OnQuestUpdated" /> |
| | | 100 | | |
| | | 101 | | <!-- Quest Timeline --> |
| | | 102 | | <ArcQuestTimeline Quest="_selectedQuest" |
| | | 103 | | IsGm="_isCurrentUserGM" |
| | | 104 | | CurrentUserId="_currentUserId" /> |
| | | 105 | | } |
| | | 106 | | |
| | | 107 | | <!-- Arc Info --> |
| | | 108 | | <MudText Typo="Typo.h6" Class="mb-3" Style="color: var(--chronicis-beige-gold);"> |
| | | 109 | | Arc Info |
| | | 110 | | </MudText> |
| | | 111 | | |
| | | 112 | | <MudSimpleTable Dense="true" Hover="true" Class="mb-4"> |
| | | 113 | | <tbody> |
| | | 114 | | <tr> |
| | | 115 | | <td><MudIcon Icon="@Icons.Material.Filled.PlayCircle" Size="Size.Small" Class="mr-2" />Active Arc</t |
| | | 116 | | <td> |
| | | 117 | | <MudSwitch T="bool" |
| | | 118 | | Value="_arc.IsActive" |
| | | 119 | | ValueChanged="OnActiveToggle" |
| | | 120 | | Color="Color.Success" |
| | | 121 | | Size="Size.Small" |
| | | 122 | | Disabled="_isTogglingActive" /> |
| | | 123 | | </td> |
| | | 124 | | </tr> |
| | | 125 | | <tr> |
| | | 126 | | <td><MudIcon Icon="@Icons.Material.Filled.EventNote" Size="Size.Small" Class="mr-2" />Sessions</td> |
| | 0 | 127 | | <td>@_arc.SessionCount</td> |
| | | 128 | | </tr> |
| | | 129 | | <tr> |
| | | 130 | | <td><MudIcon Icon="@Icons.Material.Filled.Sort" Size="Size.Small" Class="mr-2" />Sort Order</td> |
| | 0 | 131 | | <td>@_arc.SortOrder</td> |
| | | 132 | | </tr> |
| | | 133 | | <tr> |
| | | 134 | | <td><MudIcon Icon="@Icons.Material.Filled.CalendarToday" Size="Size.Small" Class="mr-2" />Created</t |
| | 0 | 135 | | <td>@_arc.CreatedAt.ToString("MMMM d, yyyy")</td> |
| | | 136 | | </tr> |
| | | 137 | | </tbody> |
| | | 138 | | </MudSimpleTable> |
| | | 139 | | |
| | | 140 | | <!-- AI Summary Section --> |
| | | 141 | | <AISummarySection EntityId="ArcId" |
| | | 142 | | EntityType="Arc" |
| | | 143 | | @bind-IsExpanded="_summaryExpanded" /> |
| | | 144 | | |
| | | 145 | | <!-- Save Status --> |
| | | 146 | | <div class="chronicis-flex-between mt-4"> |
| | | 147 | | <SaveStatusIndicator IsSaving="_isSaving" HasUnsavedChanges="_hasUnsavedChanges" /> |
| | | 148 | | |
| | | 149 | | <div class="d-flex gap-2"> |
| | | 150 | | <MudButton Variant="Variant.Filled" |
| | | 151 | | Color="Color.Primary" |
| | | 152 | | OnClick="SaveArc" |
| | | 153 | | Disabled="_isSaving" |
| | | 154 | | StartIcon="@Icons.Material.Filled.Save"> |
| | | 155 | | Save |
| | | 156 | | </MudButton> |
| | | 157 | | |
| | | 158 | | <MudButton Variant="Variant.Outlined" |
| | | 159 | | Color="Color.Error" |
| | | 160 | | OnClick="DeleteArc" |
| | | 161 | | Disabled="_isSaving || _sessions.Any()" |
| | | 162 | | StartIcon="@Icons.Material.Filled.Delete"> |
| | | 163 | | Delete |
| | | 164 | | </MudButton> |
| | | 165 | | </div> |
| | | 166 | | </div> |
| | | 167 | | |
| | 0 | 168 | | @if (_sessions.Any()) |
| | | 169 | | { |
| | | 170 | | <MudText Typo="Typo.caption" Class="mt-2" Style="color: var(--mud-palette-text-secondary);"> |
| | | 171 | | Delete all sessions before deleting this arc. |
| | | 172 | | </MudText> |
| | | 173 | | } |
| | | 174 | | </MudPaper> |
| | | 175 | | } |
| | | 176 | | |
| | | 177 | | @code { |
| | | 178 | | [Parameter] |
| | 0 | 179 | | public Guid ArcId { get; set; } |
| | | 180 | | |
| | | 181 | | private ArcDto? _arc; |
| | | 182 | | private CampaignDto? _campaign; |
| | | 183 | | private WorldDto? _world; |
| | 0 | 184 | | private List<ArticleTreeDto> _sessions = new(); |
| | 0 | 185 | | private string _editName = string.Empty; |
| | 0 | 186 | | private string _editDescription = string.Empty; |
| | | 187 | | private int _editSortOrder = 0; |
| | 0 | 188 | | private bool _isLoading = true; |
| | | 189 | | private bool _isSaving = false; |
| | | 190 | | private bool _isTogglingActive = false; |
| | | 191 | | private bool _hasUnsavedChanges = false; |
| | | 192 | | private bool _summaryExpanded = false; |
| | 0 | 193 | | private List<BreadcrumbItem> _breadcrumbs = new(); |
| | | 194 | | |
| | | 195 | | // Quest state |
| | | 196 | | private QuestDto? _selectedQuest; |
| | | 197 | | private Guid _currentUserId; |
| | | 198 | | private bool _isCurrentUserGM = false; |
| | | 199 | | |
| | | 200 | | protected override async Task OnParametersSetAsync() |
| | | 201 | | { |
| | 0 | 202 | | await LoadArcAsync(); |
| | 0 | 203 | | } |
| | | 204 | | |
| | | 205 | | private async Task LoadArcAsync() |
| | | 206 | | { |
| | 0 | 207 | | _isLoading = true; |
| | 0 | 208 | | StateHasChanged(); |
| | | 209 | | |
| | | 210 | | try |
| | | 211 | | { |
| | 0 | 212 | | _arc = await ArcApi.GetArcAsync(ArcId); |
| | 0 | 213 | | if (_arc == null) |
| | | 214 | | { |
| | 0 | 215 | | Navigation.NavigateTo("/dashboard", replace: true); |
| | 0 | 216 | | return; |
| | | 217 | | } |
| | | 218 | | else |
| | | 219 | | { |
| | 0 | 220 | | _editName = _arc.Name; |
| | 0 | 221 | | _editDescription = _arc.Description ?? string.Empty; |
| | 0 | 222 | | _editSortOrder = _arc.SortOrder; |
| | 0 | 223 | | _hasUnsavedChanges = false; |
| | | 224 | | |
| | | 225 | | // Load sessions (articles with ArcId and Session type) |
| | 0 | 226 | | var allArticles = await ArticleApi.GetAllArticlesAsync(); |
| | 0 | 227 | | _sessions = allArticles |
| | 0 | 228 | | .Where(a => a.ArcId == ArcId && a.Type == ArticleType.Session) |
| | 0 | 229 | | .ToList(); |
| | | 230 | | |
| | | 231 | | // Load campaign and world for breadcrumbs |
| | 0 | 232 | | _campaign = await CampaignApi.GetCampaignAsync(_arc.CampaignId); |
| | 0 | 233 | | if (_campaign != null) |
| | | 234 | | { |
| | 0 | 235 | | var worldDetail = await WorldApi.GetWorldAsync(_campaign.WorldId); |
| | 0 | 236 | | _world = worldDetail != null ? new WorldDto |
| | 0 | 237 | | { |
| | 0 | 238 | | Id = worldDetail.Id, |
| | 0 | 239 | | Name = worldDetail.Name, |
| | 0 | 240 | | Slug = worldDetail.Slug |
| | 0 | 241 | | } : null; |
| | | 242 | | } |
| | | 243 | | |
| | 0 | 244 | | if (_arc != null && _campaign != null && _world != null) |
| | | 245 | | { |
| | 0 | 246 | | _breadcrumbs = BreadcrumbService.ForArc(_arc, _campaign, _world); |
| | | 247 | | } |
| | | 248 | | else |
| | | 249 | | { |
| | | 250 | | // Fallback if data not fully loaded |
| | 0 | 251 | | _breadcrumbs = new List<BreadcrumbItem> |
| | 0 | 252 | | { |
| | 0 | 253 | | new("Dashboard", href: "/dashboard"), |
| | 0 | 254 | | new(_arc?.Name ?? "Arc", href: null, disabled: true) |
| | 0 | 255 | | }; |
| | | 256 | | } |
| | | 257 | | |
| | 0 | 258 | | await JSRuntime.InvokeVoidAsync("eval", $"document.title = '{JsUtilities.EscapeForJs(_arc?.Name ?? "Arc" |
| | | 259 | | |
| | | 260 | | // Highlight in tree |
| | 0 | 261 | | TreeState.ExpandPathToAndSelect(ArcId); |
| | | 262 | | |
| | | 263 | | // Get current user info for quest permissions |
| | 0 | 264 | | var user = await AuthService.GetCurrentUserAsync(); |
| | 0 | 265 | | if (user != null && _world != null) |
| | | 266 | | { |
| | 0 | 267 | | var worldDetail = await WorldApi.GetWorldAsync(_world.Id); |
| | 0 | 268 | | if (worldDetail?.Members != null) |
| | | 269 | | { |
| | 0 | 270 | | var currentMember = worldDetail.Members.FirstOrDefault(m => |
| | 0 | 271 | | m.Email.Equals(user.Email, StringComparison.OrdinalIgnoreCase)); |
| | | 272 | | |
| | 0 | 273 | | if (currentMember != null) |
| | | 274 | | { |
| | 0 | 275 | | _currentUserId = currentMember.UserId; |
| | 0 | 276 | | _isCurrentUserGM = currentMember.Role == WorldRole.GM; |
| | | 277 | | } |
| | | 278 | | } |
| | | 279 | | } |
| | 0 | 280 | | } |
| | 0 | 281 | | } |
| | 0 | 282 | | catch (Exception ex) |
| | | 283 | | { |
| | 0 | 284 | | Snackbar.Add($"Failed to load arc: {ex.Message}", Severity.Error); |
| | 0 | 285 | | } |
| | | 286 | | finally |
| | | 287 | | { |
| | 0 | 288 | | _isLoading = false; |
| | | 289 | | } |
| | 0 | 290 | | } |
| | | 291 | | |
| | 0 | 292 | | private void OnNameChanged() => _hasUnsavedChanges = true; |
| | 0 | 293 | | private void OnDescriptionChanged() => _hasUnsavedChanges = true; |
| | 0 | 294 | | private void OnSortOrderChanged() => _hasUnsavedChanges = true; |
| | | 295 | | |
| | | 296 | | private async Task OnActiveToggle(bool isActive) |
| | | 297 | | { |
| | 0 | 298 | | if (_arc == null || _isTogglingActive) return; |
| | | 299 | | |
| | 0 | 300 | | _isTogglingActive = true; |
| | 0 | 301 | | StateHasChanged(); |
| | | 302 | | |
| | | 303 | | try |
| | | 304 | | { |
| | 0 | 305 | | if (isActive) |
| | | 306 | | { |
| | 0 | 307 | | var success = await ArcApi.ActivateArcAsync(ArcId); |
| | 0 | 308 | | if (success) |
| | | 309 | | { |
| | 0 | 310 | | _arc.IsActive = true; |
| | 0 | 311 | | Snackbar.Add("Arc set as active", Severity.Success); |
| | | 312 | | } |
| | | 313 | | else |
| | | 314 | | { |
| | 0 | 315 | | Snackbar.Add("Failed to activate arc", Severity.Error); |
| | | 316 | | } |
| | | 317 | | } |
| | | 318 | | else |
| | | 319 | | { |
| | 0 | 320 | | Snackbar.Add("To deactivate, set another arc as active", Severity.Info); |
| | | 321 | | } |
| | 0 | 322 | | } |
| | 0 | 323 | | catch (Exception ex) |
| | | 324 | | { |
| | 0 | 325 | | Snackbar.Add($"Error: {ex.Message}", Severity.Error); |
| | 0 | 326 | | } |
| | | 327 | | finally |
| | | 328 | | { |
| | 0 | 329 | | _isTogglingActive = false; |
| | 0 | 330 | | StateHasChanged(); |
| | | 331 | | } |
| | 0 | 332 | | } |
| | | 333 | | |
| | | 334 | | private async Task SaveArc() |
| | | 335 | | { |
| | 0 | 336 | | if (_arc == null || _isSaving) return; |
| | | 337 | | |
| | 0 | 338 | | _isSaving = true; |
| | 0 | 339 | | StateHasChanged(); |
| | | 340 | | |
| | | 341 | | try |
| | | 342 | | { |
| | 0 | 343 | | var updateDto = new ArcUpdateDto |
| | 0 | 344 | | { |
| | 0 | 345 | | Name = _editName.Trim(), |
| | 0 | 346 | | Description = string.IsNullOrWhiteSpace(_editDescription) ? null : _editDescription.Trim(), |
| | 0 | 347 | | SortOrder = _editSortOrder |
| | 0 | 348 | | }; |
| | | 349 | | |
| | 0 | 350 | | var updated = await ArcApi.UpdateArcAsync(ArcId, updateDto); |
| | 0 | 351 | | if (updated != null) |
| | | 352 | | { |
| | 0 | 353 | | _arc.Name = updated.Name; |
| | 0 | 354 | | _arc.Description = updated.Description; |
| | 0 | 355 | | _arc.SortOrder = updated.SortOrder; |
| | 0 | 356 | | _hasUnsavedChanges = false; |
| | | 357 | | |
| | 0 | 358 | | await TreeState.RefreshAsync(); |
| | 0 | 359 | | await JSRuntime.InvokeVoidAsync("eval", $"document.title = '{JsUtilities.EscapeForJs(_editName)} - Chron |
| | | 360 | | |
| | 0 | 361 | | Snackbar.Add("Arc saved", Severity.Success); |
| | | 362 | | } |
| | 0 | 363 | | } |
| | 0 | 364 | | catch (Exception ex) |
| | | 365 | | { |
| | 0 | 366 | | Snackbar.Add($"Failed to save: {ex.Message}", Severity.Error); |
| | 0 | 367 | | } |
| | | 368 | | finally |
| | | 369 | | { |
| | 0 | 370 | | _isSaving = false; |
| | 0 | 371 | | StateHasChanged(); |
| | | 372 | | } |
| | 0 | 373 | | } |
| | | 374 | | |
| | | 375 | | private async Task DeleteArc() |
| | | 376 | | { |
| | 0 | 377 | | if (_arc == null || _sessions.Any()) return; |
| | | 378 | | |
| | 0 | 379 | | var confirmed = await JSRuntime.InvokeAsync<bool>("confirm", |
| | 0 | 380 | | $"Are you sure you want to delete '{_arc.Name}'?\n\nThis action cannot be undone."); |
| | | 381 | | |
| | 0 | 382 | | if (!confirmed) return; |
| | | 383 | | |
| | | 384 | | try |
| | | 385 | | { |
| | 0 | 386 | | await ArcApi.DeleteArcAsync(ArcId); |
| | 0 | 387 | | await TreeState.RefreshAsync(); |
| | | 388 | | |
| | 0 | 389 | | Snackbar.Add("Arc deleted", Severity.Success); |
| | 0 | 390 | | Navigation.NavigateTo($"/campaign/{_arc.CampaignId}"); |
| | 0 | 391 | | } |
| | 0 | 392 | | catch (Exception ex) |
| | | 393 | | { |
| | 0 | 394 | | Snackbar.Add($"Failed to delete: {ex.Message}", Severity.Error); |
| | 0 | 395 | | } |
| | 0 | 396 | | } |
| | | 397 | | |
| | | 398 | | private async Task CreateSession() |
| | | 399 | | { |
| | 0 | 400 | | if (_arc == null || _campaign == null) return; |
| | | 401 | | |
| | 0 | 402 | | var sessionNumber = _sessions.Count + 1; |
| | 0 | 403 | | var createDto = new ArticleCreateDto |
| | 0 | 404 | | { |
| | 0 | 405 | | Title = $"Session {sessionNumber}", |
| | 0 | 406 | | Body = string.Empty, |
| | 0 | 407 | | WorldId = _campaign.WorldId, |
| | 0 | 408 | | CampaignId = _campaign.Id, |
| | 0 | 409 | | ArcId = ArcId, |
| | 0 | 410 | | Type = ArticleType.Session, |
| | 0 | 411 | | EffectiveDate = DateTime.Now |
| | 0 | 412 | | }; |
| | | 413 | | |
| | 0 | 414 | | var created = await ArticleApi.CreateArticleAsync(createDto); |
| | 0 | 415 | | if (created == null) |
| | | 416 | | { |
| | 0 | 417 | | Snackbar.Add("Failed to create session", Severity.Error); |
| | 0 | 418 | | return; |
| | | 419 | | } |
| | | 420 | | |
| | 0 | 421 | | await TreeState.RefreshAsync(); |
| | 0 | 422 | | await LoadArcAsync(); |
| | | 423 | | |
| | | 424 | | // Navigate using full path from breadcrumbs |
| | 0 | 425 | | if (created.Breadcrumbs.Any()) |
| | | 426 | | { |
| | 0 | 427 | | var path = BreadcrumbService.BuildArticleUrl(created.Breadcrumbs); |
| | 0 | 428 | | Navigation.NavigateTo(path); |
| | | 429 | | } |
| | | 430 | | else |
| | | 431 | | { |
| | 0 | 432 | | Navigation.NavigateTo($"/article/{created.Slug}"); |
| | | 433 | | } |
| | 0 | 434 | | Snackbar.Add("Session created", Severity.Success); |
| | 0 | 435 | | } |
| | | 436 | | |
| | | 437 | | private async Task NavigateToSession(ArticleTreeDto session) |
| | | 438 | | { |
| | | 439 | | // Load full article to get breadcrumbs for proper path |
| | 0 | 440 | | var article = await ArticleApi.GetArticleDetailAsync(session.Id); |
| | 0 | 441 | | if (article != null && article.Breadcrumbs.Any()) |
| | | 442 | | { |
| | 0 | 443 | | var path = BreadcrumbService.BuildArticleUrl(article.Breadcrumbs); |
| | 0 | 444 | | Navigation.NavigateTo(path); |
| | | 445 | | } |
| | | 446 | | else |
| | | 447 | | { |
| | | 448 | | // Fallback |
| | 0 | 449 | | Navigation.NavigateTo($"/article/{session.Slug}"); |
| | | 450 | | } |
| | 0 | 451 | | } |
| | | 452 | | |
| | | 453 | | private void OnQuestUpdated(QuestDto updatedQuest) |
| | | 454 | | { |
| | 0 | 455 | | _selectedQuest = updatedQuest; |
| | 0 | 456 | | StateHasChanged(); |
| | 0 | 457 | | } |
| | | 458 | | } |