Replace status bar with global notifications
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
parent
910d1ebc35
commit
7893777ab3
27 changed files with 297 additions and 64 deletions
|
|
@ -2,10 +2,12 @@
|
|||
# Changelog
|
||||
|
||||
|
||||
## [1.0.8-rc38] - unstable
|
||||
## [1.0.8-rc37] - unstable
|
||||
|
||||
### Added
|
||||
|
||||
* [PostIt] Replace the persistent status bar with a global notification service using ephemeral toasts for info/success and dismissible modal alerts for warnings/errors.
|
||||
|
||||
* [PostIt/Administration] Rechercher les utilisateurs côté serveur par login ou nom, par pages de 25 résultats maximum avec navigation précédente/suivante.
|
||||
|
||||
* [PostIt] Telemetry
|
||||
|
|
|
|||
|
|
@ -55,6 +55,7 @@ public static class ServiceCollectionHelpers
|
|||
services.AddSingleton<ChatViewModel>();
|
||||
services.AddSingleton<ChatHubConnection>();
|
||||
services.AddSingleton<MessagingSession>();
|
||||
services.AddSingleton(NotificationService.Instance);
|
||||
|
||||
// Android activities need fresh controls; retain state in singleton VMs.
|
||||
void AddReusablePage<TPage>() where TPage : class
|
||||
|
|
|
|||
25
src/PostIt/PostIt/Services/NotificationService.cs
Normal file
25
src/PostIt/PostIt/Services/NotificationService.cs
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
using System;
|
||||
using PostIt.Models;
|
||||
|
||||
namespace PostIt.Services;
|
||||
|
||||
public sealed class NotificationService
|
||||
{
|
||||
public static NotificationService Instance { get; } = new();
|
||||
|
||||
public event EventHandler<NotificationRequest>? NotificationRequested;
|
||||
|
||||
private NotificationService()
|
||||
{
|
||||
}
|
||||
|
||||
public void Show(string message, StatusSeverity severity = StatusSeverity.Info, string? actionLabel = null, Action? action = null)
|
||||
=> NotificationRequested?.Invoke(this, new NotificationRequest(message, severity, actionLabel, action));
|
||||
|
||||
public void Hide()
|
||||
{
|
||||
NotificationRequested?.Invoke(this, new NotificationRequest(string.Empty, StatusSeverity.Info));
|
||||
}
|
||||
}
|
||||
|
||||
public sealed record NotificationRequest(string Message, StatusSeverity Severity, string? ActionLabel = null, Action? Action = null);
|
||||
|
|
@ -1,4 +1,6 @@
|
|||
using Microsoft.Extensions.DependencyInjection;
|
||||
using PostIt.Models;
|
||||
using PostIt.Services;
|
||||
|
||||
namespace PostIt.ViewModels;
|
||||
|
||||
|
|
@ -22,13 +24,22 @@ public static class ActionStatusViewModelExtensions
|
|||
public static void SetStatus(this IActionStatusViewModel viewModel, string message, StatusSeverity severity)
|
||||
{
|
||||
var normalizedMessage = string.IsNullOrWhiteSpace(message) ? "Pret." : message.Trim();
|
||||
|
||||
viewModel.StatusMessage = normalizedMessage;
|
||||
viewModel.ActionStatus = severity switch
|
||||
var statusNotice = severity switch
|
||||
{
|
||||
StatusSeverity.Error => StatusNotice.Error(normalizedMessage),
|
||||
StatusSeverity.Warning => StatusNotice.Warning(normalizedMessage),
|
||||
_ => StatusNotice.Info(normalizedMessage),
|
||||
};
|
||||
|
||||
viewModel.StatusMessage = normalizedMessage;
|
||||
viewModel.ActionStatus = statusNotice;
|
||||
|
||||
if (App.Current is App app && app.ServiceProvider is { } serviceProvider)
|
||||
{
|
||||
var settings = serviceProvider.GetRequiredService<Settings>();
|
||||
settings.SetActionStatus(normalizedMessage, severity);
|
||||
var notificationService = serviceProvider.GetRequiredService<NotificationService>();
|
||||
notificationService.Show(normalizedMessage, severity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,6 +9,8 @@ using System.Net.Http;
|
|||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Globalization;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using PostIt.Models;
|
||||
using PostIt.Services;
|
||||
|
||||
|
|
|
|||
|
|
@ -11,11 +11,10 @@ public sealed class StatusNotice
|
|||
public string Background { get; }
|
||||
public string BorderBrush { get; }
|
||||
public string Foreground { get; }
|
||||
|
||||
public bool HasCheckCommand { get => CheckCommand != null; }
|
||||
|
||||
public bool HasCheckCommand => CheckCommand is not null;
|
||||
public bool IsTransient => Severity == StatusSeverity.Info && CheckCommand is null;
|
||||
public bool IsModal => !IsTransient;
|
||||
public ICommand? CheckCommand { get; }
|
||||
|
||||
public string CheckCommandLabel { get; }
|
||||
|
||||
public StatusNotice(string message, StatusSeverity severity, ICommand? checkCommand)
|
||||
|
|
@ -27,7 +26,7 @@ public sealed class StatusNotice
|
|||
{
|
||||
StatusSeverity.Error => ("!", "#7F1D1D", "#C62828", "#e1f0f6"),
|
||||
StatusSeverity.Warning => ("~", "#7C4A03", "#E6A700", "#eaeaea"),
|
||||
_ => ("i", "#E8F0FE", "#5B8DEF", "#1E3A8A"),
|
||||
_ => ("✓", "#E8F0FE", "#5B8DEF", "#1E3A8A"),
|
||||
};
|
||||
CheckCommand = checkCommand;
|
||||
CheckCommandLabel = HasCheckCommand ?
|
||||
|
|
|
|||
|
|
@ -48,8 +48,7 @@
|
|||
|
||||
<!-- Action buttons -->
|
||||
<Grid Grid.Row="3" ColumnDefinitions="*,Auto,Auto" Margin="0,8,0,0">
|
||||
<postitControls:StatusBar Grid.Column="0"
|
||||
DataContext="{Binding ActionStatus}" />
|
||||
|
||||
<Button Grid.Column="1" Content="Ajouter"
|
||||
x:Name="AddButton"
|
||||
Command="{Binding AddAsync}"
|
||||
|
|
|
|||
|
|
@ -102,8 +102,7 @@
|
|||
|
||||
<!-- Status bar -->
|
||||
<Grid Grid.Row="2" ColumnDefinitions="*,Auto" Margin="12,0,12,12">
|
||||
<postitControls:StatusBar Grid.Column="0"
|
||||
DataContext="{Binding ActionStatus}" />
|
||||
|
||||
<ProgressBar Grid.Column="1" IsIndeterminate="True"
|
||||
IsVisible="{Binding IsBusy}"
|
||||
Width="120"/>
|
||||
|
|
|
|||
|
|
@ -54,8 +54,7 @@
|
|||
|
||||
<!-- Status bar -->
|
||||
<Grid Grid.Row="3" ColumnDefinitions="*,Auto">
|
||||
<postitControls:StatusBar Grid.Column="0"
|
||||
DataContext="{Binding ActionStatus}" />
|
||||
|
||||
<ProgressBar Grid.Column="1" IsIndeterminate="True"
|
||||
IsVisible="{Binding IsBusy}"
|
||||
Width="120"/>
|
||||
|
|
|
|||
|
|
@ -132,8 +132,7 @@
|
|||
</Grid>
|
||||
|
||||
<Grid Grid.Row="2" ColumnDefinitions="*,Auto">
|
||||
<postitControls:StatusBar Grid.Column="0"
|
||||
DataContext="{Binding ActionStatus}" />
|
||||
|
||||
<ProgressBar Grid.Column="1" Width="120" IsIndeterminate="True" IsVisible="{Binding IsBusy}" />
|
||||
</Grid>
|
||||
</Grid>
|
||||
|
|
|
|||
|
|
@ -82,8 +82,7 @@
|
|||
</ListBox>
|
||||
|
||||
<Grid Grid.Row="4" ColumnDefinitions="*,Auto" Margin="0,12,0,0">
|
||||
<postitControls:StatusBar Grid.Column="0"
|
||||
DataContext="{Binding ActionStatus}" />
|
||||
|
||||
<ProgressBar Grid.Column="1" Width="120" IsIndeterminate="True" IsVisible="{Binding IsBusy}" />
|
||||
</Grid>
|
||||
</Grid>
|
||||
|
|
|
|||
|
|
@ -174,8 +174,7 @@
|
|||
</ScrollViewer>
|
||||
|
||||
<Grid Grid.Row="3" ColumnDefinitions="*,Auto" Margin="0,8,0,0">
|
||||
<postitControls:StatusBar Grid.Column="0"
|
||||
DataContext="{Binding ActionStatus}" />
|
||||
|
||||
<ProgressBar Grid.Column="1"
|
||||
Width="120"
|
||||
IsIndeterminate="True"
|
||||
|
|
|
|||
|
|
@ -42,8 +42,7 @@
|
|||
<Button Grid.Column="4"
|
||||
Content="Demandes en cours (validées, en lecture seule)"
|
||||
Command="{Binding OpenOngoingQueriesCommand}" />
|
||||
<postitControls:StatusBar Grid.Column="6"
|
||||
DataContext="{Binding ActionStatus}" />
|
||||
|
||||
</Grid>
|
||||
</Grid>
|
||||
</ContentPage>
|
||||
|
|
|
|||
|
|
@ -187,8 +187,7 @@
|
|||
<Button Grid.Column="0"
|
||||
Content="{Binding SendLabel}"
|
||||
Command="{Binding SendCommand}" />
|
||||
<postitControls:StatusBar Grid.Column="2"
|
||||
DataContext="{Binding ActionStatus}" />
|
||||
|
||||
<ProgressBar Grid.Column="3"
|
||||
Width="120"
|
||||
IsIndeterminate="True"
|
||||
|
|
|
|||
|
|
@ -69,8 +69,7 @@
|
|||
</ListBox>
|
||||
|
||||
<Grid Grid.Row="3" ColumnDefinitions="*,Auto" Margin="0,12,0,0">
|
||||
<postitControls:StatusBar Grid.Column="0"
|
||||
DataContext="{Binding ActionStatus}" />
|
||||
|
||||
<ProgressBar Grid.Column="1" Width="120" IsIndeterminate="True" IsVisible="{Binding IsBusy}" />
|
||||
</Grid>
|
||||
</Grid>
|
||||
|
|
|
|||
|
|
@ -139,7 +139,7 @@
|
|||
<ProgressBar Width="120"
|
||||
IsIndeterminate="True"
|
||||
IsVisible="{Binding IsBusy}" />
|
||||
<postitControls:StatusBar DataContext="{Binding ActionStatus}" />
|
||||
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Grid>
|
||||
|
|
|
|||
|
|
@ -97,8 +97,7 @@
|
|||
</Grid>
|
||||
|
||||
<Grid Grid.Row="4" ColumnDefinitions="*,Auto" Margin="0,12,0,0">
|
||||
<postitControls:StatusBar Grid.Column="0"
|
||||
DataContext="{Binding ActionStatus}" />
|
||||
|
||||
<ProgressBar Grid.Column="1" Width="120" IsIndeterminate="True" IsVisible="{Binding IsBusy}" />
|
||||
</Grid>
|
||||
</Grid>
|
||||
|
|
|
|||
|
|
@ -321,9 +321,6 @@
|
|||
Text="Choisissez un billet dans la liste pour le lire."
|
||||
TextWrapping="Wrap" />
|
||||
</Grid>
|
||||
<postitControls:StatusBar
|
||||
x:Name="StatusBar"
|
||||
Grid.Row="5"
|
||||
DataContext="{Binding ActionStatus}" />
|
||||
|
||||
</Grid>
|
||||
</ContentPage>
|
||||
|
|
|
|||
|
|
@ -70,8 +70,6 @@ public partial class BlogsPage : ContentPage
|
|||
PostEditor.Margin = new Thickness(compact ? 4 : 12);
|
||||
PostEditor.RowSpacing = compact ? 2 : 10;
|
||||
}
|
||||
SetArea(StatusBar, sideBySide ? 1 : isWide ? 3 : 5, sideBySide ? 2 : 0,
|
||||
columnSpan: isWide && !sideBySide ? 3 : 1);
|
||||
if (_isWideLayout == isWide)
|
||||
return;
|
||||
_isWideLayout = isWide;
|
||||
|
|
|
|||
|
|
@ -107,10 +107,7 @@
|
|||
IsVisible="{Binding LanCall.Incoming}" />
|
||||
</StackPanel>
|
||||
|
||||
<postitControls:StatusBar
|
||||
x:Name="StatusBar"
|
||||
Grid.Row="4"
|
||||
DataContext="{Binding Status}" />
|
||||
|
||||
|
||||
</Grid>
|
||||
</ContentPage>
|
||||
|
|
|
|||
|
|
@ -94,8 +94,7 @@
|
|||
Content="{Binding SubmitLabel}"
|
||||
Command="{Binding SubmitCommand}"
|
||||
IsEnabled="{Binding IsSupported}" />
|
||||
<postitControls:StatusBar Grid.Column="2"
|
||||
DataContext="{Binding ActionStatus}" />
|
||||
|
||||
<ProgressBar Grid.Column="3"
|
||||
Width="120"
|
||||
IsIndeterminate="True"
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
x:Class="PostIt.Views.Commands.RdvPage"
|
||||
x:DataType="cvm:RdvViewModel"
|
||||
Header="Commande billing">
|
||||
<ScrollViewer>
|
||||
|
||||
<Grid RowDefinitions="Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto" ColumnDefinitions="Auto,*" Margin="12">
|
||||
<TextBlock Grid.Row="0" Grid.ColumnSpan="2"
|
||||
Text="{Binding Title}"
|
||||
|
|
@ -113,13 +113,11 @@
|
|||
Content="{Binding SubmitLabel}"
|
||||
Command="{Binding SubmitCommand}"
|
||||
IsEnabled="{Binding IsSupported}" />
|
||||
<postitControls:StatusBar Grid.Column="2"
|
||||
DataContext="{Binding ActionStatus}" />
|
||||
|
||||
<ProgressBar Grid.Column="3"
|
||||
Width="120"
|
||||
IsIndeterminate="True"
|
||||
IsVisible="{Binding IsBusy}" />
|
||||
</Grid>
|
||||
</Grid>
|
||||
</ScrollViewer>
|
||||
</ContentPage>
|
||||
|
|
|
|||
|
|
@ -14,6 +14,68 @@
|
|||
|
||||
<Grid>
|
||||
<NavigationPage x:Name="NavRoot"/>
|
||||
|
||||
<Border x:Name="NotificationToast"
|
||||
IsVisible="False"
|
||||
HorizontalAlignment="Right"
|
||||
VerticalAlignment="Top"
|
||||
Margin="16"
|
||||
CornerRadius="10"
|
||||
Padding="12"
|
||||
BorderThickness="1"
|
||||
BorderBrush="#5B8DEF"
|
||||
Background="#E8F0FE"
|
||||
BoxShadow="0 6 16 0 #26000000"
|
||||
PointerPressed="NotificationToast_PointerPressed">
|
||||
<Grid ColumnDefinitions="Auto,*" ColumnSpacing="10">
|
||||
<TextBlock x:Name="NotificationToastGlyph"
|
||||
VerticalAlignment="Center"
|
||||
FontSize="18"
|
||||
FontWeight="Bold"
|
||||
Foreground="#1E3A8A"
|
||||
Text="✓"/>
|
||||
<TextBlock x:Name="NotificationToastMessage"
|
||||
Grid.Column="1"
|
||||
MaxWidth="420"
|
||||
TextWrapping="Wrap"
|
||||
VerticalAlignment="Center"
|
||||
Foreground="#1E3A8A"
|
||||
Text=""/>
|
||||
</Grid>
|
||||
</Border>
|
||||
|
||||
<Border x:Name="NotificationModal"
|
||||
IsVisible="False"
|
||||
Background="#80000000"
|
||||
Padding="12"
|
||||
KeyboardNavigation.TabNavigation="Cycle">
|
||||
<Border MaxWidth="420"
|
||||
HorizontalAlignment="Stretch"
|
||||
VerticalAlignment="Center"
|
||||
Padding="20"
|
||||
CornerRadius="8"
|
||||
Background="{DynamicResource SystemControlBackgroundAltHighBrush}">
|
||||
<StackPanel Spacing="12">
|
||||
<TextBlock x:Name="NotificationModalTitle"
|
||||
FontSize="22"
|
||||
FontWeight="SemiBold"
|
||||
TextWrapping="Wrap"
|
||||
Text="Notification"/>
|
||||
<TextBlock x:Name="NotificationModalMessage"
|
||||
TextWrapping="Wrap"
|
||||
Text=""/>
|
||||
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Spacing="8">
|
||||
<Button x:Name="NotificationModalCloseButton"
|
||||
Content="Fermer"
|
||||
Click="NotificationModalCloseButton_Click"/>
|
||||
<Button x:Name="NotificationModalActionButton"
|
||||
IsVisible="False"
|
||||
Click="NotificationModalActionButton_Click"/>
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
</Border>
|
||||
</Border>
|
||||
|
||||
<Border x:Name="AuthenticationModal"
|
||||
IsVisible="{Binding SessionStatus.IsAuthenticationRequired, FallbackValue=False}"
|
||||
Background="#80000000"
|
||||
|
|
|
|||
|
|
@ -1,9 +1,15 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.Platform;
|
||||
using Avalonia.Input;
|
||||
using Avalonia.Interactivity;
|
||||
using Avalonia.Media;
|
||||
using Avalonia.Threading;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using PostIt.Models;
|
||||
using PostIt.Services;
|
||||
|
||||
namespace PostIt.Views;
|
||||
|
||||
|
|
@ -14,11 +20,15 @@ public partial class MainView : UserControl
|
|||
private Thickness _safeArea;
|
||||
private Rect? _keyboardRect;
|
||||
private IInputElement? _previousFocus;
|
||||
private bool _toastIsVisible;
|
||||
private readonly NotificationService _notificationService = NotificationService.Instance;
|
||||
internal bool IsSoftKeyboardOpen { get; private set; }
|
||||
|
||||
public MainView()
|
||||
{
|
||||
InitializeComponent();
|
||||
_notificationService.NotificationRequested += OnNotificationRequested;
|
||||
|
||||
AuthenticationModal.PropertyChanged += (_, e) =>
|
||||
{
|
||||
if (e.Property != IsVisibleProperty) return;
|
||||
|
|
@ -40,46 +50,74 @@ public partial class MainView : UserControl
|
|||
}, DispatcherPriority.Input);
|
||||
}
|
||||
};
|
||||
|
||||
LoginButton.PropertyChanged += (_, e) =>
|
||||
{
|
||||
if (e.Property == IsEnabledProperty && LoginButton.IsEnabled && AuthenticationModal.IsVisible)
|
||||
Dispatcher.UIThread.Post(FocusAuthentication, DispatcherPriority.Input);
|
||||
};
|
||||
Loaded += (_, _) =>
|
||||
{
|
||||
Dispatcher.UIThread.Post(FocusAuthentication, DispatcherPriority.Input);
|
||||
};
|
||||
|
||||
Loaded += (_, _) => Dispatcher.UIThread.Post(FocusAuthentication, DispatcherPriority.Input);
|
||||
|
||||
NotificationModalCloseButton.Click += (_, _) => HideNotificationModal();
|
||||
NotificationModalActionButton.Click += (_, _) => HideNotificationModal(executeAction: true);
|
||||
|
||||
NavRoot.IsEnabled = !AuthenticationModal.IsVisible;
|
||||
TopLevel.SetAutoSafeAreaPadding(this, false);
|
||||
|
||||
AttachedToVisualTree += (_, _) =>
|
||||
{
|
||||
var topLevel = TopLevel.GetTopLevel(this);
|
||||
_inputPane = topLevel?.InputPane;
|
||||
_insetsManager = topLevel?.InsetsManager;
|
||||
|
||||
if (_insetsManager is not null)
|
||||
{
|
||||
_insetsManager.SafeAreaChanged += SafeAreaChanged;
|
||||
_safeArea = _insetsManager.SafeAreaPadding;
|
||||
}
|
||||
|
||||
if (_inputPane is not null)
|
||||
{
|
||||
_inputPane.StateChanged += InputPaneStateChanged;
|
||||
ApplyKeyboardOcclusion(_inputPane.State == InputPaneState.Open ? _inputPane.OccludedRect : null);
|
||||
}
|
||||
|
||||
ApplyKeyboardOcclusion(_keyboardRect);
|
||||
};
|
||||
|
||||
DetachedFromVisualTree += (_, _) =>
|
||||
{
|
||||
if (_inputPane is not null)
|
||||
_inputPane.StateChanged -= InputPaneStateChanged;
|
||||
_inputPane = null;
|
||||
|
||||
if (_insetsManager is not null)
|
||||
_insetsManager.SafeAreaChanged -= SafeAreaChanged;
|
||||
_insetsManager = null;
|
||||
};
|
||||
|
||||
SizeChanged += (_, _) => ApplyKeyboardOcclusion(_keyboardRect);
|
||||
}
|
||||
|
||||
private void OnNotificationRequested(object? sender, NotificationRequest request)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(request.Message))
|
||||
{
|
||||
HideToast();
|
||||
HideNotificationModal();
|
||||
return;
|
||||
}
|
||||
|
||||
if (request.Severity is StatusSeverity.Warning or StatusSeverity.Error)
|
||||
{
|
||||
ShowNotificationModal(request.Message, request.Severity, request.ActionLabel, request.Action);
|
||||
return;
|
||||
}
|
||||
|
||||
ShowToast(request.Message, request.Severity, request.ActionLabel, request.Action);
|
||||
}
|
||||
|
||||
private void FocusAuthentication()
|
||||
{
|
||||
if (AuthenticationModal.IsVisible)
|
||||
|
|
@ -104,10 +142,10 @@ public partial class MainView : UserControl
|
|||
IsSoftKeyboardOpen = keyboardRect is { Height: > 0 };
|
||||
var topLevel = TopLevel.GetTopLevel(this);
|
||||
var bottom = topLevel is null ? null : this.TranslatePoint(new Point(0, Bounds.Height), topLevel);
|
||||
// Subtract only actual overlap: AdjustResize may already have removed the keyboard area.
|
||||
var overlap = keyboardRect is { Height: > 0 } rect && bottom is { } point
|
||||
? Math.Clamp(point.Y - rect.Top, 0, Bounds.Height)
|
||||
: 0;
|
||||
|
||||
Padding = new Thickness(_safeArea.Left, _safeArea.Top, _safeArea.Right,
|
||||
Math.Max(_safeArea.Bottom, overlap));
|
||||
}
|
||||
|
|
@ -115,12 +153,132 @@ public partial class MainView : UserControl
|
|||
protected override void OnDataContextChanged(EventArgs e)
|
||||
{
|
||||
base.OnDataContextChanged(e);
|
||||
if (DataContext is ViewModels.BlogsViewModel vm)
|
||||
|
||||
if (DataContext is ViewModels.BlogsViewModel vm && !vm.IsLoaded)
|
||||
vm.RefreshAsync().Wait();
|
||||
}
|
||||
|
||||
private void NotificationToast_PointerPressed(object? sender, PointerPressedEventArgs e)
|
||||
=> HideToast();
|
||||
|
||||
private void NotificationModalCloseButton_Click(object? sender, RoutedEventArgs e)
|
||||
=> HideNotificationModal();
|
||||
|
||||
private void NotificationModalActionButton_Click(object? sender, RoutedEventArgs e)
|
||||
=> HideNotificationModal(executeAction: true);
|
||||
|
||||
internal void ShowToast(string message, StatusSeverity severity = StatusSeverity.Info, string? actionLabel = null, Action? action = null)
|
||||
{
|
||||
var glyph = severity switch
|
||||
{
|
||||
if (!vm.IsLoaded)
|
||||
{
|
||||
vm.RefreshAsync().Wait();
|
||||
}
|
||||
StatusSeverity.Error => "!",
|
||||
StatusSeverity.Warning => "~",
|
||||
_ => "✓"
|
||||
};
|
||||
|
||||
var background = severity switch
|
||||
{
|
||||
StatusSeverity.Error => Color.Parse("#7F1D1D"),
|
||||
StatusSeverity.Warning => Color.Parse("#7C4A03"),
|
||||
_ => Color.Parse("#E8F0FE")
|
||||
};
|
||||
|
||||
var borderBrush = severity switch
|
||||
{
|
||||
StatusSeverity.Error => Color.Parse("#C62828"),
|
||||
StatusSeverity.Warning => Color.Parse("#E6A700"),
|
||||
_ => Color.Parse("#5B8DEF")
|
||||
};
|
||||
|
||||
var foreground = severity switch
|
||||
{
|
||||
StatusSeverity.Error => Color.Parse("#E1F0F6"),
|
||||
StatusSeverity.Warning => Color.Parse("#EAEAEA"),
|
||||
_ => Color.Parse("#1E3A8A")
|
||||
};
|
||||
|
||||
NotificationToastGlyph.Text = glyph;
|
||||
NotificationToastGlyph.Foreground = new SolidColorBrush(foreground);
|
||||
NotificationToastMessage.Text = message;
|
||||
NotificationToastMessage.Foreground = new SolidColorBrush(foreground);
|
||||
NotificationToast.Background = new SolidColorBrush(background);
|
||||
NotificationToast.BorderBrush = new SolidColorBrush(borderBrush);
|
||||
NotificationToast.IsVisible = true;
|
||||
_toastIsVisible = true;
|
||||
|
||||
if (action is not null && !string.IsNullOrWhiteSpace(actionLabel))
|
||||
{
|
||||
NotificationModalActionButton.Content = actionLabel;
|
||||
NotificationModalActionButton.IsVisible = true;
|
||||
NotificationModalActionButton.Tag = action;
|
||||
}
|
||||
else
|
||||
{
|
||||
NotificationModalActionButton.Content = string.Empty;
|
||||
NotificationModalActionButton.IsVisible = false;
|
||||
NotificationModalActionButton.Tag = null;
|
||||
}
|
||||
|
||||
if (severity is StatusSeverity.Warning or StatusSeverity.Error)
|
||||
{
|
||||
ShowNotificationModal(message, severity, actionLabel, action);
|
||||
return;
|
||||
}
|
||||
|
||||
Dispatcher.UIThread.Post(async () =>
|
||||
{
|
||||
await Task.Delay(2800);
|
||||
if (_toastIsVisible)
|
||||
HideToast();
|
||||
});
|
||||
}
|
||||
|
||||
internal void HideToast()
|
||||
{
|
||||
_toastIsVisible = false;
|
||||
NotificationToast.IsVisible = false;
|
||||
}
|
||||
|
||||
internal void ShowNotificationModal(string message, StatusSeverity severity, string? actionLabel = null, Action? action = null)
|
||||
{
|
||||
var title = severity switch
|
||||
{
|
||||
StatusSeverity.Error => "Erreur",
|
||||
StatusSeverity.Warning => "Attention",
|
||||
_ => "Information"
|
||||
};
|
||||
|
||||
NotificationModalTitle.Text = title;
|
||||
NotificationModalMessage.Text = message;
|
||||
|
||||
if (action is not null && !string.IsNullOrWhiteSpace(actionLabel))
|
||||
{
|
||||
NotificationModalActionButton.Content = actionLabel;
|
||||
NotificationModalActionButton.IsVisible = true;
|
||||
NotificationModalActionButton.Tag = action;
|
||||
}
|
||||
else
|
||||
{
|
||||
NotificationModalActionButton.Content = string.Empty;
|
||||
NotificationModalActionButton.IsVisible = false;
|
||||
NotificationModalActionButton.Tag = null;
|
||||
}
|
||||
|
||||
NotificationModal.IsVisible = true;
|
||||
HideToast();
|
||||
}
|
||||
|
||||
internal void HideNotificationModal(bool executeAction = false)
|
||||
{
|
||||
NotificationModal.IsVisible = false;
|
||||
if (executeAction && NotificationModalActionButton.Tag is Action action)
|
||||
{
|
||||
NotificationModalActionButton.Tag = null;
|
||||
action();
|
||||
}
|
||||
else
|
||||
{
|
||||
NotificationModalActionButton.Tag = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -64,8 +64,6 @@
|
|||
Opacity="0.8"
|
||||
TextWrapping="Wrap" />
|
||||
|
||||
<postitControls:StatusBar DataContext="{Binding ActionStatus}"/>
|
||||
|
||||
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
|
||||
<Button x:Name="ChooseAvatarButton"
|
||||
Content="Choisir l'avatar"
|
||||
|
|
|
|||
|
|
@ -79,8 +79,7 @@
|
|||
</ScrollViewer>
|
||||
|
||||
<Grid Grid.Row="3" ColumnDefinitions="Auto,8,*,Auto" Margin="0,12,0,0">
|
||||
<postitControls:StatusBar Grid.Column="0"
|
||||
DataContext="{Binding ActionStatus}" />
|
||||
|
||||
<ProgressBar Grid.Column="3"
|
||||
Width="120"
|
||||
IsIndeterminate="True"
|
||||
|
|
|
|||
|
|
@ -46,10 +46,7 @@
|
|||
<Button Content="Capturer" Command="{Binding CaptureAsync}" />
|
||||
</StackPanel>
|
||||
|
||||
<postitControls:StatusBar Grid.Row="3"
|
||||
DataContext="{Binding ActionStatus}" />
|
||||
|
||||
<TextBlock Grid.Row="4"
|
||||
<TextBlock Grid.Row="3"
|
||||
FontSize="11"
|
||||
Foreground="DarkSlateGray"
|
||||
TextWrapping="Wrap">
|
||||
|
|
|
|||
Loading…
Reference in a new issue