Fix search bugs

This commit is contained in:
Lim Chee Aun 2023-09-04 17:01:06 +08:00
parent 0fd719d3e7
commit eed9b70a7d
3 changed files with 18 additions and 7 deletions

View file

@ -19,7 +19,8 @@ const Link = forwardRef((props, ref) => {
let hash = (location.hash || '').replace(/^#/, '').trim(); let hash = (location.hash || '').replace(/^#/, '').trim();
if (hash === '') hash = '/'; if (hash === '') hash = '/';
const { to, ...restProps } = props; const { to, ...restProps } = props;
const isActive = decodeURIComponent(hash) === to; // TODO: maybe better pass hash into URL to deconstruct the pathname and search, then decodeURIComponent them
const isActive = hash === to || decodeURIComponent(hash) === to;
return ( return (
<a <a
ref={ref} ref={ref}

View file

@ -163,7 +163,6 @@ const SearchForm = forwardRef((props, ref) => {
if (focusItem) { if (focusItem) {
e.preventDefault(); e.preventDefault();
focusItem.click(); focusItem.click();
props?.onSubmit?.(e);
} }
setSearchMenuOpen(false); setSearchMenuOpen(false);
} }
@ -221,7 +220,14 @@ const SearchForm = forwardRef((props, ref) => {
return 0; return 0;
}) })
.map(({ label, to, hidden, type }) => ( .map(({ label, to, hidden, type }) => (
<Link to={to} class="search-popover-item" hidden={hidden}> <Link
to={to}
class="search-popover-item"
hidden={hidden}
onClick={(e) => {
props?.onSubmit?.(e);
}}
>
<Icon <Icon
icon={type === 'link' ? 'arrow-right' : 'search'} icon={type === 'link' ? 'arrow-right' : 'search'}
class="more-insignificant" class="more-insignificant"

View file

@ -153,22 +153,26 @@ function Search(props) {
<main> <main>
{!!q && ( {!!q && (
<div class="filter-bar"> <div class="filter-bar">
{!!type && <Link to={`/search${q ? `?q=${q}` : ''}`}> All</Link>} {!!type && (
<Link to={`/search${q ? `?q=${encodeURIComponent(q)}` : ''}`}>
All
</Link>
)}
{[ {[
{ {
label: 'Accounts', label: 'Accounts',
type: 'accounts', type: 'accounts',
to: `/search?q=${q}&type=accounts`, to: `/search?q=${encodeURIComponent(q)}&type=accounts`,
}, },
{ {
label: 'Hashtags', label: 'Hashtags',
type: 'hashtags', type: 'hashtags',
to: `/search?q=${q}&type=hashtags`, to: `/search?q=${encodeURIComponent(q)}&type=hashtags`,
}, },
{ {
label: 'Posts', label: 'Posts',
type: 'statuses', type: 'statuses',
to: `/search?q=${q}&type=statuses`, to: `/search?q=${encodeURIComponent(q)}&type=statuses`,
}, },
] ]
.sort((a, b) => { .sort((a, b) => {