From 86580a9f5dfa4d40cb53137c08f66ac398d2dce2 Mon Sep 17 00:00:00 2001 From: 6d486f49 <76097bcc@gmail.com> Date: Wed, 5 Nov 2025 15:11:55 -0500 Subject: [PATCH] WIP Tooltip code --- Components/Feedback/TooltipComponent.razor | 79 ++++++++++++++++++++++ IGP/Dialog/SearchDialogComponent.razor | 30 ++++---- IGP/Portals/TooltipPortal.razor | 46 +++++++++++++ Model/Feedback/TooltipModel.cs | 6 ++ Services/IServices.cs | 11 +++ Services/Website/TooltipService.cs | 54 +++++++++++++++ 6 files changed, 211 insertions(+), 15 deletions(-) create mode 100644 Components/Feedback/TooltipComponent.razor create mode 100644 IGP/Portals/TooltipPortal.razor create mode 100644 Model/Feedback/TooltipModel.cs create mode 100644 Services/Website/TooltipService.cs diff --git a/Components/Feedback/TooltipComponent.razor b/Components/Feedback/TooltipComponent.razor new file mode 100644 index 0000000..3c600d7 --- /dev/null +++ b/Components/Feedback/TooltipComponent.razor @@ -0,0 +1,79 @@ +@inject ITooltipService TooltipService + +@implements IDisposable + +@if (Tooltip == null) +{ +
Add tooltip object...
+} +else +{ +
+
+ @Tooltip.Message +
+
+} + + + +@code { + [Parameter] public TooltipModel? Tooltip { get; set; } + + protected override void OnInitialized() + { + base.OnInitialized(); + TooltipService.Subscribe(OnUpdate); + } + + void Dismiss() + { + TooltipService.RemoveTooltip(Tooltip!); + } + + void IDisposable.Dispose() + { + TooltipService.Unsubscribe(OnUpdate); + } + + void OnUpdate() + { + } + +} \ No newline at end of file diff --git a/IGP/Dialog/SearchDialogComponent.razor b/IGP/Dialog/SearchDialogComponent.razor index a3fa8ac..dfbcb53 100644 --- a/IGP/Dialog/SearchDialogComponent.razor +++ b/IGP/Dialog/SearchDialogComponent.razor @@ -1,11 +1,11 @@ @implements IDisposable; -@inject ISearchService searchService -@inject IJSRuntime jsRuntime +@inject ISearchService SearchService +@inject IJSRuntime JsRuntime -@inject NavigationManager navigationManager +@inject NavigationManager NavigationManager -@if (searchService.IsLoaded() && searchService.IsVisible) +@if (SearchService.IsLoaded() && SearchService.IsVisible) {
@if (SearchText.Length > 0) { - foreach (var searchSection in searchService.Searches) + foreach (var searchSection in SearchService.Searches) { var searchPoints = searchSection.Value.FindAll(x => x.Title.ToLower().Contains(SearchText.ToLower())); @@ -141,7 +141,7 @@ protected override void OnInitialized() { - searchService.Subscribe(OnSearchChanged); + SearchService.Subscribe(OnSearchChanged); timer = new Timer(200); timer.Elapsed += FocusTimer; @@ -151,7 +151,7 @@ private void FocusTimer(object? sender, ElapsedEventArgs e) { - jsRuntime.InvokeVoidAsync("SetFocusToElement", "searchInput"); + JsRuntime.InvokeVoidAsync("SetFocusToElement", "searchInput"); StateHasChanged(); } @@ -159,9 +159,9 @@ private void OnSearchChanged() { - if (timer.Enabled != searchService.IsVisible) + if (timer.Enabled != SearchService.IsVisible) { - timer.Enabled = searchService.IsVisible; + timer.Enabled = SearchService.IsVisible; } StateHasChanged(); @@ -169,26 +169,26 @@ public void Dispose() { - searchService.Unsubscribe(OnSearchChanged); + SearchService.Unsubscribe(OnSearchChanged); timer.Elapsed -= FocusTimer; } public void CloseDialog() { - searchService.Hide(); + SearchService.Hide(); } public void NavigateTo(string url) { if (url.Contains("#")) { - navigationManager.NavigateTo(url, - navigationManager.Uri.Split("#").First().Contains(url.Split("#").First())); + NavigationManager.NavigateTo(url, + NavigationManager.Uri.Split("#").First().Contains(url.Split("#").First())); } else { - navigationManager.NavigateTo(url); + NavigationManager.NavigateTo(url); } } @@ -200,7 +200,7 @@ private void OnSearch(SearchPointModel searchPoint) { NavigateTo(searchPoint.Href); - searchService.Hide(); + SearchService.Hide(); } private void OnFocus(object obj) diff --git a/IGP/Portals/TooltipPortal.razor b/IGP/Portals/TooltipPortal.razor new file mode 100644 index 0000000..1b19562 --- /dev/null +++ b/IGP/Portals/TooltipPortal.razor @@ -0,0 +1,46 @@ +@implements IDisposable; + +@inject ITooltipService TooltipService + +@if (TooltipService.HasTooltips()) +{ +
+ @foreach (var tooltip in Tooltips) + { + + } +
+} + + + + +@code { + private List Tooltips => TooltipService.GetTooltips(); + + protected override void OnInitialized() + { + base.OnInitialized(); + TooltipService.Subscribe(OnUpdate); + } + + void IDisposable.Dispose() + { + TooltipService.Unsubscribe(OnUpdate); + } + + void OnUpdate() + { + StateHasChanged(); + } + +} \ No newline at end of file diff --git a/Model/Feedback/TooltipModel.cs b/Model/Feedback/TooltipModel.cs new file mode 100644 index 0000000..6c02ffe --- /dev/null +++ b/Model/Feedback/TooltipModel.cs @@ -0,0 +1,6 @@ +namespace Model.Feedback; + +public class TooltipModel +{ + public string Message { get; set; } = "addMessage"; +} \ No newline at end of file diff --git a/Services/IServices.cs b/Services/IServices.cs index 2e679a1..226ea11 100644 --- a/Services/IServices.cs +++ b/Services/IServices.cs @@ -11,6 +11,17 @@ using Services.Website; namespace Services; +public interface ITooltipService +{ + public void Subscribe(Action action); + public void Unsubscribe(Action action); + void AddTooltip(TooltipModel tooltip); + void RemoveTooltip(TooltipModel tooltip); + bool HasTooltips(); + List GetTooltips(); + void ClearAllTooltips(); +} + public interface IToastService { public void Subscribe(Action action); diff --git a/Services/Website/TooltipService.cs b/Services/Website/TooltipService.cs new file mode 100644 index 0000000..74a0fb6 --- /dev/null +++ b/Services/Website/TooltipService.cs @@ -0,0 +1,54 @@ +using Model.Feedback; + +namespace Services.Website; + +public class TooltipService : ITooltipService +{ + private readonly List tooltips = new(); + + public void Subscribe(Action action) + { + OnChange += action; + } + + public void Unsubscribe(Action action) + { + OnChange += action; + } + + public void AddTooltip(TooltipModel tooltip) + { + tooltips.Insert(0, tooltip); + + NotifyDataChanged(); + } + + public void RemoveTooltip(TooltipModel tooltip) + { + tooltips.Remove(tooltip); + } + + public bool HasTooltips() + { + return tooltips.Count > 0; + } + + public List GetTooltips() + { + return tooltips; + } + + + public void ClearAllTooltips() + { + tooltips.Clear(); + NotifyDataChanged(); + } + + private event Action OnChange = null!; + + private void NotifyDataChanged() + { + OnChange(); + } +} \ No newline at end of file