1
0
mirror of https://github.com/oceanprotocol/market.git synced 2024-12-02 05:57:29 +01:00

Merge branch 'main' into feature/enforce-docker-containers

This commit is contained in:
Bogdan Fazakas 2022-10-10 16:18:34 +03:00
commit c030f8ec7e
6 changed files with 106 additions and 5 deletions

View File

@ -6,7 +6,7 @@ export enum SortDirectionOptions {
export enum SortTermOptions {
Created = 'nft.created',
Relevance = '_score',
Stats = 'stats.orders',
Orders = 'stats.orders',
Allocated = 'stats.allocated'
}

View File

@ -305,7 +305,7 @@ export async function getPublishedAssets(
aggs: {
totalOrders: {
sum: {
field: SortTermOptions.Stats
field: SortTermOptions.Orders
}
}
},
@ -359,7 +359,7 @@ export async function getTopPublishers(
aggs: {
totalSales: {
sum: {
field: SortTermOptions.Stats
field: SortTermOptions.Orders
}
}
}

View File

@ -0,0 +1,45 @@
import { LoggerInstance } from '@oceanprotocol/lib'
import { generateBaseQuery, queryMetadata } from '@utils/aquarius'
import axios, { CancelToken } from 'axios'
import { SortTermOptions } from 'src/@types/aquarius/SearchQuery'
export async function getTopTags(
chainIds: number[],
cancelToken: CancelToken
): Promise<string[]> {
const baseQueryParams = {
chainIds,
aggs: {
topTags: {
terms: {
field: 'metadata.tags.keyword',
size: 20,
order: { totalSales: 'desc' }
},
aggs: {
totalSales: {
sum: {
field: SortTermOptions.Orders
}
}
}
}
},
esPaginationOptions: { from: 0, size: 0 }
} as BaseQueryParams
const query = generateBaseQuery(baseQueryParams)
try {
const result = await queryMetadata(query, cancelToken)
const tagsList = result?.aggregations?.topTags?.buckets.map(
(x: { key: any }) => x.key
)
return tagsList
} catch (error) {
if (axios.isCancel(error)) {
LoggerInstance.log(error.message)
} else {
LoggerInstance.error(error.message)
}
}
}

View File

@ -0,0 +1,3 @@
.section {
composes: section from '../index.module.css';
}

View File

@ -0,0 +1,51 @@
import { useUserPreferences } from '@context/UserPreferences'
import React, { ReactElement, useEffect, useState } from 'react'
import styles from './index.module.css'
import Tags from '@shared/atoms/Tags'
import { getTopTags } from './_utils'
import { useCancelToken } from '@hooks/useCancelToken'
import { LoggerInstance } from '@oceanprotocol/lib'
import Loader from '@shared/atoms/Loader'
export default function TopTags({
title,
action
}: {
title: ReactElement | string
action?: ReactElement
}): ReactElement {
const { chainIds } = useUserPreferences()
const [result, setResult] = useState<string[]>([])
const [loading, setLoading] = useState<boolean>()
const newCancelToken = useCancelToken()
useEffect(() => {
async function init() {
setLoading(true)
if (chainIds.length === 0) {
const result: string[] = []
setResult(result)
setLoading(false)
} else {
try {
const tags = await getTopTags(chainIds, newCancelToken())
setResult(tags)
setLoading(false)
} catch (error) {
LoggerInstance.error(error.message)
setLoading(false)
}
}
}
init()
}, [chainIds])
return (
<section className={styles.section}>
<h3>{title}</h3>
{loading ? <Loader /> : <Tags items={result} />}
{action && action}
</section>
)
}

View File

@ -5,8 +5,9 @@ import { generateBaseQuery } from '@utils/aquarius'
import { useUserPreferences } from '@context/UserPreferences'
import { SortTermOptions } from '../../@types/aquarius/SearchQuery'
import TopSales from './TopSales'
import styles from './index.module.css'
import TopTags from './TopTags'
import SectionQueryResult from './SectionQueryResult'
import styles from './index.module.css'
export default function HomePage(): ReactElement {
const [queryLatest, setQueryLatest] = useState<SearchQuery>()
@ -32,7 +33,7 @@ export default function HomePage(): ReactElement {
size: 6
},
sortOptions: {
sortBy: SortTermOptions.Stats
sortBy: SortTermOptions.Orders
} as SortOptions
} as BaseQueryParams
setQueryMostSales(generateBaseQuery(baseParamsSales))
@ -63,6 +64,7 @@ export default function HomePage(): ReactElement {
<SectionQueryResult title="Most Sales" query={queryMostSales} />
<TopSales title="Publishers With Most Sales" />
<TopTags title="Top Tags By Sales" />
<SectionQueryResult
title="Recently Published"