2023-02-17 09:21:02 +00:00
|
|
|
import { PageLayout } from '../components/_shared/PageLayout'
|
|
|
|
import { SearchView } from '../components/Views/Search'
|
|
|
|
import type { PageProps } from './types'
|
2022-10-05 15:11:14 +00:00
|
|
|
import { createMemo, createSignal, onCleanup, onMount, Show } from 'solid-js'
|
2023-02-17 09:21:02 +00:00
|
|
|
import { useRouter } from '../stores/router'
|
|
|
|
import { loadShouts, resetSortedArticles } from '../stores/zine/articles'
|
|
|
|
import { Loading } from '../components/_shared/Loading'
|
2023-02-28 17:35:33 +00:00
|
|
|
import { ReactionsProvider } from '../context/reactions'
|
2023-11-14 10:45:44 +00:00
|
|
|
import { useLocalize } from '../context/localize'
|
2022-09-22 09:37:49 +00:00
|
|
|
|
|
|
|
export const SearchPage = (props: PageProps) => {
|
2022-10-05 15:11:14 +00:00
|
|
|
const [isLoaded, setIsLoaded] = createSignal(Boolean(props.searchResults))
|
|
|
|
|
2023-11-14 10:45:44 +00:00
|
|
|
const { t } = useLocalize()
|
2022-10-05 15:11:14 +00:00
|
|
|
|
2023-11-14 10:45:44 +00:00
|
|
|
const { page } = useRouter()
|
2022-10-05 15:11:14 +00:00
|
|
|
|
2023-11-14 10:45:44 +00:00
|
|
|
const q = createMemo(() => page().params['q'] as string)
|
2022-10-05 15:11:14 +00:00
|
|
|
|
|
|
|
onMount(async () => {
|
|
|
|
if (isLoaded()) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-11-18 02:23:04 +00:00
|
|
|
await loadShouts({ filters: { title: q(), body: q() }, limit: 50, offset: 0 })
|
2022-10-05 15:11:14 +00:00
|
|
|
setIsLoaded(true)
|
|
|
|
})
|
|
|
|
|
|
|
|
onCleanup(() => resetSortedArticles())
|
|
|
|
|
2022-09-22 09:37:49 +00:00
|
|
|
return (
|
2023-11-14 10:45:44 +00:00
|
|
|
<PageLayout title={t('Search')}>
|
2023-02-28 17:35:33 +00:00
|
|
|
<ReactionsProvider>
|
|
|
|
<Show when={isLoaded()} fallback={<Loading />}>
|
|
|
|
<SearchView results={props.searchResults || []} query={props.searchQuery} />
|
|
|
|
</Show>
|
|
|
|
</ReactionsProvider>
|
2023-02-17 09:21:02 +00:00
|
|
|
</PageLayout>
|
2022-09-22 09:37:49 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2023-02-17 09:21:02 +00:00
|
|
|
export const Page = SearchPage
|