render search results & refactor search modal

This commit is contained in:
dog 2024-01-09 16:37:35 +03:00
parent f520de9d52
commit c78d5b3337
3 changed files with 68 additions and 62 deletions

View File

@ -88,6 +88,13 @@
position: relative; position: relative;
text-align: left; text-align: left;
&::-webkit-scrollbar {
display: none;
}
-ms-overflow-style: none; /* IE and Edge */
scrollbar-width: none; /* Firefox */
@include media-breakpoint-up(sm) { @include media-breakpoint-up(sm) {
padding: 5rem; padding: 5rem;
} }

View File

@ -45,6 +45,11 @@
&:not(:placeholder-shown) + .searchButton img { &:not(:placeholder-shown) + .searchButton img {
filter: invert(1); filter: invert(1);
} }
&::-moz-selection,
&::selection {
color: #2638d9;
}
} }
.searchButton { .searchButton {
@ -61,6 +66,7 @@
} }
.searchDescription { .searchDescription {
margin-bottom: 44px;
@include font-size(1.6rem); @include font-size(1.6rem);
color: rgb(255 255 255 / 0.64); color: rgb(255 255 255 / 0.64);

View File

@ -1,4 +1,3 @@
import clsx from 'clsx'
import { createSignal, Show, For } from 'solid-js' import { createSignal, Show, For } from 'solid-js'
import { ArticleCard } from '../../Feed/ArticleCard' import { ArticleCard } from '../../Feed/ArticleCard'
@ -10,16 +9,18 @@ import type { Shout } from '../../../graphql/types.gen'
import { searchUrl } from '../../../utils/config' import { searchUrl } from '../../../utils/config'
import { useLocalize } from '../../../context/localize' import { useLocalize } from '../../../context/localize'
import { hideModal } from '../../../stores/ui'
import styles from './SearchModal.module.scss' import styles from './SearchModal.module.scss'
// @@TODO handle founded shouts rendering (cors) // @@TODO handle empty article options after backend support (subtitle, cover, etc.)
// @@TODO implement load more (await ...({ filters: { .. }, limit: .., offset: .. })) // @@TODO implement load more
// @@TODO implement FILTERS & TOPICS
const getSearchCoincidences = ({ str, intersection }) => const getSearchCoincidences = ({ str, intersection }: { str: string; intersection: string }) =>
`<span>${str.replace( `<span>${str.replace(
new RegExp(intersection, 'g'), new RegExp(intersection, 'gi'),
`<span class="blackModeIntersection">${intersection}</span>` (casePreservedMatch) => `<span class="blackModeIntersection">${casePreservedMatch}</span>`
)}</span>` )}</span>`
export const SearchModal = () => { export const SearchModal = () => {
@ -28,8 +29,8 @@ export const SearchModal = () => {
const searchInputRef: { current: HTMLInputElement } = { current: null } const searchInputRef: { current: HTMLInputElement } = { current: null }
const [searchResultsList, setSearchResultsList] = createSignal<[] | null>([]) const [searchResultsList, setSearchResultsList] = createSignal<[] | null>([])
const [isLoadMoreButtonVisible, setIsLoadMoreButtonVisible] = createSignal(false)
const [isLoading, setIsLoading] = createSignal(false) const [isLoading, setIsLoading] = createSignal(false)
// const [isLoadMoreButtonVisible, setIsLoadMoreButtonVisible] = createSignal(false)
const handleSearch = async () => { const handleSearch = async () => {
const searchValue = searchInputRef.current?.value || '' const searchValue = searchInputRef.current?.value || ''
@ -46,25 +47,34 @@ export const SearchModal = () => {
}) })
.then((data) => data.json()) .then((data) => data.json())
.then((data) => { .then((data) => {
// if (data.what) { if (data.length) {
// const preparedSearchResultsList = data.what.map((article) => ({ const preparedSearchResultsList = data.map((article, index) => ({
// ...article, ...article,
// title: getSearchCoincidences({ body: '',
// str: article.title, cover: '',
// intersection: searchInputRef.current?.value || '' createdAt: '',
// }), id: index,
// subtitle: getSearchCoincidences({ slug: article.slug,
// str: article.subtitle, authors: [],
// intersection: searchInputRef.current?.value || '' topics: [],
// }), title: article.title
// })) ? getSearchCoincidences({
// str: article.title,
// setSearchResultsList(preparedSearchResultsList) intersection: searchInputRef.current?.value || ''
// })
// @@TODO handle setIsLoadMoreButtonVisible() : '',
// } else { subtitle: article.subtitle
// setSearchResultsList(null) ? getSearchCoincidences({
// } str: article.subtitle,
intersection: searchInputRef.current?.value || ''
})
: ''
}))
setSearchResultsList(preparedSearchResultsList)
} else {
setSearchResultsList(null)
}
}) })
.catch((error) => { .catch((error) => {
console.log('search request failed', error) console.log('search request failed', error)
@ -75,7 +85,9 @@ export const SearchModal = () => {
} }
} }
const loadMore = () => {} const handleArticleClick = () => {
hideModal()
}
return ( return (
<div class={styles.searchContainer}> <div class={styles.searchContainer}>
@ -100,50 +112,31 @@ export const SearchModal = () => {
)} )}
/> />
{/* <Show when={!isLoading()}> */} <Show when={!isLoading()}>
<Show when={false}> <Show when={searchResultsList()}>
<Show when={searchResultsList().length}> <For each={searchResultsList()}>
{/* <For each={searchResultsList()}> */}
<For
each={[
{
body: 'body',
cover: 'production/image/bbad6b10-9b44-11ee-bdef-5758f9198f7d.png',
createdAt: '12',
id: 12,
slug: '/about',
authors: [
{
id: 1,
name: 'author',
slug: '/'
}
],
title: 'asas',
subtitle: 'asas',
topics: []
}
]}
>
{(article: Shout) => ( {(article: Shout) => (
<ArticleCard <div onClick={handleArticleClick}>
article={article} <ArticleCard
settings={{ article={article}
isFloorImportant: true, settings={{
isSingle: true, noimage: true, // @@TODO remove flag after cover support
nodate: true isFloorImportant: true,
}} isSingle: true,
/> nodate: true
}}
/>
</div>
)} )}
</For> </For>
<Show when={isLoadMoreButtonVisible()}> {/* <Show when={isLoadMoreButtonVisible()}>
<p class="load-more-container"> <p class="load-more-container">
<button class="button" onClick={loadMore}> <button class="button" onClick={loadMore}>
{t('Load more')} {t('Load more')}
</button> </button>
</p> </p>
</Show> </Show> */}
</Show> </Show>
<Show when={!searchResultsList()}> <Show when={!searchResultsList()}>