1
0
mirror of https://github.com/oceanprotocol/market.git synced 2024-06-29 00:57:50 +02:00
market/src/components/organisms/AssetQueryList.tsx
Matthias Kretschmann ad107c5415
Data Partners (#214)
* datapartners prototype

* output partner name on asset teasers

* badge, output partner data

* deprioritize pool badge

* teaser spacing tweaks

* styling

* carousel pattern

* carousel fixes

* styling tweaks

* cleanup, useDataPartner hook

* large screen fixes

* add partner badge to all data set list titles

* byline links tweaks

* byline tweaks

* switch list data source

* fixes, link to https://github.com/oceanprotocol/list-datapartners

* refactor

* refactor
2020-11-05 14:43:13 +01:00

81 lines
2.1 KiB
TypeScript

import AssetTeaser from '../molecules/AssetTeaser'
import React from 'react'
import { QueryResult } from '@oceanprotocol/lib/dist/node/metadatacache/MetadataCache'
import { useLocation, useNavigate } from '@reach/router'
import Pagination from '../molecules/Pagination'
import { updateQueryStringParameter } from '../../utils'
import styles from './AssetQueryList.module.css'
import { DDO } from '@oceanprotocol/lib'
import classNames from 'classnames/bind'
const cx = classNames.bind(styles)
declare type AssetQueryListProps = {
queryResult: QueryResult
className?: string
}
const AssetQueryList: React.FC<AssetQueryListProps> = ({
queryResult,
className
}) => {
const location = useLocation()
const navigate = useNavigate()
// Construct the urls on the pagination links. This is only for UX,
// since the links are no <Link> they will not work by itself.
function hrefBuilder(pageIndex: number) {
const newUrl = updateQueryStringParameter(
location.pathname + location.search,
'page',
`${pageIndex}`
)
return newUrl
}
// // This is what iniitates a new search with new `page`
// // url parameter
function onPageChange(selected: number) {
const newUrl = updateQueryStringParameter(
location.pathname + location.search,
'page',
`${selected + 1}`
)
return navigate(newUrl)
}
const styleClasses = cx({
assetList: true,
[className]: className
})
return (
<>
<div className={styleClasses}>
{queryResult?.results.length > 0 ? (
queryResult.results.map((ddo: DDO) => (
<AssetTeaser ddo={ddo} key={ddo.id} />
))
) : (
<div className={styles.empty}>No results found.</div>
)}
</div>
{/*
Little hack cause the pagination navigation only works
on the search page right now.
*/}
{location.pathname === '/search' && queryResult && (
<Pagination
totalPages={queryResult.totalPages}
currentPage={queryResult.page}
hrefBuilder={hrefBuilder}
onPageChange={onPageChange}
/>
)}
</>
)
}
export default AssetQueryList