Skip to content

Commit

Permalink
fix: searchbar cannot clear + add onEnter (#312)
Browse files Browse the repository at this point in the history
  • Loading branch information
ryenguyen7411 authored Dec 1, 2023
1 parent 1f7b0df commit f8e1d25
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 28 deletions.
58 changes: 30 additions & 28 deletions src/components/Search/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const Search = () => {
const params = router.query;
const chainBridge = String(params.bridge || '');

const [search, setSearch] = useState('');
const [search, setSearch] = useState(router.query.q);
const { media } = StylingConstants;
const lg = useMatchMedia({ query: `(min-width: ${rem(media.lg)})` });
const md = useMatchMedia({ query: `(min-width: ${rem(media.md)})` });
Expand All @@ -37,40 +37,42 @@ export const Search = () => {
}
};

const handleSearch = async () => {
var address = await checkUD(search);
if (address)
router.push({
pathname: PATH.EXPLORER,
query: {
bridge: chainBridge,
type: address ? 'search' : '',
q: address,
},
});
else
router.push({
pathname: PATH.EXPLORER,
query: {
bridge: chainBridge,
type: search ? 'search' : '',
q: search,
},
});
};

return (
<SearchInput
size={lg ? 'country' : md ? 'state' : 'country'}
value={search || router.query.q}
value={search}
onKeyDown={(evt) => {
if (evt.keyCode === 13) {
handleSearch();
}
}}
onChange={(evt) => {
setSearch(evt.target.value);
}}
placeholder={formatMessage({ id: 'common.placeholder.search' })}
right={
<SearchIcon
size="country"
onClick={async () => {
var address = await checkUD(search);
if (address)
router.push({
pathname: PATH.EXPLORER,
query: {
bridge: chainBridge,
type: address ? 'search' : '',
q: address,
},
});
else
router.push({
pathname: PATH.EXPLORER,
query: {
bridge: chainBridge,
type: search ? 'search' : '',
q: search,
},
});
}}
/>
}
right={<SearchIcon size="country" onClick={handleSearch} />}
/>
);
};
1 change: 1 addition & 0 deletions src/components/Search/styled.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,5 @@ export const SearchInput = styled(TextInput)`
export const SearchIcon = styled(Icon.Search)`
color: ${({ theme }) => theme.pulsar.color.primary.normal};
font-size: ${({ theme }) => rem(theme.pulsar.size.street)};
cursor: pointer;
`;

1 comment on commit f8e1d25

@vercel
Copy link

@vercel vercel bot commented on f8e1d25 Dec 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.