1
0
Fork 0

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();
if (hash === '') hash = '/';
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 (
<a
ref={ref}

View file

@ -163,7 +163,6 @@ const SearchForm = forwardRef((props, ref) => {
if (focusItem) {
e.preventDefault();
focusItem.click();
props?.onSubmit?.(e);
}
setSearchMenuOpen(false);
}
@ -221,7 +220,14 @@ const SearchForm = forwardRef((props, ref) => {
return 0;
})
.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={type === 'link' ? 'arrow-right' : 'search'}
class="more-insignificant"

View file

@ -153,22 +153,26 @@ function Search(props) {
<main>
{!!q && (
<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',
type: 'accounts',
to: `/search?q=${q}&type=accounts`,
to: `/search?q=${encodeURIComponent(q)}&type=accounts`,
},
{
label: 'Hashtags',
type: 'hashtags',
to: `/search?q=${q}&type=hashtags`,
to: `/search?q=${encodeURIComponent(q)}&type=hashtags`,
},
{
label: 'Posts',
type: 'statuses',
to: `/search?q=${q}&type=statuses`,
to: `/search?q=${encodeURIComponent(q)}&type=statuses`,
},
]
.sort((a, b) => {