diff --git a/frontend/src/app/components/TinderSwiper/TinderSwiper.js b/frontend/src/app/components/TinderSwiper/TinderSwiper.js index cf64c2a..9aafff5 100644 --- a/frontend/src/app/components/TinderSwiper/TinderSwiper.js +++ b/frontend/src/app/components/TinderSwiper/TinderSwiper.js @@ -2,14 +2,30 @@ import styles from "./TinderSwiper.module.css"; import TinderCard from "react-tinder-card"; +import React, { useMemo, useRef } from "react"; const TinderSwiper = ({ tasks }) => { - console.log(tasks); + const cardRefs = useMemo( + () => + Array(tasks.length) + .fill(0) + .map((i) => React.createRef()), + [tasks] + ); + + const swipe = (direction) => { + // swipe the topmost card. + const lastCardIndex = tasks.length - 1; + if (cardRefs[lastCardIndex].current) { + cardRefs[lastCardIndex].current.swipe(direction); + } + }; + return ( <>
- {tasks.map(({ id, name }) => ( - + {tasks.map(({ id, name }, index) => ( +
{name}
@@ -17,8 +33,22 @@ const TinderSwiper = ({ tasks }) => { ))}
- - + +
);