Update Tinder.js
This commit is contained in:
parent
18b3e0b819
commit
1cd3aaa6ab
@ -1,4 +1,4 @@
|
|||||||
import React, {useEffect, useState} from 'react';
|
import React, {useState} from 'react';
|
||||||
import TinderCard from 'react-tinder-card';
|
import TinderCard from 'react-tinder-card';
|
||||||
import './Tinder.css';
|
import './Tinder.css';
|
||||||
|
|
||||||
@ -23,40 +23,29 @@ const db = [
|
|||||||
id: 5,
|
id: 5,
|
||||||
name: 'Dinesh Chugtai',
|
name: 'Dinesh Chugtai',
|
||||||
}
|
}
|
||||||
]
|
];
|
||||||
|
|
||||||
const Tinder = () => {
|
const Tinder = () => {
|
||||||
const characters = db;
|
const characters = db;
|
||||||
const [lastDirection, setLastDirection] = useState();
|
const [lastDirection, setLastDirection] = useState();
|
||||||
const [cardId, setCardId] = useState([]);
|
const [cardId, setCardId] = useState([]);
|
||||||
|
|
||||||
const swiped = (direction, nameToDelete, id) => {
|
const swiped = (direction, id) => {
|
||||||
console.log('removing: ' + nameToDelete);
|
|
||||||
setLastDirection(direction);
|
setLastDirection(direction);
|
||||||
if (direction === 'right') {
|
if (direction === 'right') {
|
||||||
cardId.push(id);
|
cardId.push(id);
|
||||||
};
|
};
|
||||||
console.log(cardId);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const outOfFrame = (name) => {
|
|
||||||
console.log(name + ' left the screen!');
|
|
||||||
};
|
|
||||||
|
|
||||||
useEffect(() => {
|
let uniqueTags = [];
|
||||||
let uniqueTags = [];
|
|
||||||
if (cardId.length === 1) {
|
const getId = () => {
|
||||||
uniqueTags = cardId.filter(function(elem, pos) {
|
uniqueTags = cardId.filter(function(elem, pos) {
|
||||||
return cardId.indexOf(elem) === pos;})
|
return cardId.indexOf(elem) === pos;
|
||||||
console.log(uniqueTags);
|
});
|
||||||
}
|
console.log(uniqueTags);
|
||||||
})
|
}
|
||||||
// const getId = () => {
|
|
||||||
// uniqueTags = cardId.filter(function(elem, pos) {
|
|
||||||
// return cardId.indexOf(elem) === pos;
|
|
||||||
// });
|
|
||||||
// console.log(uniqueTags);
|
|
||||||
// }
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='tinder-container'>
|
<div className='tinder-container'>
|
||||||
@ -66,8 +55,11 @@ const db = [
|
|||||||
<TinderCard
|
<TinderCard
|
||||||
className='swipe'
|
className='swipe'
|
||||||
key={character.id}
|
key={character.id}
|
||||||
onSwipe={(dir) => swiped(dir, character.name, character.id)}
|
onSwipe={(dir) => {
|
||||||
onCardLeftScreen={() => outOfFrame(character.name)}
|
swiped(dir, character.id);
|
||||||
|
getId();
|
||||||
|
console.log(uniqueTags);
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<div className='card'>
|
<div className='card'>
|
||||||
<div
|
<div
|
||||||
|
Loading…
x
Reference in New Issue
Block a user