Repository navigation
Expand file tree
/
Copy pathAnalyticsLayout.tsx
More file actions
159 lines (146 loc) · 7.35 KB
/
Copy pathAnalyticsLayout.tsx
File metadata and controls
159 lines (146 loc) · 7.35 KB
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
import { Button, Drawer, List, ListItemButton, ListItemIcon, ListItemText, ListSubheader, MenuItem, Select } from "@mui/material";
import { NavigateOptions, Outlet, To, useNavigate } from "react-router-dom";
import { AnalyticsSettingsContext } from "../../components/context/AnalyticsSettingsContextProvider";
import { useContext, useEffect, useState } from "react";
import ListItemTeam from "../../components/analytics/ListItemTeam";
import { SettingsContext } from "../../components/context/SettingsContextProvider";
import { ScheduleContext } from "../../components/context/ScheduleContextProvider";
import ListItemTeamGroup from "../../components/analytics/ListItemTeamGroup";
export default function AnalyticsLayout() {
const navigate = useNavigate();
const settings = useContext(SettingsContext);
if (!settings) throw new Error("SettingsContext not found");
const analyticsSettings = useContext(AnalyticsSettingsContext);
if (!analyticsSettings) throw new Error("AnalyticsSettingsContext not found");
const schedule = useContext(ScheduleContext);
if (!schedule) throw new Error("ScheduleContext not found");
const [mobile, setMobile] = useState(false);
useEffect(() => {
const handleResize = () => {
const isMobile = window.innerWidth < 1024;
if (isMobile !== mobile) setMobile(isMobile);
}
window.addEventListener('resize', handleResize);
handleResize();
return () => window.removeEventListener('resize', handleResize);
}, [mobile]);
const [open, setOpen] = useState(false);
function onNavigate(to: To, options?: NavigateOptions) {
if (mobile) setOpen(false);
navigate(to, options);
}
return (
<div className="w-full h-full flex flex-col items-center relative" style={{ paddingLeft: mobile ? 0 : 240 }}>
<Drawer
open={mobile ? open : true}
onClose={() => setOpen(false)}
variant={mobile ? "temporary" : "permanent"}
sx={{
'& .MuiDrawer-paperAnchorDockedLeft': { position: 'absolute' },
'& .MuiDrawer-paper': { boxSizing: 'border-box', width: 240 },
}}
keepMounted
>
{analyticsSettings.starredTeams.length > 0 &&
<List
aria-labelledby="starred-list-subheader"
subheader={
<ListSubheader component="div" id="starred-list-subheader" sx={{ backgroundImage: "var(--Paper-overlay, initial);" }}>
Starred Teams
</ListSubheader>
}
>
{analyticsSettings.starredTeams.map(team => (
<ListItemTeam key={team} team={team} onNavigate={onNavigate} />
))}
</List>
}
<List
aria-labelledby="custom-list-subheader"
subheader={
<ListSubheader component="div" id="custom-list-subheader" sx={{ backgroundImage: "var(--Paper-overlay, initial);" }}>
Custom Groups
</ListSubheader>
}
>
{analyticsSettings.customTeamGroups.map(group => (
<ListItemTeamGroup
key={group.id}
name={group.name}
teams={group.teams}
editable
setGroup={(name, teams)=>analyticsSettings.setCustomTeamGroupById(group.id, {...group, name, teams})}
deleteGroup={()=>analyticsSettings.removeCustomTeamGroup(group)}
onNavigate={onNavigate}
/>
))}
<ListItemButton onClick={() => analyticsSettings.addCustomTeamGroup({id: Date.now(), name: "New Group", teams: []})} className="opacity-60">
<ListItemIcon>
<span className="material-symbols-outlined">add</span>
</ListItemIcon>
<ListItemText primary="Add Group" />
</ListItemButton>
</List>
<List
aria-labelledby="alliance-list-subheader"
subheader={
<ListSubheader component="div" id="alliance-list-subheader" className="flex items-center gap-4" sx={{ backgroundImage: "var(--Paper-overlay, initial);" }}>
<div>Alliances in </div>
<Select
variant="standard"
value={analyticsSettings.currentMatch}
onChange={e => analyticsSettings.setCurrentMatch(e.target.value)}
>
{schedule.matches.map(({matchId}) => (
<MenuItem key={matchId} value={matchId}>{matchId}</MenuItem>
))}
</Select>
</ListSubheader>
}
>
<ListItemTeamGroup
name="Blue Alliance"
teams={analyticsSettings.blueAllianceTeams}
open={analyticsSettings.currentMatchBlueOpen}
setOpen={analyticsSettings.setCurrentMatchBlueOpen}
onNavigate={onNavigate}
className="!bg-blue-500 !bg-opacity-20"
/>
<ListItemTeamGroup
name="Red Alliance"
teams={analyticsSettings.redAllianceTeams}
open={analyticsSettings.currentMatchRedOpen}
setOpen={analyticsSettings.setCurrentMatchRedOpen}
onNavigate={onNavigate}
className="!bg-red-500 !bg-opacity-20"
/>
</List>
<List
aria-labelledby="all-teams-list-subheader"
subheader={
<ListSubheader component="div" id="all-teams-list-subheader" sx={{ backgroundImage: "var(--Paper-overlay, initial);" }}>
All Teams
</ListSubheader>
}
>
{analyticsSettings.teamList.map(team => (
<ListItemTeam key={team} team={team} onNavigate={onNavigate} />
))}
</List>
</Drawer>
<Outlet />
<div className="absolute top-0 left-0">
<Button onClick={() => setOpen(!open)}
variant="contained"
size="small"
color="secondary"
className="!rounded-tl-none !rounded-bl-none !rounded-tr-none"
>
<div className="flex items-center">
<span>Teams</span><span className="material-symbols-outlined">{open ? "chevron_left" : "chevron_right"}</span>
</div>
</Button>
</div>
</div>
)
}