Added IMessageDisplay Interface, added implementation to ToastComponent
This commit is contained in:
parent
3bd17a4cb5
commit
33e8d490ac
|
@ -2,6 +2,7 @@
|
||||||
@using Microsoft.AspNetCore.Identity
|
@using Microsoft.AspNetCore.Identity
|
||||||
@using Wave.Data
|
@using Wave.Data
|
||||||
@using Humanizer
|
@using Humanizer
|
||||||
|
@using Wave.Utilities
|
||||||
|
|
||||||
@rendermode InteractiveServer
|
@rendermode InteractiveServer
|
||||||
@attribute [Authorize(Policy = "RoleAssignPermissions")]
|
@attribute [Authorize(Policy = "RoleAssignPermissions")]
|
||||||
|
@ -59,7 +60,7 @@
|
||||||
@code {
|
@code {
|
||||||
[CascadingParameter(Name = "TitlePrefix")]
|
[CascadingParameter(Name = "TitlePrefix")]
|
||||||
private string TitlePrefix { get; set; } = default!;
|
private string TitlePrefix { get; set; } = default!;
|
||||||
public ToastComponent Toast { get; set; } = null!;
|
public IMessageDisplay Toast { get; set; } = null!;
|
||||||
private string ModalId { get; } = "UserDialog";
|
private string ModalId { get; } = "UserDialog";
|
||||||
|
|
||||||
[CascadingParameter]
|
[CascadingParameter]
|
||||||
|
|
|
@ -1,4 +1,7 @@
|
||||||
<div class="toast toast-start z-10" role="alert">
|
@using Wave.Utilities
|
||||||
|
@implements IMessageDisplay
|
||||||
|
|
||||||
|
<div class="toast toast-start z-10" role="alert">
|
||||||
@foreach (var message in Messages) {
|
@foreach (var message in Messages) {
|
||||||
<div class="alert @message.Type" @onclick="() => Messages.Remove(message)">
|
<div class="alert @message.Type" @onclick="() => Messages.Remove(message)">
|
||||||
@if (message.Title is null) {
|
@if (message.Title is null) {
|
||||||
|
@ -12,24 +15,10 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@code {
|
@code {
|
||||||
private List<Message> Messages { get; } = [];
|
private List<IMessageDisplay.Message> Messages { get; } = [];
|
||||||
|
|
||||||
public void ShowInfo(string message, string? title = null) {
|
public void ShowMessage(IMessageDisplay.Message message) {
|
||||||
Messages.Add(new Message(message, "alert-info", title, DateTimeOffset.UtcNow));
|
Messages.Add(message);
|
||||||
StateHasChanged();
|
StateHasChanged();
|
||||||
}
|
}
|
||||||
public void ShowSuccess(string message, string? title = null) {
|
|
||||||
Messages.Add(new Message(message, "alert-success", title, DateTimeOffset.UtcNow));
|
|
||||||
StateHasChanged();
|
|
||||||
}
|
|
||||||
public void ShowWarning(string message, string? title = null) {
|
|
||||||
Messages.Add(new Message(message, "alert-warning", title, DateTimeOffset.UtcNow));
|
|
||||||
StateHasChanged();
|
|
||||||
}
|
|
||||||
public void ShowError(string message, string? title = null) {
|
|
||||||
Messages.Add(new Message(message, "alert-error", title, DateTimeOffset.UtcNow));
|
|
||||||
StateHasChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
private sealed record Message(string Body, string Type, string? Title, DateTimeOffset Created);
|
|
||||||
}
|
}
|
||||||
|
|
16
Wave/Utilities/IMessageDisplay.cs
Normal file
16
Wave/Utilities/IMessageDisplay.cs
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
namespace Wave.Utilities;
|
||||||
|
|
||||||
|
public interface IMessageDisplay {
|
||||||
|
public void ShowMessage(Message message);
|
||||||
|
|
||||||
|
public void ShowInfo(string message, string? title = null)
|
||||||
|
=> ShowMessage(new Message(message, "alert-info", title, DateTimeOffset.UtcNow));
|
||||||
|
public void ShowSuccess(string message, string? title = null)
|
||||||
|
=> ShowMessage(new Message(message, "alert-success", title, DateTimeOffset.UtcNow));
|
||||||
|
public void ShowWarning(string message, string? title = null)
|
||||||
|
=> ShowMessage(new Message(message, "alert-warning", title, DateTimeOffset.UtcNow));
|
||||||
|
public void ShowError(string message, string? title = null)
|
||||||
|
=> ShowMessage(new Message(message, "alert-error", title, DateTimeOffset.UtcNow));
|
||||||
|
|
||||||
|
public sealed record Message(string Body, string Type, string? Title, DateTimeOffset Created);
|
||||||
|
}
|
Loading…
Reference in a new issue