| | | 1 | | @page "/article/{*Path}" |
| | | 2 | | @attribute [Authorize] |
| | | 3 | | @inject ITreeStateService TreeStateService |
| | | 4 | | @inject IArticleApiService ArticleApi |
| | | 5 | | @inject IQuoteService QuoteService |
| | | 6 | | @inject NavigationManager Navigation |
| | | 7 | | @implements IDisposable |
| | | 8 | | |
| | | 9 | | @code { |
| | | 10 | | private readonly ILogger<Articles> _logger; |
| | | 11 | | |
| | | 12 | | // Direct constructor injection |
| | 0 | 13 | | public Articles(ILogger<Articles> logger) |
| | | 14 | | { |
| | 0 | 15 | | _logger = logger; |
| | 0 | 16 | | } |
| | | 17 | | } |
| | | 18 | | |
| | 0 | 19 | | @if (TreeStateService.SelectedArticleId.HasValue && TreeStateService.SelectedArticleId.Value != Guid.Empty) |
| | | 20 | | { |
| | | 21 | | <ArticleDetail /> |
| | | 22 | | } |
| | | 23 | | else |
| | | 24 | | { |
| | | 25 | | <MudPaper Elevation="2" Class="chronicis-article-card chronicis-fade-in"> |
| | | 26 | | <h6>Loading article...</h6> |
| | | 27 | | </MudPaper> |
| | | 28 | | } |
| | | 29 | | |
| | | 30 | | @code { |
| | | 31 | | [Parameter] |
| | 0 | 32 | | public string? Path { get; set; } |
| | | 33 | | |
| | | 34 | | protected override async Task OnInitializedAsync() |
| | | 35 | | { |
| | 0 | 36 | | TreeStateService.OnStateChanged += OnTreeStateChanged; |
| | | 37 | | |
| | | 38 | | // If URL has article path, load it |
| | 0 | 39 | | if (!string.IsNullOrEmpty(Path)) |
| | | 40 | | { |
| | 0 | 41 | | await LoadArticleByPath(Path); |
| | | 42 | | } |
| | 0 | 43 | | } |
| | | 44 | | |
| | | 45 | | protected override async Task OnParametersSetAsync() |
| | | 46 | | { |
| | | 47 | | // Handle URL changes (browser back/forward) |
| | 0 | 48 | | if (!string.IsNullOrEmpty(Path)) |
| | | 49 | | { |
| | 0 | 50 | | await LoadArticleByPath(Path); |
| | | 51 | | } |
| | 0 | 52 | | } |
| | | 53 | | |
| | | 54 | | private async Task LoadArticleByPath(string path) |
| | | 55 | | { |
| | | 56 | | try |
| | | 57 | | { |
| | 0 | 58 | | var article = await ArticleApi.GetArticleByPathAsync(path); |
| | | 59 | | |
| | 0 | 60 | | if (article != null) |
| | | 61 | | { |
| | 0 | 62 | | if (article.Id != TreeStateService.SelectedArticleId) |
| | | 63 | | { |
| | | 64 | | // Expand path to article and select it |
| | 0 | 65 | | TreeStateService.ExpandPathToAndSelect(article.Id); |
| | | 66 | | } |
| | | 67 | | } |
| | | 68 | | else |
| | | 69 | | { |
| | | 70 | | // Article not found - redirect to dashboard |
| | 0 | 71 | | _logger.LogWarningSanitized("Article not found for path: {Path}", path); |
| | 0 | 72 | | Navigation.NavigateTo("/dashboard", replace: true); |
| | | 73 | | } |
| | 0 | 74 | | } |
| | 0 | 75 | | catch (Exception ex) |
| | | 76 | | { |
| | 0 | 77 | | _logger.LogErrorSanitized(ex, "Error loading article by path: {Path}", path); |
| | 0 | 78 | | Navigation.NavigateTo("/dashboard", replace: true); |
| | 0 | 79 | | } |
| | 0 | 80 | | } |
| | | 81 | | |
| | | 82 | | private async Task NavigateToArticle(Guid articleId) |
| | | 83 | | { |
| | | 84 | | // Get the full article details to build path from breadcrumbs |
| | 0 | 85 | | var article = await ArticleApi.GetArticleDetailAsync(articleId); |
| | 0 | 86 | | if (article != null && article.Breadcrumbs.Any()) |
| | | 87 | | { |
| | 0 | 88 | | var path = string.Join("/", article.Breadcrumbs.Select(b => b.Slug)); |
| | 0 | 89 | | Navigation.NavigateTo($"/article/{path}"); |
| | | 90 | | } |
| | 0 | 91 | | } |
| | | 92 | | |
| | | 93 | | private void OnTreeStateChanged() |
| | | 94 | | { |
| | 0 | 95 | | InvokeAsync(StateHasChanged); |
| | 0 | 96 | | } |
| | | 97 | | |
| | | 98 | | public void Dispose() |
| | | 99 | | { |
| | 0 | 100 | | TreeStateService.OnStateChanged -= OnTreeStateChanged; |
| | 0 | 101 | | } |
| | | 102 | | } |