fix check errors
This commit is contained in:
parent
32ee6e062b
commit
d1874ea55f
|
@ -18,9 +18,33 @@ import styles from './SearchModal.module.scss'
|
||||||
const getSearchCoincidences = ({ str, intersection }: { str: string; intersection: string }) =>
|
const getSearchCoincidences = ({ str, intersection }: { str: string; intersection: string }) =>
|
||||||
`<span>${str.replace(
|
`<span>${str.replace(
|
||||||
new RegExp(intersection, 'gi'),
|
new RegExp(intersection, 'gi'),
|
||||||
(casePreservedMatch) => `<span class="blackModeIntersection">${casePreservedMatch}</span>`
|
(casePreservedMatch) => `<span class="blackModeIntersection">${casePreservedMatch}</span>`,
|
||||||
)}</span>`
|
)}</span>`
|
||||||
|
|
||||||
|
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 = () => {
|
export const SearchModal = () => {
|
||||||
const { t } = useLocalize()
|
const { t } = useLocalize()
|
||||||
|
|
||||||
|
@ -39,29 +63,8 @@ export const SearchModal = () => {
|
||||||
const response = await apiClient.getSearchResults(searchValue)
|
const response = await apiClient.getSearchResults(searchValue)
|
||||||
const searchResult = await response.json()
|
const searchResult = await response.json()
|
||||||
|
|
||||||
if (searchResult.length) {
|
if (searchResult.length > 0) {
|
||||||
const preparedSearchResultsList = searchResult.map((article, index) => ({
|
const preparedSearchResultsList = prepareSearchResults(searchResult, searchValue)
|
||||||
...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
|
|
||||||
})
|
|
||||||
: ''
|
|
||||||
}))
|
|
||||||
|
|
||||||
setSearchResultsList(preparedSearchResultsList)
|
setSearchResultsList(preparedSearchResultsList)
|
||||||
} else {
|
} else {
|
||||||
|
@ -97,7 +100,7 @@ export const SearchModal = () => {
|
||||||
<p
|
<p
|
||||||
class={styles.searchDescription}
|
class={styles.searchDescription}
|
||||||
innerHTML={t(
|
innerHTML={t(
|
||||||
'To find publications, art, comments, authors and topics of interest to you, just start typing your query'
|
'To find publications, art, comments, authors and topics of interest to you, just start typing your query',
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
@ -112,7 +115,7 @@ export const SearchModal = () => {
|
||||||
noimage: true, // @@TODO remove flag after cover support
|
noimage: true, // @@TODO remove flag after cover support
|
||||||
isFloorImportant: true,
|
isFloorImportant: true,
|
||||||
isSingle: true,
|
isSingle: true,
|
||||||
nodate: true
|
nodate: true,
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -446,14 +446,12 @@ export const apiClient = {
|
||||||
|
|
||||||
// search
|
// search
|
||||||
getSearchResults: async (searchValue: string) => {
|
getSearchResults: async (searchValue: string) => {
|
||||||
const resp = await fetch(`${searchUrl}/search?q=${searchValue}`, {
|
return await fetch(`${searchUrl}/search?q=${searchValue}`, {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
headers: {
|
headers: {
|
||||||
accept: 'application/json',
|
accept: 'application/json',
|
||||||
'content-type': 'application/json; charset=utf-8'
|
'content-type': 'application/json; charset=utf-8',
|
||||||
}
|
},
|
||||||
})
|
})
|
||||||
|
},
|
||||||
return resp
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user