Skip to content

Commit

Permalink
CORE: add missing param (#352)
Browse files Browse the repository at this point in the history
* CORE: add missing param

* CORE: avoid shadowing
  • Loading branch information
ekachxaidze98 authored Nov 11, 2024
1 parent 108847f commit 4dd776d
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 18 deletions.
12 changes: 2 additions & 10 deletions pages/data-providers/[id].jsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,10 @@ export async function getServerSideProps({
query: searchParams,
}) {
const { id } = routeParams
const {
q = '',
offset = 0,
limit = 10,
sort = 'recency',
// eslint-disable-next-line camelcase
search_id,
} = searchParams
const { q = '', offset = 0, limit = 10, sort = 'recency', t } = searchParams
const data = {}
try {
// eslint-disable-next-line camelcase
const dataProvider = await fetchMetadata(id, search_id)
const dataProvider = await fetchMetadata(id, t)
const dataProviderStats = await fetchStats(id)

Object.assign(data, {
Expand Down
3 changes: 2 additions & 1 deletion pages/search/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const getServerSideProps = async ({ query: searchParams }) => {
}
// TODO for nice response
// const { q, page = 1, limit = 10, sort = 'recency' } = searchParams
const { q, page = 1, limit = 10, sort = 'relevance' } = searchParams
const { q, page = 1, limit = 10, sort = 'relevance', t } = searchParams

const data = {
currentPage: +page,
Expand All @@ -40,6 +40,7 @@ export const getServerSideProps = async ({ query: searchParams }) => {
q,
offset,
limit,
t,
exclude: ['fullText'],
sort: sort === 'recent' ? 'recency' : sort,
}
Expand Down
6 changes: 2 additions & 4 deletions pages/works/[id].jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,12 @@ export async function getServerSideProps({
req,
}) {
const { id } = routeParams
// eslint-disable-next-line camelcase
const { search_id } = searchParams
const { t } = searchParams

const data = {}

try {
// eslint-disable-next-line camelcase
const rawWork = await fetchWork(id, search_id)
const rawWork = await fetchWork(id, t)
const { fullText: _, ...work } = rawWork
const outputs = await fetchWorkOutputs(id)

Expand Down
37 changes: 34 additions & 3 deletions templates/search/results.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,34 @@ const Results = ({ works, searchId }) =>
?.replace(/(https:\/\/)(core\.ac\.uk)/, '$1api.$2')
.replace('/reader/', '/reader-ui/')

const renderFullTextLink = ({
fullTextLink: innerFullTextLink,
downloadLink: innerDownloadLink,
modifiedReaderLink: innerModifiedReaderLink,
searchId: innerSearchId,
id: innerId,
}) => {
if (
innerFullTextLink == null &&
innerDownloadLink == null &&
innerModifiedReaderLink == null
)
return null
if (
(innerFullTextLink && innerFullTextLink.includes('core')) ||
(innerDownloadLink && innerDownloadLink.includes('core')) ||
(innerModifiedReaderLink &&
innerModifiedReaderLink.includes('api.core'))
) {
return generateMetadataLink(
innerModifiedReaderLink,
innerSearchId,
innerId
)
}
if (innerDownloadLink) return innerDownloadLink
return innerFullTextLink
}
return (
<SearchResult
id={`search-output-${id}`}
Expand All @@ -60,10 +88,13 @@ const Results = ({ works, searchId }) =>
metadataLink:
generateMetadataLink(metadataLink, searchId, id) ||
generateMetadataLink(displayLink, searchId, id),
fullTextLink:
generateMetadataLink(modifiedReaderLink, searchId, id) ||
fullTextLink ||
fullTextLink: renderFullTextLink({
fullTextLink,
downloadLink,
modifiedReaderLink,
searchId,
id,
}),
dataProviders: dataProviders || [],
isRecommended: memberType?.billing_type === 'sustaining',
}}
Expand Down

0 comments on commit 4dd776d

Please sign in to comment.