1
0
Fork 0
mirror of https://github.com/cheeaun/phanpy.git synced 2025-03-31 02:51:36 +02:00

Fixes + improvements to search UI

This commit is contained in:
Lim Chee Aun 2024-01-29 21:11:08 +08:00
parent 9792700f30
commit a66307b757
4 changed files with 84 additions and 10 deletions

View file

@ -99,4 +99,5 @@ export const ICONS = {
speak: () => import('@iconify-icons/mingcute/radar-line'), speak: () => import('@iconify-icons/mingcute/radar-line'),
building: () => import('@iconify-icons/mingcute/building-5-line'), building: () => import('@iconify-icons/mingcute/building-5-line'),
history: () => import('@iconify-icons/mingcute/history-2-line'), history: () => import('@iconify-icons/mingcute/history-2-line'),
document: () => import('@iconify-icons/mingcute/document-line'),
}; };

View file

@ -73,6 +73,7 @@ const SearchForm = forwardRef((props, ref) => {
autocomplete="off" autocomplete="off"
autocorrect="off" autocorrect="off"
autocapitalize="off" autocapitalize="off"
spellcheck="false"
onSearch={(e) => { onSearch={(e) => {
if (!e.target.value) { if (!e.target.value) {
setSearchParams({}); setSearchParams({});
@ -84,6 +85,9 @@ const SearchForm = forwardRef((props, ref) => {
}} }}
onFocus={() => { onFocus={() => {
setSearchMenuOpen(true); setSearchMenuOpen(true);
formRef.current
?.querySelector('.search-popover-item')
?.classList.add('focus');
}} }}
onBlur={() => { onBlur={() => {
setTimeout(() => { setTimeout(() => {
@ -178,8 +182,33 @@ const SearchForm = forwardRef((props, ref) => {
}} }}
/> />
<div class="search-popover" hidden={!searchMenuOpen || !query}> <div class="search-popover" hidden={!searchMenuOpen || !query}>
{/* {!!query && (
<Link
to={`/search?q=${encodeURIComponent(query)}`}
class="search-popover-item focus"
onClick={(e) => {
props?.onSubmit?.(e);
}}
>
<Icon icon="search" />
<span>{query}</span>
</Link>
)} */}
{!!query && {!!query &&
[ [
{
label: (
<>
{query}{' '}
<small class="insignificant">
accounts, hashtags &amp; posts
</small>
</>
),
to: `/search?q=${encodeURIComponent(query)}`,
top: !type && !/\s/.test(query),
hidden: !!type,
},
{ {
label: ( label: (
<> <>
@ -188,6 +217,8 @@ const SearchForm = forwardRef((props, ref) => {
), ),
to: `/search?q=${encodeURIComponent(query)}&type=statuses`, to: `/search?q=${encodeURIComponent(query)}&type=statuses`,
hidden: /^https?:/.test(query), hidden: /^https?:/.test(query),
top: /\s/.test(query),
icon: 'document',
}, },
{ {
label: ( label: (
@ -200,6 +231,7 @@ const SearchForm = forwardRef((props, ref) => {
/^@/.test(query) || /^https?:/.test(query) || /\s/.test(query), /^@/.test(query) || /^https?:/.test(query) || /\s/.test(query),
top: /^#/.test(query), top: /^#/.test(query),
type: 'link', type: 'link',
icon: 'hashtag',
}, },
{ {
label: ( label: (
@ -219,6 +251,7 @@ const SearchForm = forwardRef((props, ref) => {
</> </>
), ),
to: `/search?q=${encodeURIComponent(query)}&type=accounts`, to: `/search?q=${encodeURIComponent(query)}&type=accounts`,
icon: 'group',
}, },
] ]
.sort((a, b) => { .sort((a, b) => {
@ -226,17 +259,18 @@ const SearchForm = forwardRef((props, ref) => {
if (!a.top && b.top) return 1; if (!a.top && b.top) return 1;
return 0; return 0;
}) })
.map(({ label, to, hidden, type }) => ( .filter(({ hidden }) => !hidden)
.map(({ label, to, icon, type }, i) => (
<Link <Link
to={to} to={to}
class="search-popover-item" class={`search-popover-item ${i === 0 ? 'focus' : ''}`}
hidden={hidden} // hidden={hidden}
onClick={(e) => { onClick={(e) => {
props?.onSubmit?.(e); props?.onSubmit?.(e);
}} }}
> >
<Icon <Icon
icon={type === 'link' ? 'arrow-right' : 'search'} icon={icon || (type === 'link' ? 'arrow-right' : 'search')}
class="more-insignificant" class="more-insignificant"
/> />
<span>{label}</span>{' '} <span>{label}</span>{' '}

View file

@ -44,6 +44,18 @@
} }
} }
#search-page h2 {
a {
.icon {
vertical-align: middle;
transition: transform 0.2s;
}
&:hover .icon {
transform: translateX(4px);
}
}
}
#search-page ul.accounts-list { #search-page ul.accounts-list {
display: flex; display: flex;
flex-wrap: wrap; flex-wrap: wrap;

View file

@ -253,7 +253,14 @@ function Search({ columnMode, ...props }) {
{(!type || type === 'accounts') && ( {(!type || type === 'accounts') && (
<> <>
{type !== 'accounts' && ( {type !== 'accounts' && (
<h2 class="timeline-header">Accounts</h2> <h2 class="timeline-header">
Accounts{' '}
<Link
to={`/search?q=${encodeURIComponent(q)}&type=accounts`}
>
<Icon icon="arrow-right" size="l" />
</Link>
</h2>
)} )}
{accountResults.length > 0 ? ( {accountResults.length > 0 ? (
<> <>
@ -273,7 +280,9 @@ function Search({ columnMode, ...props }) {
<div class="ui-state"> <div class="ui-state">
<Link <Link
class="plain button" class="plain button"
to={`/search?q=${q}&type=accounts`} to={`/search?q=${encodeURIComponent(
q,
)}&type=accounts`}
> >
See more accounts <Icon icon="arrow-right" /> See more accounts <Icon icon="arrow-right" />
</Link> </Link>
@ -295,7 +304,14 @@ function Search({ columnMode, ...props }) {
{(!type || type === 'hashtags') && ( {(!type || type === 'hashtags') && (
<> <>
{type !== 'hashtags' && ( {type !== 'hashtags' && (
<h2 class="timeline-header">Hashtags</h2> <h2 class="timeline-header">
Hashtags{' '}
<Link
to={`/search?q=${encodeURIComponent(q)}&type=hashtags`}
>
<Icon icon="arrow-right" size="l" />
</Link>
</h2>
)} )}
{hashtagResults.length > 0 ? ( {hashtagResults.length > 0 ? (
<> <>
@ -331,7 +347,9 @@ function Search({ columnMode, ...props }) {
<div class="ui-state"> <div class="ui-state">
<Link <Link
class="plain button" class="plain button"
to={`/search?q=${q}&type=hashtags`} to={`/search?q=${encodeURIComponent(
q,
)}&type=hashtags`}
> >
See more hashtags <Icon icon="arrow-right" /> See more hashtags <Icon icon="arrow-right" />
</Link> </Link>
@ -353,7 +371,14 @@ function Search({ columnMode, ...props }) {
{(!type || type === 'statuses') && ( {(!type || type === 'statuses') && (
<> <>
{type !== 'statuses' && ( {type !== 'statuses' && (
<h2 class="timeline-header">Posts</h2> <h2 class="timeline-header">
Posts{' '}
<Link
to={`/search?q=${encodeURIComponent(q)}&type=statuses`}
>
<Icon icon="arrow-right" size="l" />
</Link>
</h2>
)} )}
{statusResults.length > 0 ? ( {statusResults.length > 0 ? (
<> <>
@ -377,7 +402,9 @@ function Search({ columnMode, ...props }) {
<div class="ui-state"> <div class="ui-state">
<Link <Link
class="plain button" class="plain button"
to={`/search?q=${q}&type=statuses`} to={`/search?q=${encodeURIComponent(
q,
)}&type=statuses`}
> >
See more posts <Icon icon="arrow-right" /> See more posts <Icon icon="arrow-right" />
</Link> </Link>