-
Notifications
You must be signed in to change notification settings - Fork 14
/
ProjectDashboard.tsx
150 lines (139 loc) · 3.84 KB
/
ProjectDashboard.tsx
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
import { ChevronRightIcon } from '@chakra-ui/icons'
import { Container, HStack, IconButton, Text, VStack } from '@chakra-ui/react'
import { useState } from 'react'
import { useTranslation } from 'react-i18next'
import { Outlet, useMatch } from 'react-router-dom'
import { CardLayout } from '../../components/layouts'
import Loader from '../../components/ui/Loader'
import { TitleDivider } from '../../components/ui/TitleDivider'
import { dimensions, getPath, PathsMap } from '../../constants'
import { useProjectContext } from '../../context'
import { useMobileMode } from '../../utils'
import { DashboardNavigation } from './navigation/DashboardNavigation'
export type DashboardSection = {
label: string
path: keyof PathsMap
fullWidth?: boolean
semiFullWidth?: boolean
}
export const projectSections: Record<string, DashboardSection> = {
description: {
label: 'Description',
path: 'projectDashboard',
},
details: {
label: 'Links & tags',
path: 'dashboardDetails',
},
story: {
label: 'Story',
path: 'dashboardStory',
semiFullWidth: true,
},
wallet: {
label: 'Connect wallet',
path: 'dashboardWallet',
},
nostr: {
label: 'Nostr settings',
path: 'dashboardNostr',
},
settings: {
label: 'Project settings',
path: 'dashboardSettings',
},
}
const sections = { ...projectSections }
export const ProjectDashboard = () => {
const { t } = useTranslation()
const isMobile = useMobileMode()
const [isDrawerOpen, setDrawerOpen] = useState(false)
const { project } = useProjectContext({ ownerAccessOnly: true })
const match = useMatch(
`${getPath('projectDashboard', project?.name)}/:section`,
)
const activeSectionKey = match?.params.section || 'description'
const activeSection = sections[activeSectionKey]
if (!project) {
return (
<Container pt={12}>
<Loader />
</Container>
)
}
const content = (
<>
{isMobile ? (
<TitleDivider
zIndex={10}
mb={4}
bg="neutral.0"
position="sticky"
onClick={() => setDrawerOpen(true)}
top={dimensions.topNavBar.desktop.height + 'px'}
rightAction={
<IconButton
aria-label="open dashboard menu"
variant="transparent"
justifyContent="end"
>
<ChevronRightIcon fontSize="1.7em" />
</IconButton>
}
>
{t(activeSection?.label || '')}
</TitleDivider>
) : (
<Text variant="h3">{t(activeSection?.label || '')}</Text>
)}
<Outlet />
</>
)
return (
<HStack
alignItems="stretch"
flexGrow={1}
minHeight={`calc(100vh - ${dimensions.topNavBar.mobile.height}px)`}
>
<DashboardNavigation
project={project}
setDrawerOpen={setDrawerOpen}
isDrawerOpen={isDrawerOpen}
activeSectionKey={activeSectionKey}
p={10}
position={{ base: 'sticky', xl: 'fixed' }}
top={{ base: 0, xl: dimensions.topNavBar.desktop.height + 'px' }}
/>
<VStack justifySelf="stretch" flexGrow={1} w="100%">
<Container
alignSelf="stretch"
flexGrow={1}
display="flex"
flexDirection="column"
py={{ base: 4, lg: 10 }}
pl={{
base: 4,
xl: activeSection?.fullWidth ? '18em' : undefined,
}}
maxWidth={{
base: '100%',
lg: activeSection?.fullWidth
? '100%'
: activeSection?.semiFullWidth
? '4xl'
: '3xl',
}}
justifyItems="center"
>
{isMobile ? (
content
) : (
<CardLayout pt={4} flexGrow={1}>
{content}
</CardLayout>
)}
</Container>
</VStack>
</HStack>
)
}