From c78d5b33374d94ab7aa1b288f3f111f35f9d81bd Mon Sep 17 00:00:00 2001 From: dog Date: Tue, 9 Jan 2024 16:37:35 +0300 Subject: [PATCH] render search results & refactor search modal --- src/components/Nav/Modal/Modal.module.scss | 7 ++ .../Nav/SearchModal/SearchModal.module.scss | 6 + .../Nav/SearchModal/SearchModal.tsx | 117 ++++++++---------- 3 files changed, 68 insertions(+), 62 deletions(-) diff --git a/src/components/Nav/Modal/Modal.module.scss b/src/components/Nav/Modal/Modal.module.scss index 8e99ddc6..3b34b8e3 100644 --- a/src/components/Nav/Modal/Modal.module.scss +++ b/src/components/Nav/Modal/Modal.module.scss @@ -88,6 +88,13 @@ position: relative; text-align: left; + &::-webkit-scrollbar { + display: none; + } + + -ms-overflow-style: none; /* IE and Edge */ + scrollbar-width: none; /* Firefox */ + @include media-breakpoint-up(sm) { padding: 5rem; } diff --git a/src/components/Nav/SearchModal/SearchModal.module.scss b/src/components/Nav/SearchModal/SearchModal.module.scss index 0a7e40ec..1dbc5039 100644 --- a/src/components/Nav/SearchModal/SearchModal.module.scss +++ b/src/components/Nav/SearchModal/SearchModal.module.scss @@ -45,6 +45,11 @@ &:not(:placeholder-shown) + .searchButton img { filter: invert(1); } + + &::-moz-selection, + &::selection { + color: #2638d9; + } } .searchButton { @@ -61,6 +66,7 @@ } .searchDescription { + margin-bottom: 44px; @include font-size(1.6rem); color: rgb(255 255 255 / 0.64); diff --git a/src/components/Nav/SearchModal/SearchModal.tsx b/src/components/Nav/SearchModal/SearchModal.tsx index e756edef..d31ce669 100644 --- a/src/components/Nav/SearchModal/SearchModal.tsx +++ b/src/components/Nav/SearchModal/SearchModal.tsx @@ -1,4 +1,3 @@ -import clsx from 'clsx' import { createSignal, Show, For } from 'solid-js' import { ArticleCard } from '../../Feed/ArticleCard' @@ -10,16 +9,18 @@ import type { Shout } from '../../../graphql/types.gen' import { searchUrl } from '../../../utils/config' import { useLocalize } from '../../../context/localize' +import { hideModal } from '../../../stores/ui' import styles from './SearchModal.module.scss' -// @@TODO handle founded shouts rendering (cors) -// @@TODO implement load more (await ...({ filters: { .. }, limit: .., offset: .. })) +// @@TODO handle empty article options after backend support (subtitle, cover, etc.) +// @@TODO implement load more +// @@TODO implement FILTERS & TOPICS -const getSearchCoincidences = ({ str, intersection }) => +const getSearchCoincidences = ({ str, intersection }: { str: string; intersection: string }) => `${str.replace( - new RegExp(intersection, 'g'), - `${intersection}` + new RegExp(intersection, 'gi'), + (casePreservedMatch) => `${casePreservedMatch}` )}` export const SearchModal = () => { @@ -28,8 +29,8 @@ export const SearchModal = () => { const searchInputRef: { current: HTMLInputElement } = { current: null } const [searchResultsList, setSearchResultsList] = createSignal<[] | null>([]) - const [isLoadMoreButtonVisible, setIsLoadMoreButtonVisible] = createSignal(false) const [isLoading, setIsLoading] = createSignal(false) + // const [isLoadMoreButtonVisible, setIsLoadMoreButtonVisible] = createSignal(false) const handleSearch = async () => { const searchValue = searchInputRef.current?.value || '' @@ -46,25 +47,34 @@ export const SearchModal = () => { }) .then((data) => data.json()) .then((data) => { - // if (data.what) { - // const preparedSearchResultsList = data.what.map((article) => ({ - // ...article, - // title: getSearchCoincidences({ - // str: article.title, - // intersection: searchInputRef.current?.value || '' - // }), - // subtitle: getSearchCoincidences({ - // str: article.subtitle, - // intersection: searchInputRef.current?.value || '' - // }), - // })) - // - // setSearchResultsList(preparedSearchResultsList) - // - // @@TODO handle setIsLoadMoreButtonVisible() - // } else { - // setSearchResultsList(null) - // } + if (data.length) { + const preparedSearchResultsList = data.map((article, index) => ({ + ...article, + body: '', + cover: '', + createdAt: '', + id: index, + slug: article.slug, + authors: [], + topics: [], + title: article.title + ? getSearchCoincidences({ + str: article.title, + intersection: searchInputRef.current?.value || '' + }) + : '', + subtitle: article.subtitle + ? getSearchCoincidences({ + str: article.subtitle, + intersection: searchInputRef.current?.value || '' + }) + : '' + })) + + setSearchResultsList(preparedSearchResultsList) + } else { + setSearchResultsList(null) + } }) .catch((error) => { console.log('search request failed', error) @@ -75,7 +85,9 @@ export const SearchModal = () => { } } - const loadMore = () => {} + const handleArticleClick = () => { + hideModal() + } return (
@@ -100,50 +112,31 @@ export const SearchModal = () => { )} /> - {/* */} - - - {/* */} - + + + {(article: Shout) => ( - +
+ +
)}
- + {/*

-
+
*/}