webapp/src/pages/search.page.tsx
Untone 5522c565b4
Some checks failed
deploy / push (push) Blocked by required conditions
deploy / test (push) Successful in 1m5s
deploy / quality (push) Failing after 3s
deploy / Update templates on Mailgun (push) Has been skipped
deploy / test_with_playwright (push) Has been cancelled
sometimes-needed
2024-02-04 12:30:06 +03:00

43 lines
1.4 KiB
TypeScript

import type { PageProps } from './types'
import { createEffect, createMemo, createSignal, onCleanup, Show } from 'solid-js'
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'
import { loadShoutsSearch, resetSortedArticles } from '../stores/zine/articles'
export const SearchPage = (props: PageProps) => {
const [isLoaded, setIsLoaded] = createSignal(Boolean(props.searchResults))
const { t } = useLocalize()
const { page } = useRouter()
const q = createMemo(() => page().params['q'] as string)
createEffect(async () => {
if (isLoaded()) return
if (q() && window) {
const text = q() || window.location.href.split('/').pop()
// TODO: pagination, load more
await loadShoutsSearch({ text, limit: 50, offset: 0 })
setIsLoaded(true)
}
})
onCleanup(() => resetSortedArticles())
return (
<PageLayout title={t('Search')}>
<ReactionsProvider>
<Show when={isLoaded()} fallback={<Loading />}>
<SearchView results={props.searchResults || []} query={props.searchQuery} />
</Show>
</ReactionsProvider>
</PageLayout>
)
}
export const Page = SearchPage