Skip to content

Commit 7cabcb9

Browse files
Show group names on judge live view (#310)
* Fix issue where deliberation check is wrong * Create group info store * Minor UI spacing tweaks to live judge page * Fixed issue with state not reloading
1 parent 2543290 commit 7cabcb9

File tree

5 files changed

+77
-38
lines changed

5 files changed

+77
-38
lines changed

client/src/components/judge/ProjectDisplay.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { twMerge } from 'tailwind-merge';
33
import Paragraph from '../Paragraph';
44
import { getRequest } from '../../api';
55
import { errorAlert } from '../../util';
6+
import { useGroupInfoStore } from '../../store';
67

78
interface ProjectDisplayProps {
89
/* Project ID to display */
@@ -17,6 +18,8 @@ interface ProjectDisplayProps {
1718

1819
const ProjectDisplay = (props: ProjectDisplayProps) => {
1920
const [project, setProject] = useState<Project | null>(null);
21+
const groupsEnabled = useGroupInfoStore((state) => state.enabled);
22+
const groupNames = useGroupInfoStore((state) => state.names);
2023

2124
useEffect(() => {
2225
async function fetchData() {
@@ -41,12 +44,17 @@ const ProjectDisplay = (props: ProjectDisplayProps) => {
4144

4245
return (
4346
<div className={twMerge('px-2', props.className)}>
44-
<h1 className="text-3xl mb-1 font-bold">
47+
<h1 className="text-3xl mb-0 font-bold">
4548
<a href={project.url} target="_blank" rel="noopener noreferrer">
4649
{project.name}
4750
</a>
4851
</h1>
49-
<h2 className="text-xl mb-1">Table {project.location}</h2>
52+
<h2 className="text-xl mb-2">
53+
Table {project.location}
54+
{groupsEnabled && (
55+
<span className="ml-4 text-lighter">[{groupNames[project.group]}]</span>
56+
)}
57+
</h2>
5058
<Paragraph className="text-light" text={project.description} />
5159
</div>
5260
);

client/src/pages/Expo.tsx

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { useNavigate, useParams, useSearchParams } from 'react-router-dom';
66
import Dropdown from '../components/Dropdown';
77
import Button from '../components/Button';
88
import { Helmet } from 'react-helmet';
9+
import { useGroupInfoStore } from '../store';
910

1011
const Expo = () => {
1112
const { track: trackParam } = useParams();
@@ -14,7 +15,7 @@ const Expo = () => {
1415
const [nameSort, setNameSort] = useState(false);
1516
const [track, setTrack] = useState('');
1617
const [challenges, setChallenges] = useState<string[]>([]);
17-
const [groupInfo, setGroupInfo] = useState<GroupInfo>({ enabled: false, names: [] });
18+
const groupInfo = useGroupInfoStore();
1819
const [searchParams, _] = useSearchParams();
1920
const navigate = useNavigate();
2021

@@ -36,13 +37,7 @@ const Expo = () => {
3637
return;
3738
}
3839

39-
const groupRes = await getRequest<GroupInfo>('/group-info', '');
40-
if (groupRes.status !== 200) {
41-
errorAlert(groupRes);
42-
return;
43-
}
44-
const gi = groupRes.data as GroupInfo;
45-
setGroupInfo({ enabled: gi.enabled && gi.names.length > 0, names: gi.names });
40+
await groupInfo.fetchGroupInfo();
4641

4742
setChallenges(['', ...(res.data as string[])]);
4843
}

client/src/pages/admin/settings.tsx

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,10 @@ const AdminSettings = () => {
102102
const navigate = useNavigate();
103103

104104
async function getOptions() {
105-
await fetchOptions();
105+
const newOptions = await fetchOptions() ?? options;
106106

107107
// Calculate judging timer MM:SS
108-
const timer = options.judging_timer;
108+
const timer = newOptions.judging_timer;
109109
if (timer) {
110110
const minutes = Math.floor(timer / 60);
111111
const seconds = timer % 60;
@@ -114,24 +114,24 @@ const AdminSettings = () => {
114114
}
115115

116116
// Set min views
117-
setMinViews(options.min_views);
117+
setMinViews(newOptions.min_views);
118118

119119
// Set sync clock
120-
setSyncClock(options.clock_sync);
120+
setSyncClock(newOptions.clock_sync);
121121

122122
// Set group options
123-
setMultiGroup(options.multi_group);
124-
setNumGroups(options.num_groups);
125-
setGroupSizes(options.group_sizes.join(', '));
126-
setSwitchingMode(options.switching_mode);
127-
setAutoSwitchProp(options.auto_switch_prop);
128-
setJudgeTracks(options.judge_tracks);
129-
setTracks(options.tracks.join(', '));
130-
setTrackViews(options.track_views.join(', '));
131-
setGroupNames(options.group_names.join(', '));
132-
setIgnoreTracks(options.ignore_tracks.join(', '));
133-
setBlockReqs(options.block_reqs);
134-
setMaxReqPerMin(options.max_req_per_min);
123+
setMultiGroup(newOptions.multi_group);
124+
setNumGroups(newOptions.num_groups);
125+
setGroupSizes(newOptions.group_sizes.join(', '));
126+
setSwitchingMode(newOptions.switching_mode);
127+
setAutoSwitchProp(newOptions.auto_switch_prop);
128+
setJudgeTracks(newOptions.judge_tracks);
129+
setTracks(newOptions.tracks.join(', '));
130+
setTrackViews(newOptions.track_views.join(', '));
131+
setGroupNames(newOptions.group_names.join(', '));
132+
setIgnoreTracks(newOptions.ignore_tracks.join(', '));
133+
setBlockReqs(newOptions.block_reqs);
134+
setMaxReqPerMin(newOptions.max_req_per_min);
135135

136136
// Get active clock status
137137
await fetchClock();

client/src/pages/judge/live.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import alarm from '../../assets/alarm.mp3';
1818
import data from '../../data.json';
1919
import TextInput from '../../components/TextInput';
2020
import { Helmet } from 'react-helmet';
21+
import { useGroupInfoStore } from '../../store';
2122

2223
const infoPages = ['paused', 'hidden', 'no-projects', 'done', 'doneTrack'];
2324
const infoData = [
@@ -32,6 +33,7 @@ const audio = new Audio(alarm);
3233

3334
const JudgeLive = () => {
3435
const navigate = useNavigate();
36+
const fetchGroupInfo = useGroupInfoStore((state) => state.fetchGroupInfo);
3537
const [verified, setVerified] = useState(false);
3638
const [judge, setJudge] = useState<Judge | null>(null);
3739
const [finishPopup, setFinishPopup] = useState<boolean>(false);
@@ -100,7 +102,7 @@ const JudgeLive = () => {
100102
}
101103

102104
// Check to see if deliberation has started
103-
const deliberationRes = await getRequest<OkResponse>('/admin/deliberation', '');
105+
const deliberationRes = await getRequest<OkResponse>('/judge/deliberation', 'judge');
104106
if (deliberationRes.status !== 200) {
105107
errorAlert(deliberationRes);
106108
return;
@@ -134,6 +136,9 @@ const JudgeLive = () => {
134136
return;
135137
}
136138

139+
// Fetch group info
140+
await fetchGroupInfo();
141+
137142
// If the judge has a current project, use that
138143
if (theJudge.current) {
139144
setJudge(theJudge);

client/src/store.tsx

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ const useClockStore = create<ClockStore>()((set) => ({
121121
interface OptionsStore {
122122
options: Options;
123123
selectedTrack: string;
124-
fetchOptions: () => Promise<void>;
124+
fetchOptions: () => Promise<Options | null>;
125125
setSelectedTrack: (track: string) => void;
126126
}
127127

@@ -149,7 +149,7 @@ const useOptionsStore = create<OptionsStore>((set) => ({
149149
group_names: [],
150150
ignore_tracks: [],
151151
block_reqs: false,
152-
max_req_per_min: 0
152+
max_req_per_min: 0,
153153
},
154154

155155
selectedTrack: '',
@@ -158,9 +158,11 @@ const useOptionsStore = create<OptionsStore>((set) => ({
158158
const optionsRes = await getRequest<Options>('/admin/options', 'admin');
159159
if (optionsRes.status !== 200) {
160160
errorAlert(optionsRes);
161-
return;
161+
return null;
162162
}
163-
set({ options: optionsRes.data as Options });
163+
const data = optionsRes.data as Options;
164+
set({ options: data });
165+
return data;
164166
},
165167

166168
setSelectedTrack: async (track: string) => {
@@ -193,12 +195,12 @@ const useFlagsStore = create<FlagsStore>((set) => ({
193195
}));
194196

195197
interface AdminTableStore {
196-
projects: Project[],
197-
judges: Judge[],
198-
selected: boolean[],
199-
setProjects: (projects: Project[]) => void,
200-
setJudges: (judges: Judge[]) => void,
201-
setSelected: (selected: boolean[]) => void,
198+
projects: Project[];
199+
judges: Judge[];
200+
selected: boolean[];
201+
setProjects: (projects: Project[]) => void;
202+
setJudges: (judges: Judge[]) => void;
203+
setSelected: (selected: boolean[]) => void;
202204
}
203205

204206
const useAdminTableStore = create<AdminTableStore>((set) => ({
@@ -219,4 +221,33 @@ const useAdminTableStore = create<AdminTableStore>((set) => ({
219221
},
220222
}));
221223

222-
export { useAdminStore, useClockStore, useOptionsStore, useFlagsStore, useAdminTableStore };
224+
interface GroupInfoStore {
225+
names: string[];
226+
enabled: boolean;
227+
fetchGroupInfo: () => Promise<void>;
228+
}
229+
230+
const useGroupInfoStore = create<GroupInfoStore>((set) => ({
231+
names: [],
232+
enabled: false,
233+
234+
fetchGroupInfo: async () => {
235+
const groupRes = await getRequest<GroupInfo>('/group-info', '');
236+
if (groupRes.status !== 200) {
237+
errorAlert(groupRes);
238+
return;
239+
}
240+
const groupInfo = groupRes.data as GroupInfo;
241+
console.log(groupInfo)
242+
set({ names: groupInfo.names, enabled: groupInfo.enabled && groupInfo.names.length > 0 });
243+
},
244+
}));
245+
246+
export {
247+
useAdminStore,
248+
useClockStore,
249+
useOptionsStore,
250+
useFlagsStore,
251+
useAdminTableStore,
252+
useGroupInfoStore,
253+
};

0 commit comments

Comments
 (0)