1
0
mirror of https://github.com/oceanprotocol/market.git synced 2024-07-01 06:11:43 +02:00
market/src/components/templates/Search/index.tsx

108 lines
3.1 KiB
TypeScript
Raw Normal View History

2020-07-01 18:13:32 +02:00
import React, { ReactElement, useState, useEffect } from 'react'
Issue 582 market rbac integration (#597) * adding env for RBAC server url to app.config.js * creating util function for requesting auth from the rbac server * fixing typing error * testing rbac request on homepage * removing console logs * importing RBAC url from config file * creating develpment .env file * return true if no rbac url env is set * creating permissions parent component * wrapping homepage content in permission element * wrapping publish in permissions wrapper * wrapping search results in permissions wrapper * wrapping asset actions in permissions element * creating an error alert for permission denied * updating react hook dependency * passing address to rbac component * sedning address to RBAC server * wrapping asset in permission component * removing unused import of Permission component * sending request based on address * chaning default permission case to restrict access * updating eventType as consume * Adding loader icon while waiting form permission response * only sending request to RBAC if address is defined * adding wallet connection info message * changing the env name and checking for undefined * updating .env.development * Check for undefined RBAC_URL in permissions component * removing .env.development and updating .env.example * updating .env.example comment * switching alert messages and reducing return statements * removing console.log message * fixing linting issue * Revert "fixing linting issue" This reverts commit 8bcb80be3d1ae32731b8c5b81b393dd614017fdc. * Fixing linting errors * pull from origin main * Revert "pull from origin main" This reverts commit 9535e41a5f5acfa26d2841942c29695855dd65bc.
2021-06-10 11:06:26 +02:00
import Permission from '../../organisms/Permission'
import AssetList from '../../organisms/AssetList'
2020-07-01 18:13:32 +02:00
import queryString from 'query-string'
import Filters from './Filters'
import Sort from './sort'
import { getResults } from './utils'
import { navigate } from 'gatsby'
import { updateQueryStringParameter } from '../../../utils'
2021-05-31 14:27:04 +02:00
import { useSiteMetadata } from '../../../hooks/useSiteMetadata'
import { useUserPreferences } from '../../../providers/UserPreferences'
import axios from 'axios'
import styles from './index.module.css'
2020-07-01 18:13:32 +02:00
export default function SearchPage({
location,
setTotalResults,
setTotalPagesNumber
2020-07-01 18:13:32 +02:00
}: {
location: Location
setTotalResults: (totalResults: number) => void
setTotalPagesNumber: (totalPagesNumber: number) => void
2020-07-01 18:13:32 +02:00
}): ReactElement {
2021-05-31 14:27:04 +02:00
const { appConfig } = useSiteMetadata()
2020-07-01 18:13:32 +02:00
const parsed = queryString.parse(location.search)
const { text, owner, tags, page, sort, sortOrder, serviceType, accessType } =
parsed
const { chainIds } = useUserPreferences()
const [queryResult, setQueryResult] = useState<any>()
2020-07-15 15:47:25 +02:00
const [loading, setLoading] = useState<boolean>()
const [service, setServiceType] = useState<string>(serviceType as string)
const [access, setAccessType] = useState<string>(accessType as string)
const [sortType, setSortType] = useState<string>(sort as string)
const [sortDirection, setSortDirection] = useState<string>(
sortOrder as string
)
2020-07-01 18:13:32 +02:00
useEffect(() => {
const source = axios.CancelToken.source()
2020-07-01 18:13:32 +02:00
async function initSearch() {
2020-07-15 15:47:25 +02:00
setLoading(true)
setTotalResults(undefined)
const queryResult = await getResults(parsed, chainIds, source.token)
2020-07-07 23:00:16 +02:00
setQueryResult(queryResult)
setTotalResults(queryResult.totalResults)
setTotalPagesNumber(queryResult.totalPages)
2020-07-15 15:33:45 +02:00
setLoading(false)
2020-07-01 18:13:32 +02:00
}
initSearch()
return () => {
source.cancel()
}
2021-05-31 14:27:04 +02:00
}, [
text,
owner,
tags,
sort,
page,
serviceType,
accessType,
2021-05-31 14:27:04 +02:00
sortOrder,
chainIds
2021-05-31 14:27:04 +02:00
])
2020-07-01 18:13:32 +02:00
function setPage(page: number) {
const newUrl = updateQueryStringParameter(
location.pathname + location.search,
'page',
`${page}`
)
return navigate(newUrl)
}
2020-07-01 18:13:32 +02:00
return (
Issue 582 market rbac integration (#597) * adding env for RBAC server url to app.config.js * creating util function for requesting auth from the rbac server * fixing typing error * testing rbac request on homepage * removing console logs * importing RBAC url from config file * creating develpment .env file * return true if no rbac url env is set * creating permissions parent component * wrapping homepage content in permission element * wrapping publish in permissions wrapper * wrapping search results in permissions wrapper * wrapping asset actions in permissions element * creating an error alert for permission denied * updating react hook dependency * passing address to rbac component * sedning address to RBAC server * wrapping asset in permission component * removing unused import of Permission component * sending request based on address * chaning default permission case to restrict access * updating eventType as consume * Adding loader icon while waiting form permission response * only sending request to RBAC if address is defined * adding wallet connection info message * changing the env name and checking for undefined * updating .env.development * Check for undefined RBAC_URL in permissions component * removing .env.development and updating .env.example * updating .env.example comment * switching alert messages and reducing return statements * removing console.log message * fixing linting issue * Revert "fixing linting issue" This reverts commit 8bcb80be3d1ae32731b8c5b81b393dd614017fdc. * Fixing linting errors * pull from origin main * Revert "pull from origin main" This reverts commit 9535e41a5f5acfa26d2841942c29695855dd65bc.
2021-06-10 11:06:26 +02:00
<Permission eventType="browse">
<>
<div className={styles.search}>
<div className={styles.row}>
<Filters
Issue 582 market rbac integration (#597) * adding env for RBAC server url to app.config.js * creating util function for requesting auth from the rbac server * fixing typing error * testing rbac request on homepage * removing console logs * importing RBAC url from config file * creating develpment .env file * return true if no rbac url env is set * creating permissions parent component * wrapping homepage content in permission element * wrapping publish in permissions wrapper * wrapping search results in permissions wrapper * wrapping asset actions in permissions element * creating an error alert for permission denied * updating react hook dependency * passing address to rbac component * sedning address to RBAC server * wrapping asset in permission component * removing unused import of Permission component * sending request based on address * chaning default permission case to restrict access * updating eventType as consume * Adding loader icon while waiting form permission response * only sending request to RBAC if address is defined * adding wallet connection info message * changing the env name and checking for undefined * updating .env.development * Check for undefined RBAC_URL in permissions component * removing .env.development and updating .env.example * updating .env.example comment * switching alert messages and reducing return statements * removing console.log message * fixing linting issue * Revert "fixing linting issue" This reverts commit 8bcb80be3d1ae32731b8c5b81b393dd614017fdc. * Fixing linting errors * pull from origin main * Revert "pull from origin main" This reverts commit 9535e41a5f5acfa26d2841942c29695855dd65bc.
2021-06-10 11:06:26 +02:00
serviceType={service}
accessType={access}
Issue 582 market rbac integration (#597) * adding env for RBAC server url to app.config.js * creating util function for requesting auth from the rbac server * fixing typing error * testing rbac request on homepage * removing console logs * importing RBAC url from config file * creating develpment .env file * return true if no rbac url env is set * creating permissions parent component * wrapping homepage content in permission element * wrapping publish in permissions wrapper * wrapping search results in permissions wrapper * wrapping asset actions in permissions element * creating an error alert for permission denied * updating react hook dependency * passing address to rbac component * sedning address to RBAC server * wrapping asset in permission component * removing unused import of Permission component * sending request based on address * chaning default permission case to restrict access * updating eventType as consume * Adding loader icon while waiting form permission response * only sending request to RBAC if address is defined * adding wallet connection info message * changing the env name and checking for undefined * updating .env.development * Check for undefined RBAC_URL in permissions component * removing .env.development and updating .env.example * updating .env.example comment * switching alert messages and reducing return statements * removing console.log message * fixing linting issue * Revert "fixing linting issue" This reverts commit 8bcb80be3d1ae32731b8c5b81b393dd614017fdc. * Fixing linting errors * pull from origin main * Revert "pull from origin main" This reverts commit 9535e41a5f5acfa26d2841942c29695855dd65bc.
2021-06-10 11:06:26 +02:00
setServiceType={setServiceType}
setAccessType={setAccessType}
Issue 582 market rbac integration (#597) * adding env for RBAC server url to app.config.js * creating util function for requesting auth from the rbac server * fixing typing error * testing rbac request on homepage * removing console logs * importing RBAC url from config file * creating develpment .env file * return true if no rbac url env is set * creating permissions parent component * wrapping homepage content in permission element * wrapping publish in permissions wrapper * wrapping search results in permissions wrapper * wrapping asset actions in permissions element * creating an error alert for permission denied * updating react hook dependency * passing address to rbac component * sedning address to RBAC server * wrapping asset in permission component * removing unused import of Permission component * sending request based on address * chaning default permission case to restrict access * updating eventType as consume * Adding loader icon while waiting form permission response * only sending request to RBAC if address is defined * adding wallet connection info message * changing the env name and checking for undefined * updating .env.development * Check for undefined RBAC_URL in permissions component * removing .env.development and updating .env.example * updating .env.example comment * switching alert messages and reducing return statements * removing console.log message * fixing linting issue * Revert "fixing linting issue" This reverts commit 8bcb80be3d1ae32731b8c5b81b393dd614017fdc. * Fixing linting errors * pull from origin main * Revert "pull from origin main" This reverts commit 9535e41a5f5acfa26d2841942c29695855dd65bc.
2021-06-10 11:06:26 +02:00
/>
<Sort
sortType={sortType}
sortDirection={sortDirection}
setSortType={setSortType}
setSortDirection={setSortDirection}
/>
</div>
</div>
<div className={styles.results}>
<AssetList
assets={queryResult?.results}
showPagination
isLoading={loading}
page={queryResult?.page}
totalPages={queryResult?.totalPages}
onPageChange={setPage}
/>
</div>
Issue 582 market rbac integration (#597) * adding env for RBAC server url to app.config.js * creating util function for requesting auth from the rbac server * fixing typing error * testing rbac request on homepage * removing console logs * importing RBAC url from config file * creating develpment .env file * return true if no rbac url env is set * creating permissions parent component * wrapping homepage content in permission element * wrapping publish in permissions wrapper * wrapping search results in permissions wrapper * wrapping asset actions in permissions element * creating an error alert for permission denied * updating react hook dependency * passing address to rbac component * sedning address to RBAC server * wrapping asset in permission component * removing unused import of Permission component * sending request based on address * chaning default permission case to restrict access * updating eventType as consume * Adding loader icon while waiting form permission response * only sending request to RBAC if address is defined * adding wallet connection info message * changing the env name and checking for undefined * updating .env.development * Check for undefined RBAC_URL in permissions component * removing .env.development and updating .env.example * updating .env.example comment * switching alert messages and reducing return statements * removing console.log message * fixing linting issue * Revert "fixing linting issue" This reverts commit 8bcb80be3d1ae32731b8c5b81b393dd614017fdc. * Fixing linting errors * pull from origin main * Revert "pull from origin main" This reverts commit 9535e41a5f5acfa26d2841942c29695855dd65bc.
2021-06-10 11:06:26 +02:00
</>
</Permission>
2020-07-01 18:13:32 +02:00
)
}