webapp/src/pages/search.page.tsx

43 lines
1.4 KiB
TypeScript
Raw Normal View History

2023-02-17 09:21:02 +00:00
import type { PageProps } from './types'
2023-12-26 10:05:15 +00:00
import { createEffect, createMemo, createSignal, onCleanup, Show } from 'solid-js'
2023-02-17 09:21:02 +00:00
import { Loading } from '../components/_shared/Loading'
import { PageLayout } from '../components/_shared/PageLayout'
import { SearchView } from '../components/Views/Search'
import { useLocalize } from '../context/localize'
import { ReactionsProvider } from '../context/reactions'
import { useRouter } from '../stores/router'
2023-11-29 20:24:33 +00:00
import { loadShoutsSearch, resetSortedArticles } from '../stores/zine/articles'
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 { t } = useLocalize()
2023-12-26 10:05:15 +00:00
const { page } = useRouter()
2024-02-04 09:23:20 +00:00
const q = createMemo(() => page().params.q as string)
2022-10-05 15:11:14 +00:00
2023-12-24 23:56:24 +00:00
createEffect(async () => {
if (isLoaded()) return
2024-02-04 09:23:20 +00:00
if (q() && window) {
2023-12-24 23:56:24 +00:00
const text = q() || window.location.href.split('/').pop()
// TODO: pagination, load more
await loadShoutsSearch({ text, limit: 50, offset: 0 })
setIsLoaded(true)
2022-10-05 15:11:14 +00:00
}
})
onCleanup(() => resetSortedArticles())
2022-09-22 09:37:49 +00:00
return (
<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