From 1cd3aaa6ab66e11320322463142b0251356ea5a8 Mon Sep 17 00:00:00 2001 From: VITALY-VORON <142410419+VITALY-VORON@users.noreply.github.com> Date: Thu, 24 Aug 2023 23:00:29 +0300 Subject: [PATCH] Update Tinder.js --- src/components/Tinder/Tinder.js | 42 +++++++++++++-------------------- 1 file changed, 17 insertions(+), 25 deletions(-) diff --git a/src/components/Tinder/Tinder.js b/src/components/Tinder/Tinder.js index 0d9a7b7..c01b282 100644 --- a/src/components/Tinder/Tinder.js +++ b/src/components/Tinder/Tinder.js @@ -1,4 +1,4 @@ -import React, {useEffect, useState} from 'react'; +import React, {useState} from 'react'; import TinderCard from 'react-tinder-card'; import './Tinder.css'; @@ -23,40 +23,29 @@ const db = [ id: 5, name: 'Dinesh Chugtai', } - ] + ]; const Tinder = () => { const characters = db; const [lastDirection, setLastDirection] = useState(); const [cardId, setCardId] = useState([]); - const swiped = (direction, nameToDelete, id) => { - console.log('removing: ' + nameToDelete); + const swiped = (direction, id) => { setLastDirection(direction); if (direction === 'right') { cardId.push(id); }; - console.log(cardId); - }; - - const outOfFrame = (name) => { - console.log(name + ' left the screen!'); }; - useEffect(() => { - let uniqueTags = []; - if (cardId.length === 1) { - uniqueTags = cardId.filter(function(elem, pos) { - return cardId.indexOf(elem) === pos;}) - console.log(uniqueTags); - } - }) - // const getId = () => { - // uniqueTags = cardId.filter(function(elem, pos) { - // return cardId.indexOf(elem) === pos; - // }); - // console.log(uniqueTags); - // } + + let uniqueTags = []; + + const getId = () => { + uniqueTags = cardId.filter(function(elem, pos) { + return cardId.indexOf(elem) === pos; + }); + console.log(uniqueTags); + } return (
@@ -66,8 +55,11 @@ const db = [ swiped(dir, character.name, character.id)} - onCardLeftScreen={() => outOfFrame(character.name)} + onSwipe={(dir) => { + swiped(dir, character.id); + getId(); + console.log(uniqueTags); + }} >