diff --git a/src/Heimdall.Web/Components/Layout/MainLayout.razor b/src/Heimdall.Web/Components/Layout/MainLayout.razor index 1ed7ae5..8a8bbd2 100644 --- a/src/Heimdall.Web/Components/Layout/MainLayout.razor +++ b/src/Heimdall.Web/Components/Layout/MainLayout.razor @@ -13,10 +13,18 @@ Heimdall + + @* Global Search *@ + + @if (Auth.IsLoggedIn) { - + @@ -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(); + } }