mirror of
https://github.com/oceanprotocol/market.git
synced 2024-12-02 05:57:29 +01:00
restore pagination
This commit is contained in:
parent
77db807ae8
commit
2b90f0b08e
@ -14,6 +14,8 @@ const AssetTeaser: React.FC<AssetTeaserProps> = ({
|
|||||||
did,
|
did,
|
||||||
metadata
|
metadata
|
||||||
}: AssetTeaserProps) => {
|
}: AssetTeaserProps) => {
|
||||||
|
if (!metadata.additionalInformation) return null
|
||||||
|
|
||||||
const { name, price } = metadata.main
|
const { name, price } = metadata.main
|
||||||
const { description, access } = metadata.additionalInformation
|
const { description, access } = metadata.additionalInformation
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
margin-top: -1px;
|
margin-top: -1px;
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
border: 1px solid var(--brand-grey-light);
|
border: 1px solid var(--brand-grey-lighter);
|
||||||
min-width: 3.5rem;
|
min-width: 3.5rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import React, { useState, useEffect } from 'react'
|
import React, { useState, useEffect, ReactElement } from 'react'
|
||||||
import ReactPaginate from 'react-paginate'
|
import ReactPaginate from 'react-paginate'
|
||||||
import styles from './Pagination.module.css'
|
import styles from './Pagination.module.css'
|
||||||
|
|
||||||
@ -14,7 +14,9 @@ export default function Pagination({
|
|||||||
currentPage,
|
currentPage,
|
||||||
hrefBuilder,
|
hrefBuilder,
|
||||||
onPageChange
|
onPageChange
|
||||||
}: PaginationProps) {
|
}: PaginationProps): ReactElement {
|
||||||
|
if (!totalPages || totalPages < 2) return null
|
||||||
|
|
||||||
const [smallViewport, setSmallViewport] = useState(true)
|
const [smallViewport, setSmallViewport] = useState(true)
|
||||||
|
|
||||||
function viewportChange(mq: { matches: boolean }) {
|
function viewportChange(mq: { matches: boolean }) {
|
||||||
@ -31,7 +33,7 @@ export default function Pagination({
|
|||||||
}
|
}
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
return totalPages > 1 ? (
|
return (
|
||||||
<ReactPaginate
|
<ReactPaginate
|
||||||
pageCount={totalPages}
|
pageCount={totalPages}
|
||||||
// react-pagination starts counting at 0, we start at 1
|
// react-pagination starts counting at 0, we start at 1
|
||||||
@ -53,5 +55,5 @@ export default function Pagination({
|
|||||||
disabledClassName={styles.prevNextDisabled}
|
disabledClassName={styles.prevNextDisabled}
|
||||||
breakLinkClassName={styles.break}
|
breakLinkClassName={styles.break}
|
||||||
/>
|
/>
|
||||||
) : null
|
)
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import AssetTeaser from '../molecules/AssetTeaser'
|
import AssetTeaser from '../molecules/AssetTeaser'
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
import { QueryResult } from '@oceanprotocol/lib/dist/node/metadatastore/MetadataStore'
|
import { QueryResult } from '@oceanprotocol/lib/dist/node/metadatastore/MetadataStore'
|
||||||
|
import { useLocation, useNavigate } from '@reach/router'
|
||||||
import Pagination from '../molecules/Pagination'
|
import Pagination from '../molecules/Pagination'
|
||||||
import { updateQueryStringParameter } from '../../utils'
|
import { updateQueryStringParameter } from '../../utils'
|
||||||
import styles from './AssetList.module.css'
|
import styles from './AssetList.module.css'
|
||||||
@ -14,38 +15,39 @@ declare type AssetListProps = {
|
|||||||
|
|
||||||
const AssetList: React.FC<AssetListProps> = ({ queryResult }) => {
|
const AssetList: React.FC<AssetListProps> = ({ queryResult }) => {
|
||||||
const { appConfig } = useSiteMetadata()
|
const { appConfig } = useSiteMetadata()
|
||||||
// TODO: restore Pagination behavior
|
const location = useLocation()
|
||||||
|
const navigate = useNavigate()
|
||||||
|
|
||||||
// Construct the urls on the pagination links. This is only for UX,
|
// Construct the urls on the pagination links. This is only for UX,
|
||||||
// since the links are no <Link> they will not work by itself.
|
// since the links are no <Link> they will not work by itself.
|
||||||
// function hrefBuilder(pageIndex: number) {
|
function hrefBuilder(pageIndex: number) {
|
||||||
// const newUrl = updateQueryStringParameter(
|
const newUrl = updateQueryStringParameter(
|
||||||
// router.asPath,
|
location.pathname + location.search,
|
||||||
// 'page',
|
'page',
|
||||||
// `${pageIndex}`
|
`${pageIndex}`
|
||||||
// )
|
)
|
||||||
// return newUrl
|
return newUrl
|
||||||
// }
|
}
|
||||||
|
|
||||||
// // This is what iniitates a new search with new `page`
|
// // This is what iniitates a new search with new `page`
|
||||||
// // url parameter
|
// // url parameter
|
||||||
// function onPageChange(selected: number) {
|
function onPageChange(selected: number) {
|
||||||
// const newUrl = updateQueryStringParameter(
|
const newUrl = updateQueryStringParameter(
|
||||||
// router.asPath,
|
location.pathname + location.search,
|
||||||
// 'page',
|
'page',
|
||||||
// `${selected + 1}`
|
`${selected + 1}`
|
||||||
// )
|
)
|
||||||
// return router.push(newUrl)
|
return navigate(newUrl)
|
||||||
// }
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div className={styles.assetList}>
|
<div className={styles.assetList}>
|
||||||
{queryResult && queryResult.totalResults > 0 ? (
|
{queryResult && queryResult.totalResults > 0 ? (
|
||||||
queryResult.results.map((ddo: DDO) => {
|
queryResult.results.map((ddo: DDO) => {
|
||||||
const { attributes }: MetaDataMarket = new DDO(
|
const { attributes }: MetaDataMarket = ddo.findServiceByType(
|
||||||
ddo
|
'metadata'
|
||||||
).findServiceByType('metadata')
|
)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<AssetTeaser did={ddo.id} metadata={attributes} key={ddo.id} />
|
<AssetTeaser did={ddo.id} metadata={attributes} key={ddo.id} />
|
||||||
@ -57,12 +59,19 @@ const AssetList: React.FC<AssetListProps> = ({ queryResult }) => {
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
{/* <Pagination
|
|
||||||
totalPages={queryResult.totalPages}
|
{/*
|
||||||
currentPage={queryResult.page}
|
Little hack cause the pagination navigation only works
|
||||||
hrefBuilder={hrefBuilder}
|
on the search page right now.
|
||||||
onPageChange={onPageChange}
|
*/}
|
||||||
/> */}
|
{location.pathname === '/search' && queryResult && (
|
||||||
|
<Pagination
|
||||||
|
totalPages={queryResult.totalPages}
|
||||||
|
currentPage={queryResult.page}
|
||||||
|
hrefBuilder={hrefBuilder}
|
||||||
|
onPageChange={onPageChange}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,6 @@ import { QueryResult } from '@oceanprotocol/lib/dist/node/metadatastore/Metadata
|
|||||||
import SearchBar from '../../molecules/SearchBar'
|
import SearchBar from '../../molecules/SearchBar'
|
||||||
import AssetList from '../../organisms/AssetList'
|
import AssetList from '../../organisms/AssetList'
|
||||||
import { SearchPriceFilter } from '../../molecules/SearchPriceFilter'
|
import { SearchPriceFilter } from '../../molecules/SearchPriceFilter'
|
||||||
|
|
||||||
import styles from './index.module.css'
|
import styles from './index.module.css'
|
||||||
import queryString from 'query-string'
|
import queryString from 'query-string'
|
||||||
import { getResults } from './utils'
|
import { getResults } from './utils'
|
||||||
@ -21,7 +20,7 @@ export default function SearchPage({
|
|||||||
location: Location
|
location: Location
|
||||||
}): ReactElement {
|
}): ReactElement {
|
||||||
const parsed = queryString.parse(location.search)
|
const parsed = queryString.parse(location.search)
|
||||||
const { text, tag } = parsed
|
const { text, tag, page } = parsed
|
||||||
const [queryResult, setQueryResult] = useState<QueryResult>()
|
const [queryResult, setQueryResult] = useState<QueryResult>()
|
||||||
const [loading, setLoading] = useState<boolean>()
|
const [loading, setLoading] = useState<boolean>()
|
||||||
|
|
||||||
@ -33,7 +32,7 @@ export default function SearchPage({
|
|||||||
setLoading(false)
|
setLoading(false)
|
||||||
}
|
}
|
||||||
initSearch()
|
initSearch()
|
||||||
}, [text, tag])
|
}, [text, tag, page])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<section className={styles.grid}>
|
<section className={styles.grid}>
|
||||||
|
Loading…
Reference in New Issue
Block a user