From bfe5edcfe332b4ec5b8f53be651e8325416b249b Mon Sep 17 00:00:00 2001 From: keyan Date: Tue, 26 Mar 2024 18:37:40 -0500 Subject: [PATCH] search all territories by default + more intuitive search filters --- api/resolvers/search.js | 16 +++++++++------- components/hidden-wallet-summary.js | 2 +- components/navigation/common.js | 2 +- components/navigation/sticky-bar.js | 2 -- components/search.module.css | 4 +--- next.config.js | 2 +- pages/{~ => }/search.js | 16 ++++++++-------- {pages/~ => styles}/search.module.css | 10 ++++++---- 8 files changed, 27 insertions(+), 27 deletions(-) rename pages/{~ => }/search.js (69%) rename {pages/~ => styles}/search.module.css (71%) diff --git a/api/resolvers/search.js b/api/resolvers/search.js index 0d4854a1..b3d2d149 100644 --- a/api/resolvers/search.js +++ b/api/resolvers/search.js @@ -7,14 +7,16 @@ function queryParts (q) { const queryArr = q.replace(regex, '').trim().split(/\s+/) const url = queryArr.find(word => word.startsWith('url:')) - const nym = queryArr.find(word => word.startsWith('nym:')) - const exclude = [url, nym] + const nym = queryArr.find(word => word.startsWith('@')) + const territory = queryArr.find(word => word.startsWith('~')) + const exclude = [url, nym, territory] const query = queryArr.filter(word => !exclude.includes(word)).join(' ') return { quotes: [...q.matchAll(regex)].map(m => m[1]), nym, url, + territory, query } } @@ -169,7 +171,7 @@ export default { items } }, - search: async (parent, { q, sub, cursor, sort, what, when, from: whenFrom, to: whenTo }, { me, models, search }) => { + search: async (parent, { q, cursor, sort, what, when, from: whenFrom, to: whenTo }, { me, models, search }) => { const decodedCursor = decodeCursor(cursor) let sitems = null let termQueries = [] @@ -193,7 +195,7 @@ export default { break } - const { query: _query, quotes, nym, url } = queryParts(q) + const { query: _query, quotes, nym, url, territory } = queryParts(q) let query = _query const isUrlSearch = url && query.length === 0 // exclusively searching for an url @@ -206,11 +208,11 @@ export default { } if (nym) { - whatArr.push({ wildcard: { 'user.name': `*${nym.slice(4).toLowerCase()}*` } }) + whatArr.push({ wildcard: { 'user.name': `*${nym.slice(1).toLowerCase()}*` } }) } - if (sub) { - whatArr.push({ match: { 'sub.name': sub } }) + if (territory) { + whatArr.push({ match: { 'sub.name': territory.slice(1) } }) } termQueries.push({ diff --git a/components/hidden-wallet-summary.js b/components/hidden-wallet-summary.js index 51189e49..3ff55a0e 100644 --- a/components/hidden-wallet-summary.js +++ b/components/hidden-wallet-summary.js @@ -16,7 +16,7 @@ export default function HiddenWalletSummary ({ abbreviate, fixedWidth }) { return ( setHover(true)} onPointerLeave={() => setHover(false)} + className='text-monospace' align='right' onPointerEnter={() => setHover(true)} onPointerLeave={() => setHover(false)} > {hover ? (abbreviate ? abbrNum(me.privates?.sats) : numWithUnits(me.privates?.sats, { abbreviate: false, format: true })) : '******'} diff --git a/components/navigation/common.js b/components/navigation/common.js index 26cb7d64..31bc4256 100644 --- a/components/navigation/common.js +++ b/components/navigation/common.js @@ -70,7 +70,7 @@ export function Back () { return ( { + role='button' tabIndex='0' className='nav-link p-0 me-2' onClick={() => { if (back) { router.back() } else { diff --git a/components/navigation/sticky-bar.js b/components/navigation/sticky-bar.js index 9ff8f473..b2528fda 100644 --- a/components/navigation/sticky-bar.js +++ b/components/navigation/sticky-bar.js @@ -21,8 +21,6 @@ export default function StickyBar ({ prefix, sub, path, topNavKey, dropNavKey }) } }, [ref?.current, sticky?.current]) - if (path.endsWith('/search')) return null - return ( <>
diff --git a/components/search.module.css b/components/search.module.css index 1df690b2..89b45237 100644 --- a/components/search.module.css +++ b/components/search.module.css @@ -1,13 +1,11 @@ .searchSection { - position: sticky; - top: 0; - border-bottom: 1px solid var(--theme-toolbarActive); background-color: var(--bs-body-bg); z-index: 1; } .searchContainer { position: relative; + padding-bottom: 0.5rem; } .search { diff --git a/next.config.js b/next.config.js index a10c2a5c..0a253923 100644 --- a/next.config.js +++ b/next.config.js @@ -177,7 +177,7 @@ module.exports = withPlausibleProxy()({ source: '/~:sub/:slug*', destination: '/~/:slug*?sub=:sub' }, - ...['/', '/post', '/search', '/rss', '/recent/:slug*', '/top/:slug*'].map(source => ({ source, destination: '/~' + source })) + ...['/', '/post', '/rss', '/recent/:slug*', '/top/:slug*'].map(source => ({ source, destination: '/~' + source })) ] }, async redirects () { diff --git a/pages/~/search.js b/pages/search.js similarity index 69% rename from pages/~/search.js rename to pages/search.js index 94a74ee4..ba7ddd5a 100644 --- a/pages/~/search.js +++ b/pages/search.js @@ -3,7 +3,7 @@ import { getGetServerSideProps } from '@/api/ssrApollo' import { useRouter } from 'next/router' import { SUB_SEARCH } from '@/fragments/subs' import Items from '@/components/items' -import styles from './search.module.css' +import styles from '@/styles/search.module.css' export const getServerSideProps = getGetServerSideProps({ query: SUB_SEARCH, @@ -31,16 +31,16 @@ export default function Index ({ ssrData }) {
- more filters + filters
-
-
nym:sn - limit results by stacker nym
-
url:stacker​.news - limit to specific site
-
"exact phrase" - demand results contain exact phrase
-
you are searching {variables.sub || 'home'}
home searches show results from all
-
+
    +
  • @nym - limit to results authored by nym
  • +
  • ~territory - limit to results from territory
  • +
  • url:stacker​.news - limit to link posts from a specific url
  • +
  • "exact phrase" - limit to results that contain an exact phrase
  • +
diff --git a/pages/~/search.module.css b/styles/search.module.css similarity index 71% rename from pages/~/search.module.css rename to styles/search.module.css index 65adc1c8..b022217e 100644 --- a/pages/~/search.module.css +++ b/styles/search.module.css @@ -7,7 +7,6 @@ .box { border: 1px solid var(--theme-borderColor); border-radius: 10px; - box-shadow: 2px 2px 10px var(--theme-borderColor); min-width: 50%; display: flex; flex-direction: column; @@ -20,10 +19,13 @@ align-self: center; } .inner { - padding: 0.5rem 0; + padding-right: 2rem; + padding-bottom: 1rem; + padding-top: 1rem; + padding-inline-start: 3rem; display: flex; flex-direction: column; } -.inner > div { - padding: 5px 2rem; +.inner > li { + padding: 0.25rem 0; } \ No newline at end of file