From eac579e60c16dac67bc84d3e657ff18181c6ee63 Mon Sep 17 00:00:00 2001 From: hazzeldorn Date: Sun, 29 Oct 2023 01:42:41 +0200 Subject: [PATCH] bugfix: update stack of left items --- .../components/TinderSwiper/TinderSwiper.js | 31 +++++++++---- frontend/src/app/globals.css | 45 ++++++++++++------- 2 files changed, 51 insertions(+), 25 deletions(-) diff --git a/frontend/src/app/components/TinderSwiper/TinderSwiper.js b/frontend/src/app/components/TinderSwiper/TinderSwiper.js index 9aafff5..473a68b 100644 --- a/frontend/src/app/components/TinderSwiper/TinderSwiper.js +++ b/frontend/src/app/components/TinderSwiper/TinderSwiper.js @@ -2,30 +2,45 @@ import styles from "./TinderSwiper.module.css"; import TinderCard from "react-tinder-card"; -import React, { useMemo, useRef } from "react"; +import React, { useState, useMemo, useRef } from "react"; const TinderSwiper = ({ tasks }) => { + // Initial state for remaining tasks. + const [remainingTasks, setRemainingTasks] = useState(tasks); + const cardRefs = useMemo( () => - Array(tasks.length) + Array(remainingTasks.length) .fill(0) .map((i) => React.createRef()), - [tasks] + [remainingTasks] ); const swipe = (direction) => { - // swipe the topmost card. - const lastCardIndex = tasks.length - 1; + // Swipe the topmost card. + const lastCardIndex = remainingTasks.length - 1; if (cardRefs[lastCardIndex].current) { cardRefs[lastCardIndex].current.swipe(direction); } }; + // Callback for outOfFrame. + const handleOutOfFrame = (name) => { + setRemainingTasks((prevTasks) => + prevTasks.filter((task) => task.name !== name) + ); + }; + return ( <>
{tasks.map(({ id, name }, index) => ( - + handleOutOfFrame(name)} + >
{name}
@@ -34,7 +49,7 @@ const TinderSwiper = ({ tasks }) => {