From 591d5457577c8718e39dce7fd557f7acd4b053a6 Mon Sep 17 00:00:00 2001 From: dzsak Date: Tue, 19 Dec 2023 16:01:02 +0100 Subject: [PATCH] Filter logic --- web/src/App.js | 44 ++++++++++++++++++++++++++++++----------- web/src/FilterBar.js | 47 +++++++++++++++++++++++++------------------- web/src/Services.js | 28 +++++++++++++++++++++++--- 3 files changed, 85 insertions(+), 34 deletions(-) diff --git a/web/src/App.js b/web/src/App.js index 496b286..add5c3a 100644 --- a/web/src/App.js +++ b/web/src/App.js @@ -6,6 +6,7 @@ import { rootReducer } from './redux'; import Footer from "./Footer"; import FilterBar from "./FilterBar"; import Services from "./Services"; +import { useState, useEffect } from "react"; function App() { const capacitorClient = new CapacitorClient( @@ -15,6 +16,32 @@ function App() { ); const store = createStore(rootReducer); + const [filters, setFilters] = useState(JSON.parse(localStorage.getItem("filters")) ?? []) + + useEffect(() => { + localStorage.setItem("filters", JSON.stringify(filters)); + }, [filters]); + + const addFilter = (filter) => { + setFilters([...filters, filter]); + } + + const filterValueByProperty = (property) => { + const filter = filters.find(f => f.property === property) + if (!filter) { + return "" + } + + return filter.value + } + + const deleteFilter = (filter) => { + setFilters(filters.filter(f => f.property !== filter.property)) + } + + const resetFilters = () => { + setFilters([]) + } return ( <> @@ -23,20 +50,15 @@ function App() {
- +