From b5af9d633386e1e9139888cbe272ff4d34e6219b Mon Sep 17 00:00:00 2001 From: Eug-VS Date: Tue, 7 Jan 2020 22:48:20 +0300 Subject: Improve updating and deleting on Scoreboard page --- src/components/Scoreboard/Scoreboard.js | 8 +++----- src/components/SolutionCard/SolutionCard.js | 5 +++-- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/components/Scoreboard/Scoreboard.js b/src/components/Scoreboard/Scoreboard.js index c7bc6d8..f231f55 100644 --- a/src/components/Scoreboard/Scoreboard.js +++ b/src/components/Scoreboard/Scoreboard.js @@ -26,18 +26,16 @@ const Scoreboard = () => { const updateSolutions = () => { get('scoreboard/').then(response => { - setTimeout(() => { setSolutions(response.data); - }, 300); }); }; - const removeSolution = (id) => { - setSolutions(solutions.filter((solution => solution.id !== id))); + const removeSolution = id => { + updateSolutions(); }; useEffect(() => { - updateSolutions(); + setTimeout(updateSolutions, 300); }, []); return ( diff --git a/src/components/SolutionCard/SolutionCard.js b/src/components/SolutionCard/SolutionCard.js index 7cca74c..1fff873 100644 --- a/src/components/SolutionCard/SolutionCard.js +++ b/src/components/SolutionCard/SolutionCard.js @@ -54,9 +54,10 @@ const SolutionCard = ({ data, removeThisCard }) => { }; const handleDelete = () => { - del(`solutions/${data.id}/`); + del(`solutions/${data.id}/`).then(() => { + removeThisCard(data.id); + }); handleClose(); - removeThisCard(data.id); }; return ( -- cgit v1.2.3