From f404420007f758b8d468e613b971461d23d769f9 Mon Sep 17 00:00:00 2001 From: Pat Hartl Date: Thu, 17 Aug 2023 17:23:32 -0500 Subject: [PATCH] Persist field picker across page reloads --- LANCommander/Pages/Games/Index.razor | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/LANCommander/Pages/Games/Index.razor b/LANCommander/Pages/Games/Index.razor index 4e9da10..f55e500 100644 --- a/LANCommander/Pages/Games/Index.razor +++ b/LANCommander/Pages/Games/Index.razor @@ -1,9 +1,11 @@ @page "/Games" @using LANCommander.Extensions; @using System.ComponentModel.DataAnnotations; +@using Microsoft.AspNetCore.Components.Server.ProtectedBrowserStorage; @attribute [Authorize] @inject GameService GameService @inject NavigationManager NavigationManager +@inject ProtectedLocalStorage BrowserStorage @@ -11,7 +13,7 @@ - + @Field.Icon.GetDisplayName() @Field.Title.GetDisplayName() @@ -163,7 +165,7 @@
-
@@ -233,7 +235,7 @@ ArchiveSize, } - protected override void OnAfterRender(bool firstRender) + protected override async Task OnAfterRenderAsync(bool firstRender) { if (firstRender) { @@ -241,6 +243,11 @@ Loading = false; + var storedFieldVisibility = await BrowserStorage.GetAsync>("Views.Games.FieldPicker"); + + if (storedFieldVisibility.Success && storedFieldVisibility.Value != null) + FieldVisibility = storedFieldVisibility.Value; + StateHasChanged(); } } @@ -287,4 +294,16 @@ Loading = false; } + + private async Task OpenFieldPicker() + { + FieldPickerVisible = true; + } + + private async Task CloseFieldPicker() + { + FieldPickerVisible = false; + + await BrowserStorage.SetAsync("Views.Games.FieldPicker", FieldVisibility); + } }