Browse Source

WIP Tooltip code

CalculatorDepletedHarvesters
6d486f49 6 months ago
parent
commit
86580a9f5d
  1. 79
      Components/Feedback/TooltipComponent.razor
  2. 30
      IGP/Dialog/SearchDialogComponent.razor
  3. 46
      IGP/Portals/TooltipPortal.razor
  4. 6
      Model/Feedback/TooltipModel.cs
  5. 11
      Services/IServices.cs
  6. 54
      Services/Website/TooltipService.cs

79
Components/Feedback/TooltipComponent.razor

@ -0,0 +1,79 @@
@inject ITooltipService TooltipService
@implements IDisposable
@if (Tooltip == null)
{
<div>Add tooltip object...</div>
}
else
{
<div onclick="@Dismiss" class="tooltipContainer">
<div class="tooltip">
@Tooltip.Message
</div>
</div>
}
<style>
.toastContainer {
border: 4px solid;
border-radius: 4px;
padding: 16px;
display: flex;
flex-direction: column;
justify-items: stretch;
width: 250px;
cursor: pointer;
}
.@SeverityType.Warning.ToLower() {
background-color: var(--severity-warning-color);
border-color: var(--severity-warning-border-color);
}
.@SeverityType.Error.ToLower() {
background-color: var(--severity-error-color);
border-color: var(--severity-error-border-color);
}
.@SeverityType.Information.ToLower() {
background-color: var(--severity-information-color);
border-color: var(--severity-information-border-color);
}
.@SeverityType.Success.ToLower() {
background-color: var(--severity-success-color);
border-color: var(--severity-success-border-color);
}
.toastTitle {
font-weight: 800;
}
</style>
@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()
{
}
}

30
IGP/Dialog/SearchDialogComponent.razor

@ -1,11 +1,11 @@
@implements IDisposable; @implements IDisposable;
@inject ISearchService searchService @inject ISearchService SearchService
@inject IJSRuntime jsRuntime @inject IJSRuntime JsRuntime
@inject NavigationManager navigationManager @inject NavigationManager NavigationManager
@if (searchService.IsLoaded() && searchService.IsVisible) @if (SearchService.IsLoaded() && SearchService.IsVisible)
{ {
<div id="searchBackground" class="searchBackground" onclick="@CloseDialog"> <div id="searchBackground" class="searchBackground" onclick="@CloseDialog">
<div class="searchContainer" <div class="searchContainer"
@ -20,7 +20,7 @@
<div class="searchBox"> <div class="searchBox">
@if (SearchText.Length > 0) @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())); var searchPoints = searchSection.Value.FindAll(x => x.Title.ToLower().Contains(SearchText.ToLower()));
@ -141,7 +141,7 @@
protected override void OnInitialized() protected override void OnInitialized()
{ {
searchService.Subscribe(OnSearchChanged); SearchService.Subscribe(OnSearchChanged);
timer = new Timer(200); timer = new Timer(200);
timer.Elapsed += FocusTimer; timer.Elapsed += FocusTimer;
@ -151,7 +151,7 @@
private void FocusTimer(object? sender, ElapsedEventArgs e) private void FocusTimer(object? sender, ElapsedEventArgs e)
{ {
jsRuntime.InvokeVoidAsync("SetFocusToElement", "searchInput"); JsRuntime.InvokeVoidAsync("SetFocusToElement", "searchInput");
StateHasChanged(); StateHasChanged();
} }
@ -159,9 +159,9 @@
private void OnSearchChanged() private void OnSearchChanged()
{ {
if (timer.Enabled != searchService.IsVisible) if (timer.Enabled != SearchService.IsVisible)
{ {
timer.Enabled = searchService.IsVisible; timer.Enabled = SearchService.IsVisible;
} }
StateHasChanged(); StateHasChanged();
@ -169,26 +169,26 @@
public void Dispose() public void Dispose()
{ {
searchService.Unsubscribe(OnSearchChanged); SearchService.Unsubscribe(OnSearchChanged);
timer.Elapsed -= FocusTimer; timer.Elapsed -= FocusTimer;
} }
public void CloseDialog() public void CloseDialog()
{ {
searchService.Hide(); SearchService.Hide();
} }
public void NavigateTo(string url) public void NavigateTo(string url)
{ {
if (url.Contains("#")) if (url.Contains("#"))
{ {
navigationManager.NavigateTo(url, NavigationManager.NavigateTo(url,
navigationManager.Uri.Split("#").First().Contains(url.Split("#").First())); NavigationManager.Uri.Split("#").First().Contains(url.Split("#").First()));
} }
else else
{ {
navigationManager.NavigateTo(url); NavigationManager.NavigateTo(url);
} }
} }
@ -200,7 +200,7 @@
private void OnSearch(SearchPointModel searchPoint) private void OnSearch(SearchPointModel searchPoint)
{ {
NavigateTo(searchPoint.Href); NavigateTo(searchPoint.Href);
searchService.Hide(); SearchService.Hide();
} }
private void OnFocus(object obj) private void OnFocus(object obj)

46
IGP/Portals/TooltipPortal.razor

@ -0,0 +1,46 @@
@implements IDisposable;
@inject ITooltipService TooltipService
@if (TooltipService.HasTooltips())
{
<div class="tooltipsContainer">
@foreach (var tooltip in Tooltips)
{
<TooltipComponent Tooltip="tooltip"/>
}
</div>
}
<style>
.tooltipContainer {
position: fixed;
top: 64px;
right: 64px;
display: flex;
flex-direction: column;
gap: 5px;
}
</style>
@code {
private List<TooltipModel> Tooltips => TooltipService.GetTooltips();
protected override void OnInitialized()
{
base.OnInitialized();
TooltipService.Subscribe(OnUpdate);
}
void IDisposable.Dispose()
{
TooltipService.Unsubscribe(OnUpdate);
}
void OnUpdate()
{
StateHasChanged();
}
}

6
Model/Feedback/TooltipModel.cs

@ -0,0 +1,6 @@
namespace Model.Feedback;
public class TooltipModel
{
public string Message { get; set; } = "addMessage";
}

11
Services/IServices.cs

@ -11,6 +11,17 @@ using Services.Website;
namespace Services; 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<TooltipModel> GetTooltips();
void ClearAllTooltips();
}
public interface IToastService public interface IToastService
{ {
public void Subscribe(Action action); public void Subscribe(Action action);

54
Services/Website/TooltipService.cs

@ -0,0 +1,54 @@
using Model.Feedback;
namespace Services.Website;
public class TooltipService : ITooltipService
{
private readonly List<TooltipModel> 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<TooltipModel> GetTooltips()
{
return tooltips;
}
public void ClearAllTooltips()
{
tooltips.Clear();
NotifyDataChanged();
}
private event Action OnChange = null!;
private void NotifyDataChanged()
{
OnChange();
}
}
Loading…
Cancel
Save