-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add quiz in progress to stats view (#280)
- Loading branch information
Showing
10 changed files
with
2,223 additions
and
2,133 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { IconButton, ListItem, ListItemIcon, ListItemSecondaryAction, ListItemText, makeStyles, useTheme } from "@material-ui/core"; | ||
import React, { useCallback, useContext, useEffect } from "react"; | ||
import { useState } from "react"; | ||
import { StoreContext } from "../../services/StoreService"; | ||
import { formatTime } from "../../util/time"; | ||
import AssignmentIcon from "@material-ui/icons/Assignment"; | ||
import BackspaceIcon from '@material-ui/icons/Backspace'; | ||
import useInterval from 'use-interval' | ||
|
||
interface StatsListProps { | ||
isSelected: boolean; | ||
onSelect: () => void; | ||
onDelete: () => void; | ||
onEnded: () => void; | ||
inProgress: boolean; | ||
timeToEnd: number; | ||
title: string; | ||
index: number; | ||
} | ||
|
||
export function StatsListItem(props: StatsListProps) { | ||
const [clock, setClock] = useState(props.timeToEnd - Date.now()); | ||
|
||
const theme = useTheme(); | ||
const classes = makeStyles({ | ||
quizStatRow: { | ||
paddingTop: 16, | ||
paddingBottom: 16, | ||
}, | ||
})(); | ||
|
||
useInterval(() => { | ||
if (props.timeToEnd - Date.now() > 0) | ||
setClock(props.timeToEnd - Date.now()); | ||
else { | ||
setClock(0); | ||
props.onEnded(); | ||
} | ||
}, props.inProgress ? 1000 : null); | ||
|
||
return (<ListItem | ||
button | ||
selected={props.isSelected} | ||
onClick={(event) => props.onSelect()} | ||
className={classes.quizStatRow} | ||
divider | ||
disabled={props.inProgress} | ||
> | ||
<ListItemIcon> | ||
{props.isSelected && ( | ||
<AssignmentIcon /> | ||
)} | ||
</ListItemIcon> | ||
<ListItemText primary={props.title} secondary={props.inProgress ? formatTime(clock) : ""} /> | ||
{!props.inProgress && (<ListItemSecondaryAction> | ||
<IconButton edge="end" onClick={(event) => props.onDelete()}> | ||
<BackspaceIcon /> | ||
</IconButton> | ||
</ListItemSecondaryAction>)} | ||
</ListItem>); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.