Skip to content

Commit

Permalink
Merge pull request #267 from cmu15122/alexb/cooldownsetting
Browse files Browse the repository at this point in the history
Added admin setting to toggle cooldown override.
  • Loading branch information
jacksontromero authored Apr 1, 2024
2 parents a396d6c + 0db9399 commit c04924a
Show file tree
Hide file tree
Showing 22 changed files with 6,771 additions and 8,247 deletions.
12,485 changes: 5,092 additions & 7,393 deletions client/package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"@types/node": "^18.8.4",
"@types/react": "^18.0.21",
"@types/react-dom": "^18.0.6",
"axios": "^1.6.7",
"axios": "^0.27.2",
"chart.js": "^4.4.1",
"chat.js": "^1.0.2",
"downloadjs": "^1.4.7",
Expand All @@ -31,7 +31,7 @@
"react-cookie": "^4.1.1",
"react-dom": "^18.1.0",
"react-router-dom": "^6.3.0",
"react-scripts": "^5.0.1",
"react-scripts": "5.0.1",
"react-window": "^1.8.7",
"socket.io-client": "^4.5.1",
"styled-components": "^5.3.5",
Expand Down
80 changes: 49 additions & 31 deletions client/src/components/home/shared/CooldownViolationOverlay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,41 +12,59 @@ export default function CooldownViolationOverlay(props) {

const {queueData} = useContext(QueueDataContext);
function callAddQuestionAPIOverrideCooldown() {
HomeService.addQuestion(
JSON.stringify({
andrewID: andrewID,
question: question,
location: location,
topic: topic,
overrideCooldown: true,
}),
).then((res) => {
if (res.status === 200) {
setOpen(false);
}
});
if (queueData.allowCDOverride) {
HomeService.addQuestion(
JSON.stringify({
andrewID: andrewID,
question: question,
location: location,
topic: topic,
overrideCooldown: true,
}),
).then((res) => {
if (res.status === 200) {
setOpen(false);
}
});
} else return;
}

return (
<Dialog open={open} maxWidth="sm" fullWidth>
<DialogContent sx={{p: 5, textAlign: 'center'}} >
<Typography variant='h6' textAlign='center'>
You rejoined the queue too quickly! Please wait for {queueData.rejoinTime} minutes after finishing your last question, which will be in {queueData.rejoinTime - timePassed} minutes.
</Typography>
if (queueData.allowCDOverride) {
return (
<Dialog open={open} maxWidth="sm" fullWidth>
<DialogContent sx={{p: 5, textAlign: 'center'}} >
<Typography variant='h6' textAlign='center'>
You rejoined the queue too quickly! Please wait for {queueData.rejoinTime} minutes after finishing your last question, which will be in {queueData.rejoinTime - timePassed} minutes.
</Typography>

<Stack alignItems="baseline" justifyContent="space-around" direction="row" spacing={3}>
<Button onClick={() => callAddQuestionAPIOverrideCooldown()} color='error' fullWidth variant="contained" sx={{maxHeight: '50px', mt: 3, alignContent: 'center'}} type="submit">
Override Cooldown
</Button>
<Stack alignItems="baseline" justifyContent="space-around" direction="row" spacing={3}>
<Button onClick={() => callAddQuestionAPIOverrideCooldown()} color='error' fullWidth variant="contained" sx={{maxHeight: '50px', mt: 3, alignContent: 'center'}} type="submit">
Override Cooldown
</Button>
<Button onClick={() => setOpen(false)} style={{background: theme.alternateColors.cancel}} fullWidth variant="contained" sx={{maxHeight: '50px', mt: 3, alignContent: 'center'}} type="submit">
Close
</Button>
</Stack>

<Typography lineHeight={1.3} variant='subtitle1' textAlign='center' sx={{mt: 3}}>
Overriding the cooldown will add you to the queue, however you will be frozen until a TA approves you.
</Typography>
</DialogContent>
</Dialog>
);
} else {
return (
<Dialog open={open} maxWidth="sm" fullWidth>
<DialogContent sx={{p: 5, textAlign: 'center'}} >
<Typography variant='h6' textAlign='center'>
You rejoined the queue too quickly! Please wait for {queueData.rejoinTime} minutes after finishing your last question, which will be in {queueData.rejoinTime - timePassed} minutes.
</Typography>
<Button onClick={() => setOpen(false)} style={{background: theme.alternateColors.cancel}} fullWidth variant="contained" sx={{maxHeight: '50px', mt: 3, alignContent: 'center'}} type="submit">
Close
</Button>
</Stack>

<Typography lineHeight={1.3} variant='subtitle1' textAlign='center' sx={{mt: 3}}>
Overriding the cooldown will add you to the queue, however you will be frozen until a TA approves you.
</Typography>
</DialogContent>
</Dialog>
);
</DialogContent>
</Dialog>
);
}
}

5 changes: 3 additions & 2 deletions client/src/components/home/student/YourEntry.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ export default function YourEntry(props) {
const {queueData} = useContext(QueueDataContext);
const {studentData} = useContext(StudentDataContext);

const cooldownMsg = queueData.allowCDOverride ? 'You have been frozen in line. This means you will not advance in the queue until a TA approves your entry.' : 'You have been frozen in line. You will not advance in the queue! Please wait for your cooldown to end before joining the queue again.';

return (
<BaseCard>
<CardContent sx={{m: 1, textAlign: 'left'}}>
Expand All @@ -41,8 +43,7 @@ export default function YourEntry(props) {
<Stack direction='row' display='flex' alignItems='center'>
<PauseIcon color='error' sx={{pr: 1}} />
<Typography color='error' sx={{fontWeight: 'bold'}}>
You have been frozen in line. This means you will not advance in the queue
until a TA approves your entry.
{cooldownMsg}
</Typography>
</Stack>
</div>
Expand Down
10 changes: 9 additions & 1 deletion client/src/components/home/ta/EntryTails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@ import StudentStatus from './TailOptions/StudentStatus';
import LeapStudentActions from './TailOptions/LeapStudentActions';

import {StudentStatusValues} from '../../../services/StudentStatus';
import PersistentOptions from './TailOptions/PersistentOptions';

export default function EntryTails(props) {
const {student, index, isHelping, helpIdx} = props;

const showApproval = props.showCooldownApproval;

const status = student.status;

const themeHook = useTheme();
Expand All @@ -30,8 +33,13 @@ export default function EntryTails(props) {
case StudentStatusValues.WAITING: return (ActionsHelp(props));
case StudentStatusValues.FIXING_QUESTION: return (ActionsHelp(props));
case StudentStatusValues.FROZEN: return (ActionsFreeze(props));
case StudentStatusValues.COOLDOWN_VIOLATION: return (LeapStudentActions(props));
case StudentStatusValues.RECEIVED_MESSAGE: return (ActionsHelp(props));
case StudentStatusValues.COOLDOWN_VIOLATION:
if (showApproval) {
return (LeapStudentActions(props));
} else {
return (ActionsHelp({...props, color: 'secondary'}));
}
default: return;
}
};
Expand Down
14 changes: 12 additions & 2 deletions client/src/components/home/ta/StudentEntry.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, {useState, useEffect, useRef} from 'react';
import React, {useState, useEffect, useRef, useContext} from 'react';
import {
Stack, TableCell, Typography,
} from '@mui/material';
Expand All @@ -7,16 +7,21 @@ import PauseIcon from '@mui/icons-material/Pause';
import EntryTails from './EntryTails';
import ItemRow from '../../common/table/ItemRow';

import {QueueDataContext} from '../../../contexts/QueueDataContext';

import HomeService from '../../../services/HomeService';
import {StudentStatusValues} from '../../../services/StudentStatus';
import {Settings} from '@mui/icons-material';
import {debug} from 'util';

export default function StudentEntry(props) {
const {queueData} = useContext(QueueDataContext);
const {student, index, handleClickHelp, removeStudent, handleClickUnfreeze} = props;

const [confirmRemove, setConfirmRemove] = useState(false);
const removeRef = useRef();

const [showCooldownApproval, setShowCooldownApproval] = useState(student['status'] === StudentStatusValues.COOLDOWN_VIOLATION);
const [showCooldownApproval, setShowCooldownApproval] = useState(queueData.allowCDOverride && student['status'] === StudentStatusValues.COOLDOWN_VIOLATION);

useEffect(() => {
const closeExpanded = (e) => {
Expand All @@ -32,6 +37,11 @@ export default function StudentEntry(props) {
};
}, []);

// Update showCooldownApproval when allowCDOverride changes
useEffect(() => {
setShowCooldownApproval(queueData.allowCDOverride && student['status'] === StudentStatusValues.COOLDOWN_VIOLATION);
}, [queueData.allowCDOverride, student['status']]);

function handleRemoveButton() {
if (confirmRemove) {
setConfirmRemove(false);
Expand Down
4 changes: 3 additions & 1 deletion client/src/components/home/ta/TailOptions/ActionsHelp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ export default function ActionsHelp(props) {
student, index, isHelping, handleClickHelp,
} = props;

const buttonColor = props.color == null ? 'info' : props.color;

return (
<Stack
direction={{xs: 'column', sm: 'row'}}
sx={{alignItems: 'center', justifyContent: 'flex-end'}}
>
<Button disabled={student.status === StudentStatusValues.BEING_HELPED || isHelping} color="info" variant="contained" onClick={() => handleClickHelp(index)} sx={{m: 0.5}}>
<Button disabled={student.status === StudentStatusValues.BEING_HELPED || isHelping} color={buttonColor} variant="contained" onClick={() => handleClickHelp(index)} sx={{m: 0.5}}>
Help
</Button>
{PersistentOptions(props)}
Expand Down
Loading

0 comments on commit c04924a

Please sign in to comment.