mirror of
https://github.com/oceanprotocol/commons.git
synced 2023-03-15 18:03:00 +01:00
code style
This commit is contained in:
parent
dfe07d13b3
commit
0751ff2a6b
@ -5,16 +5,16 @@ import { User } from '../../context/User'
|
|||||||
import AssetDetails from './AssetDetails'
|
import AssetDetails from './AssetDetails'
|
||||||
import stylesApp from '../../App.module.scss'
|
import stylesApp from '../../App.module.scss'
|
||||||
|
|
||||||
|
interface DetailsProps {
|
||||||
|
location: Location
|
||||||
|
match: any
|
||||||
|
}
|
||||||
|
|
||||||
interface DetailsState {
|
interface DetailsState {
|
||||||
ddo: any
|
ddo: any
|
||||||
metadata: { base: { name: string } }
|
metadata: { base: { name: string } }
|
||||||
}
|
}
|
||||||
|
|
||||||
interface DetailsProps {
|
|
||||||
location: any
|
|
||||||
match: any
|
|
||||||
}
|
|
||||||
|
|
||||||
export default class Details extends Component<DetailsProps, DetailsState> {
|
export default class Details extends Component<DetailsProps, DetailsState> {
|
||||||
public state = { ddo: {}, metadata: { base: { name: '' } } }
|
public state = { ddo: {}, metadata: { base: { name: '' } } }
|
||||||
|
|
||||||
|
@ -8,14 +8,14 @@ import styles from './Home.module.scss'
|
|||||||
|
|
||||||
import meta from '../data/meta.json'
|
import meta from '../data/meta.json'
|
||||||
|
|
||||||
interface HomeState {
|
|
||||||
search?: string
|
|
||||||
}
|
|
||||||
|
|
||||||
interface HomeProps {
|
interface HomeProps {
|
||||||
history: any
|
history: any
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface HomeState {
|
||||||
|
search?: string
|
||||||
|
}
|
||||||
|
|
||||||
class Home extends Component<HomeProps, HomeState> {
|
class Home extends Component<HomeProps, HomeState> {
|
||||||
public state = { search: '' }
|
public state = { search: '' }
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import React, { Component } from 'react'
|
import React, { PureComponent } from 'react'
|
||||||
import queryString from 'query-string'
|
import queryString from 'query-string'
|
||||||
import { Logger } from '@oceanprotocol/squid'
|
import { Logger } from '@oceanprotocol/squid'
|
||||||
import Spinner from '../components/atoms/Spinner'
|
import Spinner from '../components/atoms/Spinner'
|
||||||
@ -7,27 +7,36 @@ import { User } from '../context/User'
|
|||||||
import Asset from '../components/molecules/Asset'
|
import Asset from '../components/molecules/Asset'
|
||||||
import styles from './Search.module.scss'
|
import styles from './Search.module.scss'
|
||||||
|
|
||||||
interface SearchState {
|
|
||||||
results: any[]
|
|
||||||
isLoading: boolean
|
|
||||||
}
|
|
||||||
|
|
||||||
interface SearchProps {
|
interface SearchProps {
|
||||||
location: any
|
location: Location
|
||||||
history: any
|
history: History
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class Search extends Component<SearchProps, SearchState> {
|
interface SearchState {
|
||||||
public state = { results: [], isLoading: true, page: 0 }
|
assets: any[]
|
||||||
|
isLoading: boolean
|
||||||
|
page: number
|
||||||
|
}
|
||||||
|
|
||||||
public async componentDidMount() {
|
export default class Search extends PureComponent<SearchProps, SearchState> {
|
||||||
const searchParams = queryString.parse(this.props.location.search)
|
public state = {
|
||||||
const { text } = searchParams
|
assets: [],
|
||||||
|
isLoading: true,
|
||||||
|
page: 0
|
||||||
|
}
|
||||||
|
|
||||||
|
private readonly searchTerm = queryString.parse(this.props.location.search)
|
||||||
|
.text
|
||||||
|
|
||||||
|
public componentDidMount() {
|
||||||
|
this.searchAssets()
|
||||||
|
}
|
||||||
|
|
||||||
|
private searchAssets = async () => {
|
||||||
const searchQuery = {
|
const searchQuery = {
|
||||||
text,
|
text: this.searchTerm,
|
||||||
offset: 100,
|
offset: 100,
|
||||||
page: 0,
|
page: this.state.page,
|
||||||
query: {
|
query: {
|
||||||
price: [-1, 1]
|
price: [-1, 1]
|
||||||
},
|
},
|
||||||
@ -39,16 +48,16 @@ export default class Search extends Component<SearchProps, SearchState> {
|
|||||||
const assets = await this.context.ocean.aquarius.queryMetadataByText(
|
const assets = await this.context.ocean.aquarius.queryMetadataByText(
|
||||||
searchQuery
|
searchQuery
|
||||||
)
|
)
|
||||||
this.setState({ results: assets, isLoading: false })
|
this.setState({ assets, isLoading: false })
|
||||||
Logger.log(`Loaded ${assets.length} assets`)
|
Logger.log(`Loaded ${assets.length} assets`)
|
||||||
}
|
}
|
||||||
|
|
||||||
public renderResults = () =>
|
public renderResults = () =>
|
||||||
this.state.isLoading ? (
|
this.state.isLoading ? (
|
||||||
<Spinner message="Searching..." />
|
<Spinner message="Searching..." />
|
||||||
) : this.state.results.length ? (
|
) : this.state.assets.length ? (
|
||||||
<div className={styles.results}>
|
<div className={styles.results}>
|
||||||
{this.state.results.map((asset: any) => (
|
{this.state.assets.map((asset: any) => (
|
||||||
<Asset key={asset.id} asset={asset} />
|
<Asset key={asset.id} asset={asset} />
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
@ -57,11 +66,9 @@ export default class Search extends Component<SearchProps, SearchState> {
|
|||||||
)
|
)
|
||||||
|
|
||||||
public render() {
|
public render() {
|
||||||
const searchTerm = queryString.parse(this.props.location.search).text
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Route
|
<Route
|
||||||
title={`Search Results for <span>${searchTerm}</span>`}
|
title={`Search Results for <span>${this.searchTerm}</span>`}
|
||||||
titleReverse
|
titleReverse
|
||||||
wide
|
wide
|
||||||
>
|
>
|
||||||
|
Loading…
Reference in New Issue
Block a user