From 929cf0fa6cbbdb9983e09599a4ad303ba613771e Mon Sep 17 00:00:00 2001 From: eug-vs Date: Sat, 17 Apr 2021 15:44:57 +0300 Subject: feat: add reset filters button --- src/containers/Page.tsx | 17 +++++++++++++++-- src/lib/ServiceList.tsx | 10 +++++++++- 2 files changed, 24 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/containers/Page.tsx b/src/containers/Page.tsx index 458bf15..69f3513 100644 --- a/src/containers/Page.tsx +++ b/src/containers/Page.tsx @@ -1,4 +1,5 @@ import React from 'react'; +import { useLocation } from 'react-router-dom'; import Paper from '../components/Paper'; import Button from '../components/Button'; import { Action, Filter } from '../lib/ServiceContext'; @@ -9,12 +10,15 @@ interface Props { actions?: Action[]; filters?: Filter[]; applyFilter?: (key: string, value: string) => void; + resetFilters?: () => void; className?: string; } const style = 'mb-2 flex justify-between md:flex-row md:items-center'; -const Page: React.FC = ({ title, actions, filters, applyFilter, className, children }) => { +const Page: React.FC = ({ title, actions, filters, applyFilter, resetFilters, className, children }) => { + const location = useLocation(); + const handleFilterChange = (key: string) => (event: React.ChangeEvent) => { if (applyFilter) applyFilter(key, event.target.value); }; @@ -24,7 +28,16 @@ const Page: React.FC = ({ title, actions, filters, applyFilter, className
1 ? 'flex-col items-start' : 'flex-row items-center'}`}> {title}
-
+
+ {filters && location.search && ( + + Сбросить фильтры + + )} {filters?.map(filter => ( { history.push(`${service.route}?${queryString}`); }; + const resetFilters = () => history.push(service.route); + return ( - + ); -- cgit v1.2.3