From f5efb7769b986f17314f25ffe591814c99a221a4 Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Wed, 8 Jul 2020 13:03:35 +0200 Subject: [PATCH] Name query filter on targets (#3144) * Name query filter on targets * s/name/filter * Apply ?filter= on all Filtered wrappers --- packages/page-staking/src/Filtering.tsx | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/page-staking/src/Filtering.tsx b/packages/page-staking/src/Filtering.tsx index 1be70150eb..6ad13c6e0e 100644 --- a/packages/page-staking/src/Filtering.tsx +++ b/packages/page-staking/src/Filtering.tsx @@ -2,9 +2,11 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. -import React from 'react'; +import queryString from 'query-string'; +import React, { useEffect } from 'react'; import { Input, Toggle } from '@polkadot/react-components'; import { useApi } from '@polkadot/react-hooks'; +import { isString } from '@polkadot/util'; import { useTranslation } from './translate'; @@ -21,6 +23,16 @@ function Filtering ({ children, className, nameFilter, setNameFilter, setWithIde const { t } = useTranslation(); const { api } = useApi(); + // on load, parse the query string and extract the filter + useEffect((): void => { + const queryFilter = queryString.parse(location.href.split('?')[1]).filter; + + if (isString(queryFilter)) { + setNameFilter(queryFilter); + } + // eslint-disable-next-line react-hooks/exhaustive-deps + }, []); + return (