webapp/src/components/Views/Search.tsx

85 lines
2.3 KiB
TypeScript
Raw Normal View History

2022-09-09 11:53:35 +00:00
import { Show, For, createSignal, createMemo } from 'solid-js'
import '../../styles/Search.scss'
import type { Shout } from '../../graphql/types.gen'
import { ArticleCard } from '../Feed/Card'
import { t } from '../../utils/intl'
2022-09-09 13:30:25 +00:00
import { params } from '../../stores/router'
2022-09-13 09:59:04 +00:00
import { useArticlesStore, loadSearchResults } from '../../stores/zine/articles'
2022-09-09 13:30:25 +00:00
import { useStore } from '@nanostores/solid'
2022-09-09 11:53:35 +00:00
type Props = {
2022-09-13 09:59:04 +00:00
query: string
2022-09-09 11:53:35 +00:00
results: Shout[]
}
export const SearchPage = (props: Props) => {
2022-09-09 13:30:25 +00:00
const args = useStore(params)
2022-09-09 11:53:35 +00:00
const { getSortedArticles } = useArticlesStore({ sortedArticles: props.results })
2022-09-13 09:59:04 +00:00
const [getQuery, setQuery] = createSignal(props.query)
2022-09-09 11:53:35 +00:00
2022-09-13 09:59:04 +00:00
const handleQueryChange = (ev) => {
setQuery(ev.target.value)
}
const handleSubmit = (ev) => {
// TODO page
// TODO sort
loadSearchResults({ query: getQuery() })
}
2022-09-09 11:53:35 +00:00
return (
<div class="search-page wide-container">
<form action="/search" class="search-form row">
<div class="col-sm-9">
2022-09-13 13:38:26 +00:00
{/*FIXME t*/}
2022-09-13 09:59:04 +00:00
<input type="search" name="q" onChange={handleQueryChange} placeholder="Введите текст..." />
2022-09-09 11:53:35 +00:00
</div>
<div class="col-sm-3">
2022-09-13 09:59:04 +00:00
<button class="button" type="submit" onClick={handleSubmit}>
{t('Search')}
</button>
2022-09-09 11:53:35 +00:00
</div>
</form>
<ul class="view-switcher">
<li class="selected">
2022-09-09 13:30:25 +00:00
<a href="?by=relevance" onClick={() => (args()['by'] = 'relevance')}>
2022-09-09 11:53:35 +00:00
{t('By relevance')}
</a>
</li>
<li>
2022-09-09 13:30:25 +00:00
<a href="?by=rating" onClick={() => (args()['by'] = 'rating')}>
2022-09-09 11:53:35 +00:00
{t('Top rated')}
</a>
</li>
</ul>
<Show when={getSortedArticles().length > 0}>
<h3>{t('Publications')}</h3>
<div class="floor">
<div class="row">
<For each={getSortedArticles()}>
{(article) => (
<div class="col-md-3">
<ArticleCard article={article} />
</div>
)}
</For>
<div class="col-md-3">
<a href="#" class="search__show-more">
<span class="search__show-more-inner">{t('Load more')}</span>
</a>
</div>
</div>
</div>
<h3>{t('Topics')}</h3>
<h3>{t('Authors')}</h3>
</Show>
</div>
)
}