Commit c47464cc authored by isstuev's avatar isstuev

add initial filter value from url

parent 2f118486
...@@ -10,10 +10,11 @@ type Props = { ...@@ -10,10 +10,11 @@ type Props = {
className?: string; className?: string;
size?: 'xs' | 'sm' | 'md' | 'lg'; size?: 'xs' | 'sm' | 'md' | 'lg';
placeholder: string; placeholder: string;
initialValue?: string;
} }
const FilterInput = ({ onChange, className, size = 'sm', placeholder }: Props) => { const FilterInput = ({ onChange, className, size = 'sm', placeholder, initialValue }: Props) => {
const [ filterQuery, setFilterQuery ] = useState(''); const [ filterQuery, setFilterQuery ] = useState(initialValue || '');
const inputRef = React.useRef<HTMLInputElement>(null); const inputRef = React.useRef<HTMLInputElement>(null);
const iconColor = useColorModeValue('blackAlpha.600', 'whiteAlpha.600'); const iconColor = useColorModeValue('blackAlpha.600', 'whiteAlpha.600');
......
...@@ -27,7 +27,7 @@ const getTokenFilterValue = (getFilterValuesFromQuery<TokenType>).bind(null, TOK ...@@ -27,7 +27,7 @@ const getTokenFilterValue = (getFilterValuesFromQuery<TokenType>).bind(null, TOK
const Tokens = () => { const Tokens = () => {
const router = useRouter(); const router = useRouter();
const [ filter, setFilter ] = React.useState<string>(''); const [ filter, setFilter ] = React.useState<string>(router.query.filter?.toString() || '');
const [ type, setType ] = React.useState<Array<TokenType> | undefined>(getTokenFilterValue(router.query.type)); const [ type, setType ] = React.useState<Array<TokenType> | undefined>(getTokenFilterValue(router.query.type));
const debouncedFilter = useDebounce(filter, 300); const debouncedFilter = useDebounce(filter, 300);
...@@ -57,7 +57,15 @@ const Tokens = () => { ...@@ -57,7 +57,15 @@ const Tokens = () => {
</PopoverFilter> </PopoverFilter>
); );
const filterInput = <FilterInput w="100%" size="xs" onChange={ onSearchChange } placeholder="Token name or symbol"/>; const filterInput = (
<FilterInput
w="100%"
size="xs"
onChange={ onSearchChange }
placeholder="Token name or symbol"
initialValue={ filter }
/>
);
const bar = ( const bar = (
<> <>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment