diff --git a/StabilityMatrix/Helper/ISnackbarService.cs b/StabilityMatrix/Helper/ISnackbarService.cs index 0afd2c09..a9e3e1b4 100644 --- a/StabilityMatrix/Helper/ISnackbarService.cs +++ b/StabilityMatrix/Helper/ISnackbarService.cs @@ -1,6 +1,8 @@ using System.Threading.Tasks; using Microsoft.Extensions.Logging; using StabilityMatrix.Models; +using Wpf.Ui.Common; +using Wpf.Ui.Controls; namespace StabilityMatrix.Helper; @@ -9,24 +11,31 @@ public interface ISnackbarService /// /// Shows a generic error snackbar with the given message. /// - /// - /// Controls the appearance of the snackbar. - /// Error => Danger - /// Warning => Caution - /// Information => Info - /// Trace => Success - /// Other => Secondary - /// - Task ShowSnackbarAsync(string message, string title = "Error", LogLevel level = LogLevel.Error, int timeoutMilliseconds = 5000); + public Task ShowSnackbarAsync( + string message, + string title = "Error", + ControlAppearance appearance = ControlAppearance.Danger, + SymbolRegular icon = SymbolRegular.ErrorCircle24, + int timeoutMilliseconds = 5000); /// /// Attempt to run the given task, showing a generic error snackbar if it fails. /// - Task> TryAsync(Task task, string message, LogLevel level = LogLevel.Error, int timeoutMilliseconds = 5000); + public Task> TryAsync( + Task task, + string message, + ControlAppearance appearance = ControlAppearance.Danger, + SymbolRegular icon = SymbolRegular.ErrorCircle24, + int timeoutMilliseconds = 5000); /// /// Attempt to run the given void task, showing a generic error snackbar if it fails. /// Return a TaskResult with true if the task succeeded, false if it failed. /// - Task> TryAsync(Task task, string message, LogLevel level = LogLevel.Error, int timeoutMilliseconds = 5000); + Task> TryAsync( + Task task, + string message, + ControlAppearance appearance = ControlAppearance.Danger, + SymbolRegular icon = SymbolRegular.ErrorCircle24, + int timeoutMilliseconds = 5000); } diff --git a/StabilityMatrix/Helper/SnackbarService.cs b/StabilityMatrix/Helper/SnackbarService.cs index 7f497b2b..9647a32f 100644 --- a/StabilityMatrix/Helper/SnackbarService.cs +++ b/StabilityMatrix/Helper/SnackbarService.cs @@ -23,37 +23,26 @@ public class SnackbarService : ISnackbarService this.snackbarService = snackbarService; this.snackbarViewModel = snackbarViewModel; } - - /// - /// Shows a generic error snackbar with the given message. - /// - /// - /// Controls the appearance of the snackbar. - /// Error => Danger - /// Warning => Caution - /// Information => Info - /// Trace => Success - /// Other => Secondary - /// - public async Task ShowSnackbarAsync(string message, string title = "Error", LogLevel level = LogLevel.Error, int timeoutMilliseconds = 5000) + + /// + public async Task ShowSnackbarAsync( + string message, + string title = "Error", + ControlAppearance appearance = ControlAppearance.Danger, + SymbolRegular icon = SymbolRegular.ErrorCircle24, + int timeoutMilliseconds = 5000) { - snackbarViewModel.SnackbarAppearance = level switch - { - LogLevel.Error => ControlAppearance.Danger, - LogLevel.Warning => ControlAppearance.Caution, - LogLevel.Information => ControlAppearance.Info, - LogLevel.Trace => ControlAppearance.Success, - _ => ControlAppearance.Secondary - }; snackbarService.Timeout = timeoutMilliseconds; - var icon = new SymbolIcon(SymbolRegular.ErrorCircle24); - await snackbarService.ShowAsync(title, message, icon, snackbarViewModel.SnackbarAppearance); + await snackbarService.ShowAsync(title, message, new SymbolIcon(icon), appearance); } - /// - /// Attempt to run the given task, showing a generic error snackbar if it fails. - /// - public async Task> TryAsync(Task task, string message, LogLevel level = LogLevel.Error, int timeoutMilliseconds = 5000) + /// + public async Task> TryAsync( + Task task, + string message, + ControlAppearance appearance = ControlAppearance.Danger, + SymbolRegular icon = SymbolRegular.ErrorCircle24, + int timeoutMilliseconds = 5000) { try { @@ -72,11 +61,13 @@ public class SnackbarService : ISnackbarService } } - /// - /// Attempt to run the given void task, showing a generic error snackbar if it fails. - /// Return a TaskResult with true if the task succeeded, false if it failed. - /// - public async Task> TryAsync(Task task, string message, LogLevel level = LogLevel.Error, int timeoutMilliseconds = 5000) + /// + public async Task> TryAsync( + Task task, + string message, + ControlAppearance appearance = ControlAppearance.Danger, + SymbolRegular icon = SymbolRegular.ErrorCircle24, + int timeoutMilliseconds = 5000) { try {