mango-v4-ui/components/explore/Explore.tsx

84 lines
2.4 KiB
TypeScript
Raw Normal View History

2023-11-10 03:36:35 -08:00
import { useEffect, useMemo, useState } from 'react'
2023-10-17 04:28:43 -07:00
import PerpMarketsTable from './PerpMarketsTable'
import { useTranslation } from 'react-i18next'
import dayjs from 'dayjs'
import relativeTime from 'dayjs/plugin/relativeTime'
import mangoStore from '@store/mangoStore'
import RecentGainersLosers from './RecentGainersLosers'
import Spot from './Spot'
2023-11-10 03:36:35 -08:00
import useBanks from 'hooks/useBanks'
import TabsText from '@components/shared/TabsText'
2023-11-13 20:41:16 -08:00
import useFollowedAccounts from 'hooks/useFollowedAccounts'
import FollowedAccounts from './FollowedAccounts'
2023-10-17 04:28:43 -07:00
dayjs.extend(relativeTime)
const Explore = () => {
const { t } = useTranslation(['common'])
2023-11-10 03:36:35 -08:00
const { banks } = useBanks()
2023-11-13 20:41:16 -08:00
const { data: followedAccounts } = useFollowedAccounts()
2023-10-17 04:28:43 -07:00
const perpStats = mangoStore((s) => s.perpStats.data)
2023-11-10 03:36:35 -08:00
const [activeTab, setActiveTab] = useState('tokens')
2023-10-17 04:28:43 -07:00
useEffect(() => {
if (!perpStats || !perpStats.length) {
const actions = mangoStore.getState().actions
actions.fetchPerpStats()
}
}, [perpStats])
2023-11-10 03:36:35 -08:00
const tabsWithCount: [string, number][] = useMemo(() => {
const perpMarkets = mangoStore.getState().perpMarkets
const tabs: [string, number][] = [
['tokens', banks.length],
2023-11-14 15:53:34 -08:00
['perp', perpMarkets.length],
2023-11-13 20:41:16 -08:00
['account:followed-accounts', followedAccounts?.length],
2023-11-10 03:36:35 -08:00
]
return tabs
2023-11-13 20:41:16 -08:00
}, [banks, followedAccounts])
2023-11-10 03:36:35 -08:00
2023-10-17 04:28:43 -07:00
return (
<>
2023-11-10 03:36:35 -08:00
<div className="px-4 pt-10 md:px-6">
<h2 className="mb-4 text-center text-lg md:text-left">
2023-10-17 04:28:43 -07:00
{t('explore')}
</h2>
</div>
<RecentGainersLosers />
2023-11-10 03:36:35 -08:00
<div className="z-10 w-max px-4 pt-8 md:px-6">
<div
className={`flex h-10 flex-col items-center justify-end md:items-start ${
activeTab === 'tokens' ? 'mb-4 lg:mb-0' : ''
}`}
>
<TabsText
activeTab={activeTab}
onChange={setActiveTab}
tabs={tabsWithCount}
2023-11-14 15:53:34 -08:00
className="xl:text-lg"
2023-10-17 04:28:43 -07:00
/>
</div>
</div>
<TabContent activeTab={activeTab} />
</>
)
}
export default Explore
const TabContent = ({ activeTab }: { activeTab: string }) => {
switch (activeTab) {
2023-11-10 03:36:35 -08:00
case 'tokens':
2023-10-17 04:28:43 -07:00
return <Spot />
2023-11-10 03:36:35 -08:00
case 'perp-markets':
2023-10-17 04:28:43 -07:00
return (
<div className="mt-6 border-t border-th-bkg-3">
<PerpMarketsTable />
</div>
)
2023-11-13 20:41:16 -08:00
case 'account:followed-accounts':
return <FollowedAccounts />
2023-10-17 04:28:43 -07:00
default:
return <Spot />
}
}