2022-09-22 09:37:49 +00:00
|
|
|
import { MainLayout } from '../Layouts/MainLayout'
|
|
|
|
import { SearchView } from '../Views/Search'
|
|
|
|
import type { PageProps } from '../types'
|
2022-10-05 15:11:14 +00:00
|
|
|
import { createMemo, createSignal, onCleanup, onMount, Show } from 'solid-js'
|
|
|
|
import { loadSearchResults, resetSortedArticles } from '../../stores/zine/articles'
|
|
|
|
import { t } from '../../utils/intl'
|
|
|
|
import { useRouter } from '../../stores/router'
|
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))
|
|
|
|
|
|
|
|
const q = createMemo(() => {
|
|
|
|
const { getPage } = useRouter()
|
|
|
|
|
|
|
|
const page = getPage()
|
|
|
|
|
|
|
|
if (page.route !== 'search') {
|
|
|
|
throw new Error('ts guard')
|
|
|
|
}
|
|
|
|
|
|
|
|
return page.params.q
|
|
|
|
})
|
|
|
|
|
|
|
|
onMount(async () => {
|
|
|
|
if (isLoaded()) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
await loadSearchResults({ query: q(), limit: 50, offset: 0 })
|
|
|
|
setIsLoaded(true)
|
|
|
|
})
|
|
|
|
|
|
|
|
onCleanup(() => resetSortedArticles())
|
|
|
|
|
2022-09-22 09:37:49 +00:00
|
|
|
return (
|
|
|
|
<MainLayout>
|
2022-10-05 15:11:14 +00:00
|
|
|
<Show when={isLoaded()} fallback={t('Loading')}>
|
|
|
|
<SearchView results={props.searchResults || []} query={props.searchQuery} />
|
|
|
|
</Show>
|
2022-09-22 09:37:49 +00:00
|
|
|
</MainLayout>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
// for lazy loading
|
|
|
|
export default SearchPage
|