From 5e0ca6ea1e63b2d3ac748418a168cbd6c411ef9a Mon Sep 17 00:00:00 2001 From: Grigorii Prudnikov Date: Sat, 30 Dec 2023 19:57:47 +0500 Subject: [PATCH] add filter types to url --- .eslintrc.json | 6 ++++++ components/Filters/components/Toggle/Toggle.tsx | 12 ++++++++++-- features/Buildings/BuildingSource.tsx | 14 ++++++++------ features/Map/providers/usePopup.ts | 10 +++------- shared/helpers/hash.ts | 6 ++---- shared/scripts/extractHousesData.ts | 9 +++++---- state/features/dataLayers.ts | 5 +++-- 7 files changed, 37 insertions(+), 25 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 2a634d3b..5fa66925 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -59,6 +59,12 @@ { "from": "./features", "target": "./components" } ] } + ], + "prettier/prettier": [ + "error", + { + "endOfLine": "auto" + } ] } } diff --git a/components/Filters/components/Toggle/Toggle.tsx b/components/Filters/components/Toggle/Toggle.tsx index 75206c63..46fa805b 100644 --- a/components/Filters/components/Toggle/Toggle.tsx +++ b/components/Filters/components/Toggle/Toggle.tsx @@ -1,5 +1,6 @@ -import React, { useCallback } from 'react'; +import { useCallback } from 'react'; +import { useRouter } from 'next/router'; import { FilterType } from 'types/Filters.types'; import styles from './Toggle.module.css'; @@ -13,9 +14,16 @@ export interface ToggleProps { } export function Toggle({ id, label, onClick, type, isActive }: ToggleProps) { + const router = useRouter(); + const onChange = useCallback(() => { onClick(type); - }, [type, onClick]); + router.push({ + pathname: '/', + query: type === FilterType.HouseAge ? {} : { filter: type }, + hash: window.location.hash.slice(1), + }); + }, [onClick, type, router]); return (