Skip to content
Open
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"react-spring": "^9.1.2",
"react-use-websocket": "^2.5.0",
"typescript": "^4.2.3",
"use-interval": "^1.3.0",
"use-lodash-debounce-throttle": "^0.3.5",
"uuid": "^8.3.2",
"web-vitals": "^0.2.4",
Expand Down
10 changes: 8 additions & 2 deletions server/Lecture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,17 @@ class Lecture {
reason: reason
}
};
this.wsc?.send(JSON.stringify(serverResponse));

if (!this.wsc?.isClosed)
this.wsc?.send(JSON.stringify(serverResponse))

if (reason === "quiz_timeout") {
serverResponse.data.quizID = quiz.IDFromServer;
const remainingStudents: Student[] = selectedStudents.filter((student: Student) => !quiz.answeredStudents().includes(student.id));
remainingStudents.forEach((student: Student) => student.wsc?.send(JSON.stringify(serverResponse)));
remainingStudents.forEach((student: Student) => {
if (!student.wsc?.isClosed)
student.wsc?.send(JSON.stringify(serverResponse))
});
}
quiz.removeListener("answersAdded", answersAddedHandler);
quiz.removeListener("quizEnded", quizEndedHandler);
Expand Down
3 changes: 3 additions & 0 deletions src/@types/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ interface ScheduledQuiz {
timeSeconds?: number;
questionStats: QuestionStat[];
alreadyShowedResults: boolean;
inProgress?: boolean;
timeToEnd?: number;
}

interface AnswerStat {
Expand All @@ -67,6 +69,7 @@ interface QuizStat{
interface Statistic{
quizzes: QuizStat[];
}

type TimestampType =
"QuestionType" |
"LogType" |
Expand Down
216 changes: 125 additions & 91 deletions src/lecturer/components/app/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,10 @@ import TopBar from "../topBar/topBar";
const theme = createMuiTheme({
palette: {
primary: {

main: "#4C3957",
},
secondary: {

main: "#41658A",
},
contrastThreshold: 3,
Expand All @@ -49,18 +48,55 @@ function App() {
}
}, []);

useEffect(() => {
const handleInProgress = (parsed: ShowAnswersPayload) => {
let quizzes = store.scheduledQuizzes;
quizzes[store.scheduledQuizzes.length - 1].id = parsed.data.quizID;
store.scheduledQuizzes = quizzes;
}
socketEmiter.on("quiz_in_progress", handleInProgress);
return () => {
socketEmiter.off("quiz_in_progress", handleInProgress);
}
}, [socketEmiter, store]);

useEffect(() => {
const onClose = () => {
store.isLoading = true;
};
const onOpen = () => {
store.isLoading = false;
};
const onQuizResponse = (payload: ServerQuizResponsePayload) => {
let quizzes = store.scheduledQuizzes;
let responses = payload.data.answers;
let quizStats = quizzes.filter(scheduledQuiz => scheduledQuiz.id === payload.data.quizID)[0];
let index = (quizzes.indexOf(quizStats));
quizStats.questionStats.forEach(qStat => {
let question = quizStats?.quiz?.questions[qStat.index];
let response = responses[qStat.index];
if (question?.options?.length ?? 0 > 0) {
qStat.options.forEach(oStat => {
if (!oStat.numberOfTimesSelected)
oStat.numberOfTimesSelected = 0;
oStat.numberOfTimesSelected += response[oStat.index];
})
} else {
let answersArray = qStat.options;
answersArray.push(response);
qStat.options = answersArray;
}
})
quizzes[index] = quizStats
store.scheduledQuizzes = quizzes;
}
socketEmiter.on("onClose", onClose);
socketEmiter.on("onOpen", onOpen);
socketEmiter.on("quiz_answers_added", onQuizResponse);
return () => {
socketEmiter.off("onClose", onClose);
socketEmiter.off("onOpen", onOpen);
socketEmiter.off("quiz_answers_added", onQuizResponse);
};
}, [socketEmiter, store]);

Expand All @@ -69,100 +105,98 @@ function App() {
}

const classes = makeStyles({
mainContainer:{
mainContainer: {
minWidth: "100vw",
minHeight: "100vh",
}
})();
return (
<Store>
<Router>
<ThemeProvider theme={theme}>
<CssBaseline />
<Backdrop
style={{ zIndex: 1, backgroundColor: "rgba(0,0,0,.8)" }}
open={store.isLoading}
>
<GridLoader
color={theme.palette.secondary.light}
loading={true}
margin={10}
size={50}
/>
</Backdrop>
<Route path="/" render={({ location }) => {
return (
<div className={classes.mainContainer}>
<TopBar currentLocation={location.pathname} />

<Switch>

<Route exact path="/lecturer/" render={() => {
return (
isLectureStarted ?
<Redirect to={{
pathname: "lecturer/session",
state: { isOpen: true }
}} /> :
<CreateSessionView update={updateSessionState} />
)
}} />

<Route exact path="/lecturer/quiz" render={() => {
return <CreateQuizView />
}} />

<Route exact path="/lecturer/quizzes" render={() => {
return <QuizzesListView />
}} />

<Route exact path="/lecturer/question" render={() => {
return <CreateQuestionView />
}} />

<Route exact path="/lecturer/questions" render={() => {
return <QuestionsListView />
}} />

<Route exact path="/lecturer/stats" render={() => {
return (
isLectureStarted ?
<QuizStatsView /> :
<Redirect to="/lecturer/" />
)
}} />

<Route exact path="/lecturer/timestamp" render={() => {
return (
isLectureStarted ?
<TimestampView /> :
<Redirect to="/lecturer/" />
)
}} />

<Route exact path="/lecturer/session" render={() => {
return (
isLectureStarted ?
<SessionDashboardView update={updateSessionState} /> :
<Redirect to="/lecturer/" />
)
}} />

<Route path="/" render={() => {
return (
isLectureStarted ?
<Redirect to="/lecturer/session" /> :
<Redirect to="/lecturer/" />
)
}} />

</Switch>
</div>
)
}} />
</ThemeProvider>
</Router>
</Store>
<Router>
<ThemeProvider theme={theme}>
<CssBaseline />
<Backdrop
style={{ zIndex: 1, backgroundColor: "rgba(0,0,0,.8)" }}
open={store.isLoading}
>
<GridLoader
color={theme.palette.secondary.light}
loading={true}
margin={10}
size={50}
/>
</Backdrop>
<Route path="/" render={({ location }) => {
return (
<div className={classes.mainContainer}>
<TopBar currentLocation={location.pathname} />

<Switch>

<Route exact path="/lecturer/" render={() => {
return (
isLectureStarted ?
<Redirect to={{
pathname: "lecturer/session",
state: { isOpen: true }
}} /> :
<CreateSessionView update={updateSessionState} />
)
}} />

<Route exact path="/lecturer/quiz" render={() => {
return <CreateQuizView />
}} />

<Route exact path="/lecturer/quizzes" render={() => {
return <QuizzesListView />
}} />

<Route exact path="/lecturer/question" render={() => {
return <CreateQuestionView />
}} />

<Route exact path="/lecturer/questions" render={() => {
return <QuestionsListView />
}} />

<Route exact path="/lecturer/stats" render={() => {
return (
isLectureStarted ?
<QuizStatsView /> :
<Redirect to="/lecturer/" />
)
}} />

<Route exact path="/lecturer/timestamp" render={() => {
return (
isLectureStarted ?
<TimestampView /> :
<Redirect to="/lecturer/" />
)
}} />

<Route exact path="/lecturer/session" render={() => {
return (
isLectureStarted ?
<SessionDashboardView update={updateSessionState} /> :
<Redirect to="/lecturer/" />
)
}} />

<Route path="/" render={() => {
return (
isLectureStarted ?
<Redirect to="/lecturer/session" /> :
<Redirect to="/lecturer/" />
)
}} />

</Switch>
</div>
)
}} />
</ThemeProvider>
</Router>
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,8 @@ export function CreateQuestionView() {
}, [QuestionType, answers, mode, noError, question, store.questions, title]);

const timer = useRef<number>();
const handleSubmit = useCallback(() => {
const handleSubmit = useCallback((event) => {
event.preventDefault();
if (!loading) {

if (!validate()) {
Expand Down Expand Up @@ -407,7 +408,7 @@ export function CreateQuestionView() {
if (event.code === "Enter" || event.code === "NumpadEnter") {
event.preventDefault();
if (!loading){
handleSubmit();
handleSubmit(event);
}
}
};
Expand Down
2 changes: 1 addition & 1 deletion src/lecturer/components/createQuizView/CreateQuizView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ export function CreateQuizView() {
}, 500);
}
}
}, [checked, indexArray, loading, questions, right, rightChecked, store, title]);
}, [checked, loading, questions, right, rightChecked, store, title]);

useEffect(() => {
const listener = (event: { code: string; preventDefault: () => void; }) => {
Expand Down
1 change: 1 addition & 0 deletions src/lecturer/components/importExport/ImportExport.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export function ImportExport(props: ImportExportProps) {
height: "100%",
},
height: 55,
maxWidth: 288,
},
importExportGroup: {
width: "100%",
Expand Down
2 changes: 1 addition & 1 deletion src/lecturer/components/quizStatsView/QuestionBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export function QuestionBlock(props: QuestionBlockProps) {
let option = (props.question?.options) ? (props.question.options[k]) : (undefined);
return option && (<AnswerBar
answer={option}
selected={answerStat.numberOfTimesSelected}
selected={answerStat.numberOfTimesSelected??0}
totalSelected={props.totalSelected}
/>)
})
Expand Down
Loading