From 57645f017d53aecb0ad3aa11d1c1cd7719ec5bfc Mon Sep 17 00:00:00 2001 From: Lilian Date: Sun, 19 Jan 2025 21:25:59 +0100 Subject: [PATCH] [frontend/components] Add streaming status display --- .../Components/GlobalComponents.razor | 1 + .../Components/StreamingStatus.razor | 45 +++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 Iceshrimp.Frontend/Components/StreamingStatus.razor diff --git a/Iceshrimp.Frontend/Components/GlobalComponents.razor b/Iceshrimp.Frontend/Components/GlobalComponents.razor index 8d042a3d..c704a60c 100644 --- a/Iceshrimp.Frontend/Components/GlobalComponents.razor +++ b/Iceshrimp.Frontend/Components/GlobalComponents.razor @@ -1,4 +1,5 @@ + @code { } \ No newline at end of file diff --git a/Iceshrimp.Frontend/Components/StreamingStatus.razor b/Iceshrimp.Frontend/Components/StreamingStatus.razor new file mode 100644 index 00000000..12dae08e --- /dev/null +++ b/Iceshrimp.Frontend/Components/StreamingStatus.razor @@ -0,0 +1,45 @@ +@using Iceshrimp.Frontend.Core.Services +@using Iceshrimp.Frontend.Localization +@using Microsoft.AspNetCore.SignalR.Client +@using Microsoft.Extensions.Localization +@inject StreamingService StreamingService +@inject GlobalComponentSvc GlobalComponentSvc +@inject IStringLocalizer Loc + +@code { + protected override async Task OnInitializedAsync() + { + await StreamingService.ConnectAsync(); + StreamingService.OnConnectionChange += HandleConnectionChange; + } + + private void HandleConnectionChange(object? _, HubConnectionState hubConnectionState) + { + switch (hubConnectionState) + { + case HubConnectionState.Disconnected: + { + var banner = new BannerContainer.Banner { Text = @Loc["Connection lost, tap to reconnect."], OnClose = null, OnTap = Reconnect }; + GlobalComponentSvc.BannerComponent?.AddBanner(banner); + break; + } + case HubConnectionState.Reconnecting: + { + var banner = new BannerContainer.Banner { Text = @Loc["Reconnecting"], OnClose = null, OnTap = null }; + GlobalComponentSvc.BannerComponent?.AddBanner(banner); + break; + } + case HubConnectionState.Connected: + { + var banner = new BannerContainer.Banner { Text = @Loc["Connected"], OnClose = null, OnTap = null }; + GlobalComponentSvc.BannerComponent?.AddBanner(banner); + break; + } + } + } + + private void Reconnect() + { + _ = StreamingService.ReconnectAsync(); + } +} \ No newline at end of file