feat(ui): add global search bar in header with smart routing
This commit is contained in:
1 parent
d5776496e7
commit
493747bb70
1 file changed
+40
-1
@@ -13,10 +13,18 @@
|
||||
<MudIconButton Icon="@Icons.Material.Filled.Menu" Color="Color.Inherit"
|
||||
@onclick="@(() => _drawerOpen = !_drawerOpen)" />
|
||||
<MudText Typo="Typo.h6" Class="ml-2">Heimdall</MudText>
|
||||
|
||||
@* Global Search *@
|
||||
<MudTextField @bind-Value="_searchQuery" Placeholder="Rechercher..." Variant="Variant.Outlined"
|
||||
Adornment="Adornment.End" AdornmentIcon="@Icons.Material.Filled.Search"
|
||||
OnAdornmentClick="@DoSearch" OnKeyDown="@HandleSearchKey"
|
||||
Class="ml-4" Style="max-width:320px;" Margin="Margin.Dense" />
|
||||
|
||||
<MudSpacer />
|
||||
@if (Auth.IsLoggedIn)
|
||||
{
|
||||
<MudIconButton Icon="@Icons.Material.Filled.Notifications" Color="Color.Inherit" />
|
||||
<MudIconButton Icon="@Icons.Material.Filled.Notifications" Color="Color.Inherit"
|
||||
OnClick="@(() => Navigation.NavigateTo("/events"))" />
|
||||
<MudMenu AnchorOrigin="Origin.BottomRight">
|
||||
<ActivatorContent>
|
||||
<MudIconButton Icon="@Icons.Material.Filled.AccountCircle" Color="Color.Inherit" />
|
||||
@@ -101,6 +109,7 @@
|
||||
|
||||
@code {
|
||||
private bool _drawerOpen = true;
|
||||
private string _searchQuery = "";
|
||||
|
||||
private async Task Logout()
|
||||
{
|
||||
@@ -108,4 +117,34 @@
|
||||
await JsRuntime.InvokeVoidAsync("heimdallAuth.signOut");
|
||||
Navigation.NavigateTo("/login", true);
|
||||
}
|
||||
|
||||
private async Task DoSearch()
|
||||
{
|
||||
var q = _searchQuery?.Trim();
|
||||
if (string.IsNullOrEmpty(q)) return;
|
||||
|
||||
// Route search to the most relevant page based on the query
|
||||
if (Guid.TryParse(q, out var _))
|
||||
{
|
||||
// It looks like a GUID — try cameras, events, persons
|
||||
Navigation.NavigateTo($"/cameras/{q}");
|
||||
}
|
||||
else if (q.Contains(' '))
|
||||
{
|
||||
// Multi-word: search events by type/label
|
||||
Navigation.NavigateTo($"/events?q={Uri.EscapeDataString(q)}");
|
||||
}
|
||||
else
|
||||
{
|
||||
// Default: search events
|
||||
Navigation.NavigateTo($"/events?q={Uri.EscapeDataString(q)}");
|
||||
}
|
||||
await Task.CompletedTask;
|
||||
}
|
||||
|
||||
private async Task HandleSearchKey(KeyboardEventArgs e)
|
||||
{
|
||||
if (e.Key == "Enter")
|
||||
await DoSearch();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user