From d1874ea55fe1f33a7cedf8327d7fb4615ef19b34 Mon Sep 17 00:00:00 2001 From: dog Date: Sun, 21 Jan 2024 17:02:25 +0300 Subject: [PATCH] fix check errors --- .../Nav/SearchModal/SearchModal.tsx | 55 ++++++++++--------- src/utils/apiClient.ts | 10 ++-- 2 files changed, 33 insertions(+), 32 deletions(-) diff --git a/src/components/Nav/SearchModal/SearchModal.tsx b/src/components/Nav/SearchModal/SearchModal.tsx index d118dcc0..227d2641 100644 --- a/src/components/Nav/SearchModal/SearchModal.tsx +++ b/src/components/Nav/SearchModal/SearchModal.tsx @@ -18,9 +18,33 @@ import styles from './SearchModal.module.scss' const getSearchCoincidences = ({ str, intersection }: { str: string; intersection: string }) => `${str.replace( new RegExp(intersection, 'gi'), - (casePreservedMatch) => `${casePreservedMatch}` + (casePreservedMatch) => `${casePreservedMatch}`, )}` +const prepareSearchResults = (list, searchValue) => + list.map((article, index) => ({ + ...article, + body: '', + cover: '', + createdAt: '', + id: index, + slug: article.slug, + authors: [], + topics: [], + title: article.title + ? getSearchCoincidences({ + str: article.title, + intersection: searchValue, + }) + : '', + subtitle: article.subtitle + ? getSearchCoincidences({ + str: article.subtitle, + intersection: searchValue, + }) + : '', + })) + export const SearchModal = () => { const { t } = useLocalize() @@ -39,29 +63,8 @@ export const SearchModal = () => { const response = await apiClient.getSearchResults(searchValue) const searchResult = await response.json() - if (searchResult.length) { - const preparedSearchResultsList = searchResult.map((article, index) => ({ - ...article, - body: '', - cover: '', - createdAt: '', - id: index, - slug: article.slug, - authors: [], - topics: [], - title: article.title - ? getSearchCoincidences({ - str: article.title, - intersection: searchValue - }) - : '', - subtitle: article.subtitle - ? getSearchCoincidences({ - str: article.subtitle, - intersection: searchValue - }) - : '' - })) + if (searchResult.length > 0) { + const preparedSearchResultsList = prepareSearchResults(searchResult, searchValue) setSearchResultsList(preparedSearchResultsList) } else { @@ -97,7 +100,7 @@ export const SearchModal = () => {

@@ -112,7 +115,7 @@ export const SearchModal = () => { noimage: true, // @@TODO remove flag after cover support isFloorImportant: true, isSingle: true, - nodate: true + nodate: true, }} /> diff --git a/src/utils/apiClient.ts b/src/utils/apiClient.ts index 0af55c05..362c727d 100644 --- a/src/utils/apiClient.ts +++ b/src/utils/apiClient.ts @@ -446,14 +446,12 @@ export const apiClient = { // search getSearchResults: async (searchValue: string) => { - const resp = await fetch(`${searchUrl}/search?q=${searchValue}`, { + return await fetch(`${searchUrl}/search?q=${searchValue}`, { method: 'GET', headers: { accept: 'application/json', - 'content-type': 'application/json; charset=utf-8' - } + 'content-type': 'application/json; charset=utf-8', + }, }) - - return resp - } + }, }