Skip to content

Commit

Permalink
feat: card swiper button interactions
Browse files Browse the repository at this point in the history
  • Loading branch information
Hazzeldorn committed Oct 28, 2023
1 parent c902929 commit 45555a2
Showing 1 changed file with 35 additions and 5 deletions.
40 changes: 35 additions & 5 deletions frontend/src/app/components/TinderSwiper/TinderSwiper.js
Expand Up @@ -2,23 +2,53 @@

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 (
<>
<div className={styles.cardStack}>
{tasks.map(({ id, name }) => (
<TinderCard key={id} className={styles.card}>
{tasks.map(({ id, name }, index) => (
<TinderCard key={id} className={styles.card} ref={cardRefs[index]}>
<div className={styles.container}>
<span className="h1">{name}</span>
</div>
</TinderCard>
))}
</div>
<div className={styles.decissionTriggers}>
<button className="h2 circle bgRed colorWhite">Later</button>
<button className="h2 circle bgGreen colorWhite">Yes!</button>
<button
className="h2 circle bgRed colorWhite"
onClick={() => {
swipe("left");
}}
>
Later
</button>
<button
className="h2 circle bgGreen colorWhite"
onClick={() => {
swipe("right");
}}
>
Yes!
</button>
</div>
</>
);
Expand Down

0 comments on commit 45555a2

Please sign in to comment.