aboutsummaryrefslogtreecommitdiff
path: root/src/components/SolutionCard
diff options
context:
space:
mode:
authorEugene Sokolov <eug-vs@keemail.me>2020-03-21 17:59:48 +0300
committerGitHub <noreply@github.com>2020-03-21 17:59:48 +0300
commite89a7a79622d25561dc80a8489ae1f6022aebd73 (patch)
treee115938b26ee6019b4c349f52bd98fc34a4575e9 /src/components/SolutionCard
parentfe750a9aadfb451b9537bb3cdd79581ef5120c07 (diff)
parent7f8ab6802c68c46f988ef012fdc88b09e43a9e54 (diff)
downloadchrono-cube-ui-e89a7a79622d25561dc80a8489ae1f6022aebd73.tar.gz
Merge pull request #48 from eug-vs/typescript
Migrate project to Typescript
Diffstat (limited to 'src/components/SolutionCard')
-rw-r--r--src/components/SolutionCard/SolutionCard.tsx (renamed from src/components/SolutionCard/SolutionCard.js)22
1 files changed, 15 insertions, 7 deletions
diff --git a/src/components/SolutionCard/SolutionCard.js b/src/components/SolutionCard/SolutionCard.tsx
index fdd4bdf..5adbff9 100644
--- a/src/components/SolutionCard/SolutionCard.js
+++ b/src/components/SolutionCard/SolutionCard.tsx
@@ -11,6 +11,7 @@ import {
Menu,
MenuItem,
} from '@material-ui/core';
+import { Solution } from '../../types';
import { makeStyles } from '@material-ui/core/styles';
import TimerIcon from '@material-ui/icons/Timer';
@@ -44,22 +45,29 @@ const useStyles = makeStyles(theme => ({
},
}));
-const SolutionCard = ({ data, removeThisCard }) => {
+
+interface PropTypes {
+ data: Solution;
+ removeThisCard: (id: number) => void;
+}
+
+
+const SolutionCard: React.FC<PropTypes> = ({ data, removeThisCard }) => {
const classes = useStyles();
- const [anchorEl, setAnchorEl] = useState(null);
+ const [anchorEl, setAnchorEl] = useState<HTMLElement | null>(null);
const author = data.author? data.author.username : 'anonymous';
const date = new Date(data.date);
- const handleOpenMenu = event => {
+ const handleOpenMenu = (event: React.MouseEvent<HTMLButtonElement>): void => {
setAnchorEl(event.currentTarget);
};
- const handleClose = () => {
+ const handleClose = (): void => {
setAnchorEl(null);
};
- const handleDelete = () => {
+ const handleDelete = (): void => {
del(`solutions/${data.id}/`).then(() => {
removeThisCard(data.id);
});
@@ -77,11 +85,11 @@ const SolutionCard = ({ data, removeThisCard }) => {
}
title={author}
subheader={date.toLocaleString('default', DATE_FORMAT)}
- action={(
+ action={
<IconButton onClick={handleOpenMenu}>
<MoreVertIcon />
</IconButton>
- )}
+ }
/>
<Menu
anchorEl={anchorEl}