fix(Toast) Fixing fading.
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
@using Services
|
||||
@inject IToastService toastService
|
||||
@inject IToastService toastService
|
||||
|
||||
@implements IDisposable
|
||||
|
||||
@@ -9,7 +8,7 @@
|
||||
}
|
||||
else
|
||||
{
|
||||
<div onclick="@Dismiss" class="toastContainer @FadeoutStyle @Toast.SeverityType.ToLower()">
|
||||
<div onclick="@Dismiss" style="opacity: @Opacity()" class="toastContainer @Toast.SeverityType.ToLower()">
|
||||
<div class="toastTitle">
|
||||
@Toast.Title
|
||||
</div>
|
||||
@@ -28,15 +27,9 @@ else
|
||||
flex-direction: column;
|
||||
justify-items: stretch;
|
||||
width: 250px;
|
||||
opacity: 1;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.fadeout {
|
||||
transition: opacity 3s ease-in;
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
.@SeverityType.Warning.ToLower() {
|
||||
background-color: var(--severity-warning-color);
|
||||
border-color: var(--severity-warning-border-color);
|
||||
@@ -68,45 +61,24 @@ else
|
||||
[Parameter]
|
||||
public ToastModel? Toast { get; set; } = default!;
|
||||
|
||||
private bool isFadingOut = false;
|
||||
private float removalTime = 1300;
|
||||
private float fadeoutTime = 1200;
|
||||
|
||||
private string FadeoutStyle => isFadingOut ? "fadeout" : "";
|
||||
private float Opacity()
|
||||
{
|
||||
if (Toast!.Age < fadeoutTime)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
private int removalTime = 150000;
|
||||
private int fadeoutTime = 1000;
|
||||
return 1.0f - (Toast.Age - fadeoutTime) / (removalTime - fadeoutTime);
|
||||
}
|
||||
|
||||
private Timer removalTimer = null!;
|
||||
private Timer fadeoutTimer = null!;
|
||||
int elapsed = 0;
|
||||
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
#if DEBUG
|
||||
removalTime = 8000;
|
||||
#endif
|
||||
|
||||
removalTimer = new Timer(removalTime);
|
||||
removalTimer.Elapsed += OnRemoval!;
|
||||
removalTimer.Enabled = true;
|
||||
|
||||
fadeoutTimer = new Timer(removalTime - fadeoutTime);
|
||||
fadeoutTimer.Elapsed += OnFadeout!;
|
||||
fadeoutTimer.Enabled = true;
|
||||
|
||||
toastService.Subscribe(StateHasChanged);
|
||||
}
|
||||
|
||||
void OnFadeout(object source, ElapsedEventArgs eventArgs)
|
||||
{
|
||||
// isFadingOut = true;
|
||||
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
void OnRemoval(object source, ElapsedEventArgs eventArgs)
|
||||
{
|
||||
//toastService.RemoveToast(Toast!);
|
||||
|
||||
StateHasChanged();
|
||||
toastService.Subscribe(OnUpdate);
|
||||
}
|
||||
|
||||
void Dismiss()
|
||||
@@ -116,9 +88,15 @@ else
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
removalTimer.Elapsed -= OnRemoval!;
|
||||
fadeoutTimer.Elapsed -= OnFadeout!;
|
||||
toastService.Unsubscribe(OnUpdate);
|
||||
}
|
||||
|
||||
toastService.Unsubscribe(StateHasChanged);
|
||||
void OnUpdate()
|
||||
{
|
||||
if (Toast!.Age > removalTime)
|
||||
{
|
||||
toastService.RemoveToast(Toast);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,8 +5,9 @@
|
||||
@if (toastService.HasToasts())
|
||||
{
|
||||
<div class="toastsContainer">
|
||||
@foreach( var toast in toastService.GetToasts())
|
||||
@foreach(var toast in Toasts)
|
||||
{
|
||||
|
||||
<ToastComponent Toast="toast"/>
|
||||
}
|
||||
</div>
|
||||
@@ -19,15 +20,24 @@
|
||||
right: 64px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
gap: 5px;
|
||||
}
|
||||
</style>
|
||||
|
||||
|
||||
@code {
|
||||
private List<ToastModel> Toasts => toastService.GetToasts();
|
||||
|
||||
private Timer ageTimer = null!;
|
||||
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
toastService.Subscribe(OnUpdate);
|
||||
|
||||
ageTimer = new Timer(10);
|
||||
ageTimer.Elapsed += OnAge!;
|
||||
ageTimer.Enabled = true;
|
||||
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
@@ -35,6 +45,14 @@
|
||||
toastService.Unsubscribe(OnUpdate);
|
||||
}
|
||||
|
||||
|
||||
void OnAge(object? sender, ElapsedEventArgs elapsedEventArgs)
|
||||
{
|
||||
toastService.AgeToasts();
|
||||
ageTimer.Enabled = true;
|
||||
}
|
||||
|
||||
|
||||
void OnUpdate()
|
||||
{
|
||||
StateHasChanged();
|
||||
|
||||
@@ -6,11 +6,6 @@ using Services.Development;
|
||||
using Services.Immortal;
|
||||
using Services.Website;
|
||||
|
||||
#if NO_SQL
|
||||
#else
|
||||
using Contexts;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
#endif
|
||||
|
||||
CultureInfo.DefaultThreadCurrentCulture = new CultureInfo("en-US");
|
||||
CultureInfo.DefaultThreadCurrentUICulture = new CultureInfo("en-US");
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
@using IGP.Pages.RoadMap.Parts
|
||||
@using IGP.Pages.Notes
|
||||
@using IGP.Pages.Notes.Parts
|
||||
@using System.Timers
|
||||
@using IGP.Portals
|
||||
@using Markdig
|
||||
@using Model.Feedback
|
||||
|
||||
@@ -1,8 +1,16 @@
|
||||
namespace Model.Feedback;
|
||||
|
||||
using System.Timers;
|
||||
|
||||
namespace Model.Feedback;
|
||||
|
||||
public class ToastModel
|
||||
{
|
||||
public string Title { get; set; } = "addTitle";
|
||||
public string Message { get; set; } = "addMessage";
|
||||
public string SeverityType { get; set; } = "addType";
|
||||
|
||||
public float Age { get; set; } = 0;
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -21,6 +21,7 @@ using Services.Immortal;
|
||||
|
||||
namespace Services;
|
||||
|
||||
|
||||
public interface IToastService
|
||||
{
|
||||
public void Subscribe(Action action);
|
||||
@@ -29,6 +30,7 @@ public interface IToastService
|
||||
void RemoveToast(ToastModel toast);
|
||||
bool HasToasts();
|
||||
List<ToastModel> GetToasts();
|
||||
void AgeToasts();
|
||||
void ClearAllToasts();
|
||||
}
|
||||
|
||||
|
||||
@@ -41,7 +41,6 @@ public class ToastService : IToastService
|
||||
public void RemoveToast(ToastModel toast)
|
||||
{
|
||||
toasts.Remove(toast);
|
||||
NotifyDataChanged();
|
||||
}
|
||||
|
||||
public bool HasToasts()
|
||||
@@ -54,6 +53,16 @@ public class ToastService : IToastService
|
||||
return toasts;
|
||||
}
|
||||
|
||||
public void AgeToasts()
|
||||
{
|
||||
foreach (var toast in toasts)
|
||||
{
|
||||
toast.Age++;
|
||||
}
|
||||
|
||||
NotifyDataChanged();
|
||||
}
|
||||
|
||||
public void ClearAllToasts()
|
||||
{
|
||||
toasts.Clear();
|
||||
|
||||
Reference in New Issue
Block a user