This repository was archived by the owner on Aug 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathSidebar.tsx
170 lines (161 loc) · 4.33 KB
/
Sidebar.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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
import React from 'react';
import {
Box,
List,
ListItem,
makeStyles,
Typography,
useTheme,
Divider,
} from '@material-ui/core';
import { useTranslation } from 'react-i18next';
import { ContentCreator } from '@trex/shared/models/ContentCreator';
import { CurrentView, doUpdateCurrentView } from '../../utils/location.utils';
import { UserProfileBox } from './UserProfileBox';
import LabIcon from '../common/icons/LabIcon';
import AnalyticsIcon from '../common/icons/AnalyticsIcon';
import SettingsIcon from '../common/icons/SettingsIcon';
import YCAILogo from '../common/YCAILogo';
const useStyles = makeStyles((theme) => ({
routesList: {
marginLeft: -theme.spacing(2),
flexGrow: 1,
},
listItemNotSelected: {
color: theme.palette.primary.main,
},
listItemSelected: {
color: theme.palette.violet.contrastText,
backgroundColor: `${theme.palette.grey[500]}`,
'&:hover': {
backgroundColor: `${theme.palette.grey[500]}`,
opacity: 0.8,
},
},
listItem: {
paddingTop: theme.spacing(2),
paddingBottom: theme.spacing(2),
borderTopRightRadius: theme.shape.borderRadius,
borderBottomRightRadius: theme.shape.borderRadius,
},
listItemIcon: {
marginLeft: theme.spacing(1),
marginRight: theme.spacing(2),
},
divider: {
marginTop: theme.spacing(8),
marginBottom: theme.spacing(8),
},
}));
interface MenuItem {
title: string;
icon: React.FC<{ className?: string; color: string }>;
iconClassName: string;
iconColor: string;
iconSelectedColor: string;
views: Array<CurrentView['view']>;
notSelectedClassName: string;
selectedClassName: string;
className: string;
}
const toMenuItem = (
d: MenuItem,
currentView: CurrentView
): React.ReactElement => {
return (
<ListItem
key={d.views[0]}
className={`${
d.views.includes(currentView.view)
? d.selectedClassName
: d.notSelectedClassName
} ${d.className}`}
button={true}
onClick={doUpdateCurrentView({ view: d.views[0] as any })}
>
<d.icon
className={d.iconClassName}
color={
d.views.includes(currentView.view) ? d.iconSelectedColor : d.iconColor
}
/>
<Typography
variant="subtitle2"
style={{
lineHeight: 1,
margin: 0,
textTransform: 'uppercase',
}}
>
{d.title}
</Typography>
</ListItem>
);
};
interface SidebarProps {
currentView: CurrentView;
profile?: ContentCreator;
}
export const Sidebar: React.FC<SidebarProps> = ({ currentView, profile }) => {
const { t } = useTranslation();
const classes = useStyles();
const theme = useTheme();
return (
<Box
style={{
position: 'sticky',
top: theme.spacing(3),
}}
>
<Box
style={{
marginTop: theme.spacing(1),
marginBottom: theme.spacing(8),
}}
onClick={() => {
void doUpdateCurrentView({ view: 'index' })();
}}
>
<YCAILogo height={24} />
</Box>
{profile && (
<>
<UserProfileBox />
<Divider light className={classes.divider} />
<List className={classes.routesList} disablePadding={true}>
{[
{
title: t('routes:lab_title_short'),
icon: LabIcon,
views: ['lab', 'labEdit'] as Array<CurrentView['view']>,
},
{
title: t('routes:analytics'),
icon: AnalyticsIcon,
views: ['analytics'] as Array<CurrentView['view']>,
},
{
title: t('routes:settings'),
icon: SettingsIcon,
views: ['settings'] as Array<CurrentView['view']>,
},
].map((opts) =>
toMenuItem(
{
...opts,
iconClassName: classes.listItemIcon,
iconColor: theme.palette.primary.main,
iconSelectedColor: theme.palette.common.white,
className: classes.listItem,
notSelectedClassName: classes.listItemNotSelected,
selectedClassName: classes.listItemSelected,
},
currentView
)
)}
</List>
</>
)}
</Box>
);
};