Skip to content

Commit

Permalink
CORE: add condition (#353)
Browse files Browse the repository at this point in the history
* CORE: add condition

* lint
  • Loading branch information
ekachxaidze98 authored Nov 12, 2024
1 parent 4dd776d commit 5b656b9
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 13 deletions.
6 changes: 4 additions & 2 deletions api/data-provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ const requestV3 = (url, ...args) => request(`${API_V3_URL}${url}`, ...args)

// eslint-disable-next-line camelcase
const fetchMetadata = async (id, search_id) => {
// eslint-disable-next-line camelcase
const { data } = await requestV3(`/data-providers/${id}?t=${search_id}`)
const { data } = await requestV3(
// eslint-disable-next-line camelcase
`/data-providers/${id}${search_id ? `?t=${search_id}` : ''}`
)
return data
}

Expand Down
8 changes: 7 additions & 1 deletion api/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@ import apiRequest from './index'
const FileDownload = require('js-file-download')

export const fetchWorks = async (body) => {
const url = new URL(`/v3/search/works`, process.env.API_URL).href
// eslint-disable-next-line camelcase
const { search_id } = body
const url = new URL(
// eslint-disable-next-line camelcase
`/v3/search/works${search_id ? `?t=${search_id}` : ''}`,
process.env.API_URL
).href
const { data: dataWorks } = await apiRequest(url, {
body,
method: 'POST',
Expand Down
8 changes: 5 additions & 3 deletions api/works.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ import apiRequest from './index'

// eslint-disable-next-line camelcase
const fetchWork = async (id, search_id) => {
// eslint-disable-next-line camelcase
const url = new URL(`/v3/works/${id}?t=${search_id}`, process.env.API_URL)
.href
const url = new URL(
// eslint-disable-next-line camelcase
`/v3/works/${id}${search_id ? `?t=${search_id}` : ''}`,
process.env.API_URL
).href

const { data } = await apiRequest(url)
return data
Expand Down
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion pages/search/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,12 @@ export const getServerSideProps = async ({ query: searchParams }) => {
q,
offset,
limit,
t,
exclude: ['fullText'],
sort: sort === 'recent' ? 'recency' : sort,
}

if (t) body.t = t

try {
const response = await fetchWorks(body)

Expand Down
1 change: 1 addition & 0 deletions templates/search/results.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ const Results = ({ works, searchId }) =>
className={styles.searchResults}
useLogo={!!checkBillingType()}
searchId={searchId}
renderRedirectLink
data={{
workId: id,
title,
Expand Down

0 comments on commit 5b656b9

Please sign in to comment.