Toast message + error display

This commit is contained in:
2022-05-29 08:02:40 +02:00
parent 74a8f66db1
commit 3f0c17b6cc
7 changed files with 51 additions and 7 deletions

View File

@@ -1,3 +1,4 @@
using FileTime.GuiApp.Services;
using Serilog.Core;
using Serilog.Events;
@@ -5,19 +6,19 @@ namespace FileTime.GuiApp.Logging;
public class ToastMessageSink : ILogEventSink
{
//private readonly IDialogService dialogService;
private readonly IDialogService dialogService;
public ToastMessageSink(/*IDialogService dialogService*/)
public ToastMessageSink(IDialogService dialogService)
{
//this.dialogService = dialogService;
this.dialogService = dialogService;
}
public void Emit(LogEvent logEvent)
{
/*if (logEvent.Level >= LogEventLevel.Error)
if (logEvent.Level >= LogEventLevel.Error)
{
var message = logEvent.RenderMessage();
dialogService.ShowToastMessage(message);
}*/
}
}
}

View File

@@ -1,4 +1,5 @@
using System.Reactive.Linq;
using Avalonia.Threading;
using DynamicData;
using FileTime.App.Core.Services;
using FileTime.Core.Interactions;
@@ -9,12 +10,14 @@ namespace FileTime.GuiApp.Services;
public class DialogService : IDialogService
{
private readonly IModalService _modalService;
private readonly IGuiAppState _guiAppState;
public IObservable<ReadInputsViewModel?> ReadInput { get; }
public DialogService(IModalService modalService)
public DialogService(IModalService modalService, IGuiAppState guiAppState)
{
_modalService = modalService;
_guiAppState = guiAppState;
ReadInput = modalService
.OpenModals
.ToCollection()
@@ -37,6 +40,16 @@ public class DialogService : IDialogService
_modalService.OpenModal(modalViewModel);
}
public void ShowToastMessage(string text)
{
Task.Run(async () =>
{
await Dispatcher.UIThread.InvokeAsync(() => _guiAppState.PopupTexts.Add(text));
await Task.Delay(5000);
await Dispatcher.UIThread.InvokeAsync(() => _guiAppState.PopupTexts.Remove(text));
});
}
private void HandleReadInputsSuccess(ReadInputsViewModel readInputsViewModel)
{
_modalService.CloseModal(readInputsViewModel);

View File

@@ -443,6 +443,30 @@
</Grid>
</Grid>
</Grid>
<ItemsRepeater Items="{Binding AppState.PopupTexts}" Margin="0,0,0,20" HorizontalAlignment="Center" VerticalAlignment="Top" IsVisible="{Binding AppState.PopupTexts.Count,Converter={StaticResource NotEqualsConverter}, ConverterParameter=0}">
<ItemsRepeater.Styles>
<Style Selector="TextBlock">
<Style.Animations>
<Animation Duration="0:0:1">
<KeyFrame Cue="0%">
<Setter Property="Opacity" Value="0.0"/>
</KeyFrame>
<KeyFrame Cue="100%">
<Setter Property="Opacity" Value="1.0"/>
</KeyFrame>
</Animation>
</Style.Animations>
</Style>
</ItemsRepeater.Styles>
<ItemsRepeater.ItemTemplate>
<DataTemplate x:DataType="x:String">
<Border Background="{DynamicResource ContainerGradientBackgroundBrush}" Margin="5" Padding="5">
<TextBlock Text="{Binding}" Foreground="{DynamicResource AccentComplementBrush}" HorizontalAlignment="Center"/>
</Border>
</DataTemplate>
</ItemsRepeater.ItemTemplate>
</ItemsRepeater>
</Grid>
<Grid Grid.Row="3">