forked from DA0-DA0/dao-dao-ui
-
Notifications
You must be signed in to change notification settings - Fork 1
/
useDaoTabs.ts
84 lines (77 loc) · 1.99 KB
/
useDaoTabs.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import {
AccountBalanceWalletOutlined,
FiberSmartRecordOutlined,
HomeOutlined,
HowToVoteOutlined,
} from '@mui/icons-material'
import { ComponentType } from 'react'
import { useTranslation } from 'react-i18next'
import { DaoTabId, DaoTabWithComponent, WidgetLocation } from '@dao-dao/types'
import { ProposalsTab, SubDaosTab, TreasuryAndNftsTab } from '../components'
import { useVotingModuleAdapter } from '../voting-module-adapter'
import { useWidgets } from '../widgets'
export type UseDaoTabsOptions = {
includeHome?: ComponentType
}
export const useDaoTabs = ({
includeHome,
}: UseDaoTabsOptions = {}): DaoTabWithComponent[] => {
const { t } = useTranslation()
const {
components: { extraTabs },
} = useVotingModuleAdapter()
// Get widget tab components, if exist.
const loadingWidgets = useWidgets({
// Only load tab widgets.
location: WidgetLocation.Tab,
})
const widgetTabs = loadingWidgets.loading
? []
: loadingWidgets.data.map(
({
title,
widget: { id, Icon },
WidgetComponent,
}): DaoTabWithComponent => ({
id,
label: title,
Icon,
Component: WidgetComponent,
})
)
return [
...(includeHome
? [
{
id: DaoTabId.Home,
label: t('title.home'),
Component: includeHome,
Icon: HomeOutlined,
},
]
: []),
{
id: DaoTabId.Proposals,
label: t('title.proposals'),
Component: ProposalsTab,
Icon: HowToVoteOutlined,
},
{
id: DaoTabId.Treasury,
label: t('title.treasuryAndNfts'),
Component: TreasuryAndNftsTab,
Icon: AccountBalanceWalletOutlined,
},
{
id: DaoTabId.SubDaos,
label: t('title.subDaos'),
Component: SubDaosTab,
Icon: FiberSmartRecordOutlined,
},
...(extraTabs?.map(({ labelI18nKey, ...tab }) => ({
label: t(labelI18nKey),
...tab,
})) ?? []),
...widgetTabs,
]
}