mirror of
https://github.com/oceanprotocol/market.git
synced 2024-12-02 05:57:29 +01:00
Merge pull request #400 from oceanprotocol/feature/issue392
Search filter bar
This commit is contained in:
commit
feef24ddd9
@ -1,17 +1,27 @@
|
|||||||
|
.filterList,
|
||||||
|
div.filterList {
|
||||||
|
white-space: normal;
|
||||||
|
margin-bottom: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.filter {
|
||||||
|
display: inline-block;
|
||||||
|
}
|
||||||
|
|
||||||
.filter,
|
.filter,
|
||||||
button.filter,
|
button.filter,
|
||||||
.filter:hover,
|
.filter:hover,
|
||||||
.filter:active,
|
.filter:active,
|
||||||
.filter:focus {
|
.filter:focus {
|
||||||
border: 1px solid var(--border-color);
|
border: 1px solid var(--border-color);
|
||||||
text-transform: uppercase;
|
|
||||||
border-radius: var(--border-radius);
|
border-radius: var(--border-radius);
|
||||||
margin-right: calc(var(--spacer) / 6);
|
margin-right: calc(var(--spacer) / 6);
|
||||||
|
margin-bottom: calc(var(--spacer) / 6);
|
||||||
color: var(--color-secondary);
|
color: var(--color-secondary);
|
||||||
background: var(--background-content);
|
background: var(--background-content);
|
||||||
|
|
||||||
/* the only thing not possible to overwrite button style="text" with more specifity of selectors, so sledgehammer */
|
/* the only thing not possible to overwrite button style="text" with more specifity of selectors, so sledgehammer */
|
||||||
padding: calc(var(--spacer) / 5) !important;
|
padding: calc(var(--spacer) / 6) !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
.filter:hover,
|
.filter:hover,
|
||||||
@ -27,6 +37,20 @@ button.filter,
|
|||||||
border-color: var(--background-body);
|
border-color: var(--background-body);
|
||||||
}
|
}
|
||||||
|
|
||||||
.filterList:first-of-type {
|
.filter.selected::after {
|
||||||
margin-bottom: calc(var(--spacer) / 6);
|
content: '✕';
|
||||||
|
margin-left: calc(var(--spacer) / 6);
|
||||||
|
color: var(--background-body);
|
||||||
|
}
|
||||||
|
|
||||||
|
.showClear {
|
||||||
|
display: inline-flex;
|
||||||
|
text-transform: capitalize;
|
||||||
|
color: var(--color-secondary);
|
||||||
|
font-weight: var(--font-weight-base);
|
||||||
|
margin-left: calc(var(--spacer) / 6);
|
||||||
|
}
|
||||||
|
|
||||||
|
.hideClear {
|
||||||
|
display: none !important;
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import React, { ReactElement } from 'react'
|
import React, { ReactElement, useEffect, useState } from 'react'
|
||||||
import { useNavigate } from '@reach/router'
|
import { useNavigate } from '@reach/router'
|
||||||
import styles from './filterPrice.module.css'
|
import styles from './filterPrice.module.css'
|
||||||
import classNames from 'classnames/bind'
|
import classNames from 'classnames/bind'
|
||||||
@ -11,22 +11,22 @@ import Button from '../../atoms/Button'
|
|||||||
|
|
||||||
const cx = classNames.bind(styles)
|
const cx = classNames.bind(styles)
|
||||||
|
|
||||||
const filterItemsPrice = [
|
const clearFilters = [{ display: 'Clear', value: '' }]
|
||||||
{ display: 'all', value: undefined },
|
|
||||||
|
const priceFilterItems = [
|
||||||
{ display: 'fixed price', value: FilterByPriceOptions.Fixed },
|
{ display: 'fixed price', value: FilterByPriceOptions.Fixed },
|
||||||
{ display: 'dynamic price', value: FilterByPriceOptions.Dynamic }
|
{ display: 'dynamic price', value: FilterByPriceOptions.Dynamic }
|
||||||
]
|
]
|
||||||
|
|
||||||
const filterItemsType = [
|
const serviceFilterItems = [
|
||||||
{ display: 'all', value: undefined },
|
{ display: 'data sets', value: FilterByTypeOptions.Data },
|
||||||
{ display: 'algorithms', value: FilterByTypeOptions.Algorithm },
|
{ display: 'algorithms', value: FilterByTypeOptions.Algorithm }
|
||||||
{ display: 'data sets', value: FilterByTypeOptions.Data }
|
|
||||||
]
|
]
|
||||||
|
|
||||||
export default function FilterPrice({
|
export default function FilterPrice({
|
||||||
priceType,
|
priceType,
|
||||||
setPriceType,
|
|
||||||
serviceType,
|
serviceType,
|
||||||
|
setPriceType,
|
||||||
setServiceType
|
setServiceType
|
||||||
}: {
|
}: {
|
||||||
priceType: string
|
priceType: string
|
||||||
@ -36,7 +36,10 @@ export default function FilterPrice({
|
|||||||
}): ReactElement {
|
}): ReactElement {
|
||||||
const navigate = useNavigate()
|
const navigate = useNavigate()
|
||||||
|
|
||||||
async function applyFilter(filterBy: string) {
|
const [priceSelections, setPriceSelections] = useState<string[]>([])
|
||||||
|
const [serviceSelections, setServiceSelections] = useState<string[]>([])
|
||||||
|
|
||||||
|
async function applyPriceFilter(filterBy: string) {
|
||||||
let urlLocation = await addExistingParamsToUrl(location, 'priceType')
|
let urlLocation = await addExistingParamsToUrl(location, 'priceType')
|
||||||
if (filterBy) {
|
if (filterBy) {
|
||||||
urlLocation = `${urlLocation}&priceType=${filterBy}`
|
urlLocation = `${urlLocation}&priceType=${filterBy}`
|
||||||
@ -45,59 +48,141 @@ export default function FilterPrice({
|
|||||||
navigate(urlLocation)
|
navigate(urlLocation)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function applyTypeFilter(filterBy: string) {
|
async function applyServiceFilter(filterBy: string) {
|
||||||
let urlLocation = await addExistingParamsToUrl(location, 'serviceType')
|
let urlLocation = await addExistingParamsToUrl(location, 'serviceType')
|
||||||
if (filterBy) {
|
if (filterBy && location.search.indexOf('&serviceType') === -1) {
|
||||||
urlLocation = `${urlLocation}&serviceType=${filterBy}`
|
urlLocation = `${urlLocation}&serviceType=${filterBy}`
|
||||||
}
|
}
|
||||||
setServiceType(filterBy)
|
setServiceType(filterBy)
|
||||||
navigate(urlLocation)
|
navigate(urlLocation)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function handleSelectedFilter(isSelected: boolean, value: string) {
|
||||||
|
if (
|
||||||
|
value === FilterByPriceOptions.Fixed ||
|
||||||
|
value === FilterByPriceOptions.Dynamic
|
||||||
|
) {
|
||||||
|
if (isSelected) {
|
||||||
|
if (priceSelections.length > 1) {
|
||||||
|
// both selected -> select the other one
|
||||||
|
const otherValue = priceFilterItems.find((p) => p.value !== value)
|
||||||
|
.value
|
||||||
|
await applyPriceFilter(otherValue)
|
||||||
|
} else {
|
||||||
|
// only the current one selected -> deselect it
|
||||||
|
await applyPriceFilter(undefined)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (priceSelections.length > 0) {
|
||||||
|
// one already selected -> both selected
|
||||||
|
await applyPriceFilter(FilterByPriceOptions.All)
|
||||||
|
setPriceSelections(priceFilterItems.map((p) => p.value))
|
||||||
|
} else {
|
||||||
|
// none selected -> select
|
||||||
|
await applyPriceFilter(value)
|
||||||
|
setPriceSelections([value])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (isSelected) {
|
||||||
|
if (serviceSelections.length > 1) {
|
||||||
|
const otherValue = serviceFilterItems.find((p) => p.value !== value)
|
||||||
|
.value
|
||||||
|
await applyServiceFilter(otherValue)
|
||||||
|
setServiceSelections([otherValue])
|
||||||
|
} else {
|
||||||
|
await applyServiceFilter(undefined)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (serviceSelections.length) {
|
||||||
|
await applyServiceFilter(undefined)
|
||||||
|
setServiceSelections(serviceFilterItems.map((p) => p.value))
|
||||||
|
} else {
|
||||||
|
await applyServiceFilter(value)
|
||||||
|
setServiceSelections([value])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function applyClearFilter() {
|
||||||
|
let urlLocation = await addExistingParamsToUrl(
|
||||||
|
location,
|
||||||
|
'priceType',
|
||||||
|
'serviceType'
|
||||||
|
)
|
||||||
|
|
||||||
|
urlLocation = `${urlLocation}`
|
||||||
|
|
||||||
|
setServiceSelections([])
|
||||||
|
setPriceSelections([])
|
||||||
|
|
||||||
|
setPriceType(undefined)
|
||||||
|
setServiceType(undefined)
|
||||||
|
navigate(urlLocation)
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div className={styles.filterList}>
|
||||||
<div className={styles.filterList}>
|
{priceFilterItems.map((e, index) => {
|
||||||
{filterItemsType.map((e, index) => {
|
const isPriceSelected =
|
||||||
const filter = cx({
|
e.value === priceType || priceSelections.includes(e.value)
|
||||||
[styles.selected]: e.value === serviceType,
|
const selectFilter = cx({
|
||||||
[styles.filter]: true
|
[styles.selected]: isPriceSelected,
|
||||||
})
|
[styles.filter]: true
|
||||||
return (
|
})
|
||||||
<Button
|
return (
|
||||||
size="small"
|
<Button
|
||||||
style="text"
|
size="small"
|
||||||
key={index}
|
style="text"
|
||||||
className={filter}
|
key={index}
|
||||||
onClick={async () => {
|
className={selectFilter}
|
||||||
await applyTypeFilter(e.value)
|
onClick={async () => {
|
||||||
}}
|
handleSelectedFilter(isPriceSelected, e.value)
|
||||||
>
|
}}
|
||||||
{e.display}
|
>
|
||||||
</Button>
|
{e.display}
|
||||||
)
|
</Button>
|
||||||
})}
|
)
|
||||||
</div>
|
})}
|
||||||
<div className={styles.filterList}>
|
{serviceFilterItems.map((e, index) => {
|
||||||
{filterItemsPrice.map((e, index) => {
|
const isServiceSelected =
|
||||||
const filter = cx({
|
e.value === serviceType || serviceSelections.includes(e.value)
|
||||||
[styles.selected]: e.value === priceType,
|
const selectFilter = cx({
|
||||||
[styles.filter]: true
|
[styles.selected]: isServiceSelected,
|
||||||
})
|
[styles.filter]: true
|
||||||
return (
|
})
|
||||||
<Button
|
return (
|
||||||
size="small"
|
<Button
|
||||||
style="text"
|
size="small"
|
||||||
key={index}
|
style="text"
|
||||||
className={filter}
|
key={index}
|
||||||
onClick={async () => {
|
className={selectFilter}
|
||||||
await applyFilter(e.value)
|
onClick={async () => {
|
||||||
}}
|
handleSelectedFilter(isServiceSelected, e.value)
|
||||||
>
|
}}
|
||||||
{e.display}
|
>
|
||||||
</Button>
|
{e.display}
|
||||||
)
|
</Button>
|
||||||
})}
|
)
|
||||||
</div>
|
})}
|
||||||
|
{clearFilters.map((e, index) => {
|
||||||
|
const showClear =
|
||||||
|
priceSelections.length > 0 || serviceSelections.length > 0
|
||||||
|
return (
|
||||||
|
<Button
|
||||||
|
size="small"
|
||||||
|
style="text"
|
||||||
|
key={index}
|
||||||
|
className={showClear ? styles.showClear : styles.hideClear}
|
||||||
|
onClick={async () => {
|
||||||
|
applyClearFilter()
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{e.display}
|
||||||
|
</Button>
|
||||||
|
)
|
||||||
|
})}
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,7 @@ export default function SearchPage({
|
|||||||
const [queryResult, setQueryResult] = useState<QueryResult>()
|
const [queryResult, setQueryResult] = useState<QueryResult>()
|
||||||
const [loading, setLoading] = useState<boolean>()
|
const [loading, setLoading] = useState<boolean>()
|
||||||
const [price, setPriceType] = useState<string>(priceType as string)
|
const [price, setPriceType] = useState<string>(priceType as string)
|
||||||
const [type, setType] = useState<string>(serviceType as string)
|
const [service, setServiceType] = useState<string>(serviceType as string)
|
||||||
const [sortType, setSortType] = useState<string>(sort as string)
|
const [sortType, setSortType] = useState<string>(sort as string)
|
||||||
const [sortDirection, setSortDirection] = useState<string>(
|
const [sortDirection, setSortDirection] = useState<string>(
|
||||||
sortOrder as string
|
sortOrder as string
|
||||||
@ -82,9 +82,9 @@ export default function SearchPage({
|
|||||||
<div className={styles.row}>
|
<div className={styles.row}>
|
||||||
<PriceFilter
|
<PriceFilter
|
||||||
priceType={price}
|
priceType={price}
|
||||||
|
serviceType={service}
|
||||||
setPriceType={setPriceType}
|
setPriceType={setPriceType}
|
||||||
serviceType={type}
|
setServiceType={setServiceType}
|
||||||
setServiceType={setType}
|
|
||||||
/>
|
/>
|
||||||
<Sort
|
<Sort
|
||||||
sortType={sortType}
|
sortType={sortType}
|
||||||
@ -92,6 +92,7 @@ export default function SearchPage({
|
|||||||
setSortType={setSortType}
|
setSortType={setSortType}
|
||||||
setSortDirection={setSortDirection}
|
setSortDirection={setSortDirection}
|
||||||
setPriceType={setPriceType}
|
setPriceType={setPriceType}
|
||||||
|
setServiceType={setServiceType}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -1,11 +1,18 @@
|
|||||||
.sortList {
|
.sortList {
|
||||||
align-self: flex-end;
|
padding: 0 calc(var(--spacer) / 10);
|
||||||
padding: calc(var(--spacer) / 10);
|
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
border-radius: var(--border-radius);
|
border-radius: var(--border-radius);
|
||||||
border: 1px solid var(--border-color);
|
border: 1px solid var(--border-color);
|
||||||
background: var(--background-content);
|
background: var(--background-content);
|
||||||
|
overflow-y: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (min-width: 40rem) {
|
||||||
|
.sortList {
|
||||||
|
align-self: flex-end;
|
||||||
|
overflow-y: unset;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.sortLabel {
|
.sortLabel {
|
||||||
@ -15,6 +22,7 @@
|
|||||||
margin-right: calc(var(--spacer) / 1.5);
|
margin-right: calc(var(--spacer) / 1.5);
|
||||||
text-transform: uppercase;
|
text-transform: uppercase;
|
||||||
color: var(--color-secondary);
|
color: var(--color-secondary);
|
||||||
|
font-size: var(--font-size-small);
|
||||||
}
|
}
|
||||||
|
|
||||||
.sorted {
|
.sorted {
|
||||||
@ -25,7 +33,7 @@
|
|||||||
text-transform: capitalize;
|
text-transform: capitalize;
|
||||||
border-radius: 0;
|
border-radius: 0;
|
||||||
font-weight: var(--font-weight-base);
|
font-weight: var(--font-weight-base);
|
||||||
background: var(--background-body);
|
background: var(--background-content);
|
||||||
box-shadow: none;
|
box-shadow: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,13 +24,15 @@ export default function Sort({
|
|||||||
setSortType,
|
setSortType,
|
||||||
sortDirection,
|
sortDirection,
|
||||||
setSortDirection,
|
setSortDirection,
|
||||||
setPriceType
|
setPriceType,
|
||||||
|
setServiceType
|
||||||
}: {
|
}: {
|
||||||
sortType: string
|
sortType: string
|
||||||
setSortType: React.Dispatch<React.SetStateAction<string>>
|
setSortType: React.Dispatch<React.SetStateAction<string>>
|
||||||
sortDirection: string
|
sortDirection: string
|
||||||
setSortDirection: React.Dispatch<React.SetStateAction<string>>
|
setSortDirection: React.Dispatch<React.SetStateAction<string>>
|
||||||
setPriceType: React.Dispatch<React.SetStateAction<string>>
|
setPriceType: React.Dispatch<React.SetStateAction<string>>
|
||||||
|
setServiceType: React.Dispatch<React.SetStateAction<string>>
|
||||||
}): ReactElement {
|
}): ReactElement {
|
||||||
const navigate = useNavigate()
|
const navigate = useNavigate()
|
||||||
const directionArrow = String.fromCharCode(
|
const directionArrow = String.fromCharCode(
|
||||||
@ -44,8 +46,6 @@ export default function Sort({
|
|||||||
if (sortBy === SortTermOptions.Liquidity) {
|
if (sortBy === SortTermOptions.Liquidity) {
|
||||||
urlLocation = `${urlLocation}&priceType=${FilterByPriceOptions.Dynamic}`
|
urlLocation = `${urlLocation}&priceType=${FilterByPriceOptions.Dynamic}`
|
||||||
setPriceType(FilterByPriceOptions.Dynamic)
|
setPriceType(FilterByPriceOptions.Dynamic)
|
||||||
} else {
|
|
||||||
setPriceType(undefined)
|
|
||||||
}
|
}
|
||||||
setSortType(sortBy)
|
setSortType(sortBy)
|
||||||
} else if (direction) {
|
} else if (direction) {
|
||||||
|
@ -28,7 +28,8 @@ type SortValueOptions = typeof SortValueOptions[keyof typeof SortValueOptions]
|
|||||||
|
|
||||||
export const FilterByPriceOptions = {
|
export const FilterByPriceOptions = {
|
||||||
Fixed: 'exchange',
|
Fixed: 'exchange',
|
||||||
Dynamic: 'pool'
|
Dynamic: 'pool',
|
||||||
|
All: 'all'
|
||||||
} as const
|
} as const
|
||||||
type FilterByPriceOptions = typeof FilterByPriceOptions[keyof typeof FilterByPriceOptions]
|
type FilterByPriceOptions = typeof FilterByPriceOptions[keyof typeof FilterByPriceOptions]
|
||||||
|
|
||||||
@ -38,12 +39,20 @@ export const FilterByTypeOptions = {
|
|||||||
} as const
|
} as const
|
||||||
type FilterByTypeOptions = typeof FilterByTypeOptions[keyof typeof FilterByTypeOptions]
|
type FilterByTypeOptions = typeof FilterByTypeOptions[keyof typeof FilterByTypeOptions]
|
||||||
|
|
||||||
function addPriceFilterToQuerry(sortTerm: string, priceFilter: string): string {
|
function addPriceFilterToQuery(sortTerm: string, priceFilter: string): string {
|
||||||
sortTerm = priceFilter
|
if (priceFilter === FilterByPriceOptions.All) {
|
||||||
? sortTerm === ''
|
sortTerm = priceFilter
|
||||||
? `price.type:${priceFilter}`
|
? sortTerm === ''
|
||||||
: `${sortTerm} AND price.type:${priceFilter}`
|
? `(price.type:${FilterByPriceOptions.Fixed} OR price.type:${FilterByPriceOptions.Dynamic})`
|
||||||
: sortTerm
|
: `${sortTerm} AND (price.type:${FilterByPriceOptions.Dynamic} OR price.type:${FilterByPriceOptions.Fixed})`
|
||||||
|
: sortTerm
|
||||||
|
} else {
|
||||||
|
sortTerm = priceFilter
|
||||||
|
? sortTerm === ''
|
||||||
|
? `price.type:${priceFilter}`
|
||||||
|
: `${sortTerm} AND price.type:${priceFilter}`
|
||||||
|
: sortTerm
|
||||||
|
}
|
||||||
return sortTerm
|
return sortTerm
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,9 +98,9 @@ export function getSearchQuery(
|
|||||||
? // eslint-disable-next-line no-useless-escape
|
? // eslint-disable-next-line no-useless-escape
|
||||||
`(service.attributes.additionalInformation.categories:\"${categories}\")`
|
`(service.attributes.additionalInformation.categories:\"${categories}\")`
|
||||||
: text || ''
|
: text || ''
|
||||||
searchTerm = addPriceFilterToQuerry(searchTerm, priceType)
|
|
||||||
searchTerm = addTypeFilterToQuery(searchTerm, serviceType)
|
searchTerm = addTypeFilterToQuery(searchTerm, serviceType)
|
||||||
console.log('search', searchTerm, serviceType)
|
searchTerm = addPriceFilterToQuery(searchTerm, priceType)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
page: Number(page) || 1,
|
page: Number(page) || 1,
|
||||||
offset: Number(offset) || 21,
|
offset: Number(offset) || 21,
|
||||||
|
@ -27,7 +27,7 @@ export default function PageGatsbySearch(props: PageProps): ReactElement {
|
|||||||
(totalResults > 1 ? ' results' : ' result') +
|
(totalResults > 1 ? ' results' : ' result') +
|
||||||
' for ' +
|
' for ' +
|
||||||
searchValue
|
searchValue
|
||||||
: totalResults + ' datasets'
|
: totalResults + ' results'
|
||||||
: 'Searching...'
|
: 'Searching...'
|
||||||
}`
|
}`
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user