From 189275fb0c1cc2b8da15934a14ae4b700f99aec3 Mon Sep 17 00:00:00 2001 From: Refringe Date: Thu, 15 Aug 2024 23:45:17 -0400 Subject: [PATCH] Saves Filters to Local Storage The filters on the mod listing page are now also saved to the browser's local storage system. This means you can set a bunch of filters and a sort order, browse away (or close the browser), and the next time you visit the page the site will remember the filters that you had set. --- app/Livewire/Mod/Index.php | 7 ++++- resources/js/app.js | 9 ++++++ resources/views/livewire/mod/index.blade.php | 33 +++++++++++++++++++- 3 files changed, 47 insertions(+), 2 deletions(-) diff --git a/app/Livewire/Mod/Index.php b/app/Livewire/Mod/Index.php index 9b2b6e1..482b24d 100644 --- a/app/Livewire/Mod/Index.php +++ b/app/Livewire/Mod/Index.php @@ -6,6 +6,7 @@ use App\Http\Filters\ModFilter; use App\Models\SptVersion; use Illuminate\Contracts\View\View; use Illuminate\Database\Eloquent\Collection; +use Livewire\Attributes\Computed; use Livewire\Attributes\Url; use Livewire\Component; use Livewire\WithPagination; @@ -89,12 +90,16 @@ class Index extends Component $this->query = ''; $this->sptVersion = $this->getLatestMinorVersions()->pluck('version')->toArray(); $this->featured = 'include'; + + // Clear local storage + $this->dispatch('clear-filters'); } /** * Compute the count of active filters. */ - public function getFilterCountProperty(): int + #[Computed] + public function filterCount(): int { $count = 0; if ($this->query !== '') { diff --git a/resources/js/app.js b/resources/js/app.js index efade33..43479a9 100644 --- a/resources/js/app.js +++ b/resources/js/app.js @@ -1,3 +1,12 @@ import "./registerViteAssets"; import "./registerAlpineLivewire"; import "./themeToggle"; + +document.addEventListener("livewire:init", () => { + Livewire.on("clear-filters", (event) => { + localStorage.removeItem("filter-query"); + localStorage.removeItem("filter-order"); + localStorage.removeItem("filter-sptVersion"); + localStorage.removeItem("filter-featured"); + }); +}); diff --git a/resources/views/livewire/mod/index.blade.php b/resources/views/livewire/mod/index.blade.php index 8b269c6..da1e308 100644 --- a/resources/views/livewire/mod/index.blade.php +++ b/resources/views/livewire/mod/index.blade.php @@ -1,4 +1,35 @@ -
+

{{ __('Mods') }}

{!! __('Explore an enhanced SPT experience with the mods available below. Check out the featured mods for a tailored solo-survival game with maximum immersion.') !!}