| | | 1 | | @page "/search" |
| | | 2 | | @attribute [Authorize] |
| | | 3 | | @implements IDisposable |
| | | 4 | | @inject SearchViewModel ViewModel |
| | | 5 | | |
| | | 6 | | <MudPaper Elevation="2" Class="chronicis-article-card chronicis-fade-in"> |
| | | 7 | | @if (ViewModel.IsLoading) |
| | | 8 | | { |
| | | 9 | | <div class="d-flex flex-column align-center mt-8"> |
| | | 10 | | <MudProgressCircular Indeterminate="true" Color="Color.Primary" Size="Size.Large" /> |
| | | 11 | | <MudText Typo="Typo.h6" Class="mt-4">Searching...</MudText> |
| | | 12 | | </div> |
| | | 13 | | } |
| | | 14 | | else if (ViewModel.Results == null) |
| | | 15 | | { |
| | | 16 | | <div class="text-center mt-8"> |
| | | 17 | | <MudIcon Icon="@Icons.Material.Filled.Search" Size="Size.Large" Color="Color.Secondary" Class="mb-4" /> |
| | | 18 | | <MudText Typo="Typo.h5" Color="Color.Secondary">Enter a search term to begin</MudText> |
| | | 19 | | </div> |
| | | 20 | | } |
| | | 21 | | else if (ViewModel.Results.TotalResults == 0) |
| | | 22 | | { |
| | | 23 | | <MudAlert Severity="Severity.Info" Variant="Variant.Outlined" Class="mt-4"> |
| | | 24 | | <MudText Typo="Typo.h6">No results found for "<strong>@ViewModel.Results.Query</strong>"</MudText> |
| | | 25 | | <MudText Typo="Typo.body2" Class="mt-2">Try different keywords or check your spelling</MudText> |
| | | 26 | | </MudAlert> |
| | | 27 | | } |
| | | 28 | | else |
| | | 29 | | { |
| | | 30 | | <div class="mb-4"> |
| | | 31 | | <MudText Typo="Typo.h4"> |
| | | 32 | | Search Results |
| | | 33 | | </MudText> |
| | | 34 | | <MudText Typo="Typo.body1" Class="mt-2" Color="Color.Secondary"> |
| | | 35 | | Found <strong>@ViewModel.Results.TotalResults</strong> result@(ViewModel.Results.TotalResults == 1 ? "" |
| | | 36 | | </MudText> |
| | | 37 | | </div> |
| | | 38 | | |
| | | 39 | | @* Title Matches *@ |
| | | 40 | | @if (ViewModel.Results.TitleMatches.Any()) |
| | | 41 | | { |
| | | 42 | | <div class="search-group mt-6"> |
| | | 43 | | <MudText Typo="Typo.h6" Class="search-group-header mb-3"> |
| | | 44 | | <MudIcon Icon="@Icons.Material.Filled.Title" Class="mr-2" /> |
| | | 45 | | Title Matches (@ViewModel.Results.TitleMatches.Count) |
| | | 46 | | </MudText> |
| | | 47 | | |
| | | 48 | | @foreach (var result in ViewModel.Results.TitleMatches) |
| | | 49 | | { |
| | | 50 | | <SearchResultCard Result="@result" Query="@ViewModel.Results.Query" OnClick="@(() => ViewModel.Navig |
| | | 51 | | } |
| | | 52 | | </div> |
| | | 53 | | } |
| | | 54 | | |
| | | 55 | | @* Content Matches *@ |
| | | 56 | | @if (ViewModel.Results.BodyMatches.Any()) |
| | | 57 | | { |
| | | 58 | | <div class="search-group mt-6"> |
| | | 59 | | <MudText Typo="Typo.h6" Class="search-group-header mb-3"> |
| | | 60 | | <MudIcon Icon="@Icons.Material.Filled.Description" Class="mr-2" /> |
| | | 61 | | Content Matches (@ViewModel.Results.BodyMatches.Count) |
| | | 62 | | </MudText> |
| | | 63 | | |
| | | 64 | | @foreach (var result in ViewModel.Results.BodyMatches) |
| | | 65 | | { |
| | | 66 | | <SearchResultCard Result="@result" Query="@ViewModel.Results.Query" OnClick="@(() => ViewModel.Navig |
| | | 67 | | } |
| | | 68 | | </div> |
| | | 69 | | } |
| | | 70 | | |
| | | 71 | | @* Hashtag Matches *@ |
| | | 72 | | @if (ViewModel.Results.HashtagMatches.Any()) |
| | | 73 | | { |
| | | 74 | | <div class="search-group mt-6"> |
| | | 75 | | <MudText Typo="Typo.h6" Class="search-group-header mb-3"> |
| | | 76 | | <MudIcon Icon="@Icons.Material.Filled.Tag" Class="mr-2" /> |
| | | 77 | | Hashtag Matches (@ViewModel.Results.HashtagMatches.Count) |
| | | 78 | | </MudText> |
| | | 79 | | |
| | | 80 | | @foreach (var result in ViewModel.Results.HashtagMatches) |
| | | 81 | | { |
| | | 82 | | <SearchResultCard Result="@result" Query="@ViewModel.Results.Query" OnClick="@(() => ViewModel.Navig |
| | | 83 | | } |
| | | 84 | | </div> |
| | | 85 | | } |
| | | 86 | | } |
| | | 87 | | </MudPaper> |
| | | 88 | | |
| | | 89 | | @code { |
| | | 90 | | [SupplyParameterFromQuery(Name = "q")] |
| | | 91 | | public string? SearchQuery { get; set; } |
| | | 92 | | |
| | | 93 | | protected override async Task OnParametersSetAsync() |
| | | 94 | | { |
| | | 95 | | ViewModel.PropertyChanged += OnViewModelChanged; |
| | | 96 | | await ViewModel.SearchAsync(SearchQuery); |
| | | 97 | | } |
| | | 98 | | |
| | | 99 | | private void OnViewModelChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e) |
| | 4 | 100 | | => InvokeAsync(StateHasChanged); |
| | | 101 | | |
| | | 102 | | public void Dispose() |
| | | 103 | | { |
| | 4 | 104 | | ViewModel.PropertyChanged -= OnViewModelChanged; |
| | 4 | 105 | | } |
| | | 106 | | } |