From 56e36e202c6b47e62a2ba8bf2df720aae8a270df Mon Sep 17 00:00:00 2001 From: Christiaan Bloemendaal Date: Mon, 1 Jan 2024 16:43:26 +0100 Subject: [PATCH] feat: add auto refreshing to activity page --- .../Pages/Activity/Content.razor.cs | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/Mangarr.Frontend/Pages/Activity/Content.razor.cs b/src/Mangarr.Frontend/Pages/Activity/Content.razor.cs index c334bc2..661e3b0 100644 --- a/src/Mangarr.Frontend/Pages/Activity/Content.razor.cs +++ b/src/Mangarr.Frontend/Pages/Activity/Content.razor.cs @@ -3,18 +3,34 @@ using Mangarr.Shared.Models; using Mangarr.Shared.Responses; using Microsoft.AspNetCore.Components; +using Timer = System.Timers.Timer; namespace Mangarr.Frontend.Pages.Activity; -public partial class Content +public partial class Content : IDisposable { private readonly List _items = new(); private bool _isRefreshing; + private Timer? _timer; + [Inject] public BackendApi BackendApi { get; set; } - protected override void OnInitialized() => RefreshAsync(); + public void Dispose() + { + _timer?.Stop(); + _timer?.Dispose(); + } + + protected override void OnInitialized() + { + _timer = new Timer(2500); + _timer.Elapsed += (_, _) => RefreshAsync(); + _timer.Start(); + + RefreshAsync(); + } private async void RefreshAsync() {