-
Notifications
You must be signed in to change notification settings - Fork 213
/
Copy pathMenu.tsx
153 lines (142 loc) · 3.78 KB
/
Menu.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
import React from 'react';
import { RouteComponentProps, withRouter, useLocation } from 'react-router';
import {
IonContent,
IonIcon,
IonItem,
IonLabel,
IonList,
IonListHeader,
IonMenu,
IonMenuToggle,
IonToggle,
} from '@ionic/react';
import {
calendarOutline,
hammer,
moonOutline,
help,
informationCircleOutline,
logIn,
logOut,
mapOutline,
peopleOutline,
person,
personAdd,
} from 'ionicons/icons';
import { connect } from '../data/connect';
import { setDarkMode } from '../data/user/user.actions';
import './Menu.css';
const routes = {
appPages: [
{ title: 'Schedule', path: '/tabs/schedule', icon: calendarOutline },
{ title: 'Speakers', path: '/tabs/speakers', icon: peopleOutline },
{ title: 'Map', path: '/tabs/map', icon: mapOutline },
{ title: 'About', path: '/tabs/about', icon: informationCircleOutline },
],
loggedInPages: [
{ title: 'Account', path: '/account', icon: person },
{ title: 'Support', path: '/support', icon: help },
{ title: 'Logout', path: '/logout', icon: logOut },
],
loggedOutPages: [
{ title: 'Login', path: '/login', icon: logIn },
{ title: 'Support', path: '/support', icon: help },
{ title: 'Signup', path: '/signup', icon: personAdd },
],
};
interface Pages {
title: string;
path: string;
icon: string;
routerDirection?: string;
}
interface StateProps {
darkMode: boolean;
isAuthenticated: boolean;
menuEnabled: boolean;
}
interface DispatchProps {
setDarkMode: typeof setDarkMode;
}
interface MenuProps extends RouteComponentProps, StateProps, DispatchProps {}
const Menu: React.FC<MenuProps> = ({
darkMode,
history,
isAuthenticated,
setDarkMode,
menuEnabled,
}) => {
const location = useLocation();
function renderlistItems(list: Pages[]) {
return list
.filter((route) => !!route.path)
.map((p) => (
<IonMenuToggle key={p.title} auto-hide="false">
<IonItem
detail={false}
routerLink={p.path}
routerDirection="none"
className={
location.pathname.startsWith(p.path) ? 'selected' : undefined
}
>
<IonIcon slot="start" icon={p.icon} />
<IonLabel>{p.title}</IonLabel>
</IonItem>
</IonMenuToggle>
));
}
return (
<IonMenu type="overlay" disabled={!menuEnabled} contentId="main">
<IonContent forceOverscroll={false}>
<IonList lines="none">
<IonListHeader>Conference</IonListHeader>
{renderlistItems(routes.appPages)}
</IonList>
<IonList lines="none">
<IonListHeader>Account</IonListHeader>
{isAuthenticated
? renderlistItems(routes.loggedInPages)
: renderlistItems(routes.loggedOutPages)}
<IonItem>
<IonIcon
slot="start"
icon={moonOutline}
aria-hidden="true"
></IonIcon>
<IonToggle
checked={darkMode}
onClick={() => setDarkMode(!darkMode)}
>
Dark Mode
</IonToggle>
</IonItem>
</IonList>
<IonList lines="none">
<IonListHeader>Tutorial</IonListHeader>
<IonItem
button
onClick={() => {
history.push('/tutorial');
}}
>
<IonIcon slot="start" icon={hammer} />
<IonLabel>Show Tutorial</IonLabel>
</IonItem>
</IonList>
</IonContent>
</IonMenu>
);
};
export default connect<{}, StateProps, {}>({
mapStateToProps: (state) => ({
darkMode: state.user.darkMode,
isAuthenticated: state.user.isLoggedin,
menuEnabled: state.data.menuEnabled,
}),
mapDispatchToProps: {
setDarkMode,
},
component: withRouter(Menu),
});