improve search user experience

This commit is contained in:
sbwalker 2024-07-18 11:49:42 -04:00
parent b0e121a53f
commit 4f3190bf73
3 changed files with 23 additions and 17 deletions

View File

@ -76,13 +76,9 @@
protected override async Task OnInitializedAsync() protected override async Task OnInitializedAsync()
{ {
if (PageState.QueryString.ContainsKey("q")) if (_keywords == null && PageState.QueryString.ContainsKey("q"))
{ {
_keywords = WebUtility.UrlDecode(PageState.QueryString["q"]); _keywords = WebUtility.UrlDecode(PageState.QueryString["q"]);
}
if (!string.IsNullOrEmpty(_keywords))
{
await PerformSearch(); await PerformSearch();
} }
} }
@ -97,18 +93,25 @@
_loading = true; _loading = true;
StateHasChanged(); StateHasChanged();
var searchQuery = new SearchQuery if (!string.IsNullOrEmpty(_keywords))
{ {
SiteId = PageState.Site.SiteId, var searchQuery = new SearchQuery
Alias = PageState.Alias, {
Keywords = _keywords, SiteId = PageState.Site.SiteId,
SortDirection = _searchSortDirection, Alias = PageState.Alias,
SortField = _searchSortField, Keywords = _keywords,
PageIndex = 0, SortDirection = _searchSortDirection,
PageSize = int.MaxValue SortField = _searchSortField,
}; PageIndex = 0,
PageSize = int.MaxValue
};
_searchResults = await SearchResultsService.GetSearchResultsAsync(searchQuery); _searchResults = await SearchResultsService.GetSearchResultsAsync(searchQuery);
}
else
{
AddModuleMessage(Localizer["NoCriteria"], MessageType.Info, "bottom");
}
_loading = false; _loading = false;
StateHasChanged(); StateHasChanged();

View File

@ -117,6 +117,9 @@
<resheader name="writer"> <resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader> </resheader>
<data name="NoCriteria" xml:space="preserve">
<value>You Must Provide Some Search Criteria</value>
</data>
<data name="NoResult" xml:space="preserve"> <data name="NoResult" xml:space="preserve">
<value>No Content Matches The Criteria Provided</value> <value>No Content Matches The Criteria Provided</value>
</data> </data>

View File

@ -53,7 +53,7 @@
private void PerformSearch() private void PerformSearch()
{ {
var keywords = HttpContext.HttpContext.Request.Form["keywords"]; var keywords = HttpContext.HttpContext.Request.Form["keywords"];
if (!string.IsNullOrEmpty(keywords) && _searchResultsPage != null) if (_searchResultsPage != null)
{ {
var url = NavigateUrl(_searchResultsPage.Path, $"q={keywords}"); var url = NavigateUrl(_searchResultsPage.Path, $"q={keywords}");
NavigationManager.NavigateTo(url); NavigationManager.NavigateTo(url);