-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add pagefind proxy and fix eslint error on babel react plugin * add prefetchAuthors component to load all authors bio in memory * add Order by keys in contstns * add Pagefind ! * add accented letters to regex param * Update index.css * remove React from topDocuments * Create SearchSummary.jsx * AuthorItem now gets a specific TO param for the link router * Create PagefindMatch.jsx
- Loading branch information
1 parent
2f4b5d7
commit 7d936be
Showing
15 changed files
with
463 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { useEffect, useState } from 'react' | ||
|
||
const PagefindMatch = ({ id, getData, children }) => { | ||
const [result, setResult] = useState(null) | ||
|
||
useEffect(() => { | ||
async function fetchData() { | ||
// You can await here | ||
const result = await getData() | ||
// ... | ||
setResult(result) | ||
} | ||
fetchData() | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [id]) | ||
|
||
return <div>{result ? <>{children(result)}</> : <div>Loading...</div>}</div> | ||
} | ||
|
||
export default PagefindMatch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { useEffect } from 'react' | ||
import { useGetJSON } from '../hooks/data' | ||
import { useStore } from '../store' | ||
|
||
const PrefetchAuthors = () => { | ||
// load authro data from api | ||
const { | ||
data: authorMetadata, | ||
status, | ||
error, | ||
} = useGetJSON({ | ||
url: `/api/author/`, | ||
params: { | ||
limit: 1000, | ||
}, | ||
delay: 1000, | ||
}) | ||
|
||
const setAuthors = useStore((state) => state.setAuthors) | ||
if (error) { | ||
console.warn('[PrefetchAuthors] error:', error) | ||
} | ||
useEffect(() => { | ||
if (status !== 'success') { | ||
return | ||
} | ||
console.info('[PrefetchAuthors] authorMetadata:', authorMetadata) | ||
setAuthors(authorMetadata.results) | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [status]) | ||
} | ||
|
||
export default PrefetchAuthors |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { useTranslation } from 'react-i18next' | ||
import { useStore } from '../store' | ||
import { X } from 'react-feather' | ||
|
||
const SearchSummary = ({ q = '', author = '', count = 0, setQuery }) => { | ||
const { t, i18n } = useTranslation() | ||
const languageCode = i18n.language.split('-').join('_') | ||
const authorsIndex = useStore((state) => state.authorsIndex) | ||
const authorMetadata = authorsIndex[author] | ||
let authorName = authorMetadata?.fullname || author | ||
try { | ||
authorName = authorMetadata?.data?.fullname[languageCode] || authorMetadata?.fullname || author | ||
} catch (e) { | ||
console.warn('[SearchSummary] authorName error:', e) | ||
} | ||
return ( | ||
<div className="Biographies_summary"> | ||
{q.length === 0 && ( | ||
<> | ||
{author.length ? ( | ||
<p> | ||
<span | ||
dangerouslySetInnerHTML={{ | ||
__html: t('biographiesCountWithAuthor', { | ||
n: count, | ||
q, | ||
author: authorName, | ||
}), | ||
}} | ||
/> | ||
<button | ||
onClick={() => setQuery({ author: undefined })} | ||
className="btn btn-transparent d-inline p-0 btn-sm" | ||
> | ||
<X /> | ||
</button> | ||
</p> | ||
) : ( | ||
<p | ||
dangerouslySetInnerHTML={{ | ||
__html: t('biographiesCount', { n: count, q }), | ||
}} | ||
/> | ||
)} | ||
</> | ||
)} | ||
{q.length > 0 && ( | ||
<> | ||
{author.length ? ( | ||
<p> | ||
<span | ||
dangerouslySetInnerHTML={{ | ||
__html: t('biographiesCountWithQueryAndAuthor', { | ||
n: count, | ||
q, | ||
author: authorName, | ||
}), | ||
}} | ||
/> | ||
<button | ||
onClick={() => setQuery({ author: undefined })} | ||
className="btn btn-transparent d-inline p-0 btn-sm" | ||
> | ||
<X /> | ||
</button> | ||
</p> | ||
) : ( | ||
<p | ||
dangerouslySetInnerHTML={{ | ||
__html: t('biographiesCountWithQuery', { n: count, q }), | ||
}} | ||
/> | ||
)} | ||
</> | ||
)} | ||
</div> | ||
) | ||
} | ||
|
||
export default SearchSummary |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.