From 5919ca26792796c99bfac316a9dfca0b9257fe76 Mon Sep 17 00:00:00 2001 From: Eug-VS Date: Sun, 5 Jan 2020 03:24:01 +0300 Subject: Parse date to SolutionCard --- src/components/Scoreboard/Scoreboard.js | 2 +- src/components/SolutionCard/SolutionCard.js | 21 +++++++++++++++------ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/components/Scoreboard/Scoreboard.js b/src/components/Scoreboard/Scoreboard.js index 039b951..d55944d 100644 --- a/src/components/Scoreboard/Scoreboard.js +++ b/src/components/Scoreboard/Scoreboard.js @@ -43,7 +43,7 @@ const Scoreboard = () => { {solutions.map(solution => ( - + ))} diff --git a/src/components/SolutionCard/SolutionCard.js b/src/components/SolutionCard/SolutionCard.js index f2d814c..7cca74c 100644 --- a/src/components/SolutionCard/SolutionCard.js +++ b/src/components/SolutionCard/SolutionCard.js @@ -19,6 +19,14 @@ import MoreVertIcon from '@material-ui/icons/MoreVert'; import { del } from "../../requests"; +const DATE_FORMAT = { + month: 'long', + day: 'numeric', + year: 'numeric', + hour: '2-digit', + minute: '2-digit', +}; + const useStyles = makeStyles(theme => ({ root: { padding: theme.spacing(1), @@ -30,11 +38,12 @@ const useStyles = makeStyles(theme => ({ }, })); -const SolutionCard = ({ solution, removeThisCard }) => { +const SolutionCard = ({ data, removeThisCard }) => { const classes = useStyles(); const [anchorEl, setAnchorEl] = useState(null); - const author = solution.author? solution.author.username : 'anonymous'; + const author = data.author? data.author.username : 'anonymous'; + const date = new Date(data.date); const handleOpenMenu = event => { setAnchorEl(event.currentTarget); @@ -45,9 +54,9 @@ const SolutionCard = ({ solution, removeThisCard }) => { }; const handleDelete = () => { - del(`solutions/${solution.id}/`); + del(`solutions/${data.id}/`); handleClose(); - removeThisCard(solution.id); + removeThisCard(data.id); }; return ( @@ -60,7 +69,7 @@ const SolutionCard = ({ solution, removeThisCard }) => { ({author[0].toUpperCase()}) } title={author} - subheader="04.01.2020 13:20" + subheader={date.toLocaleString('default', DATE_FORMAT)} action={( @@ -82,7 +91,7 @@ const SolutionCard = ({ solution, removeThisCard }) => { - { solution.result } + { data.result } -- cgit v1.2.3