-
Notifications
You must be signed in to change notification settings - Fork 89
/
Copy pathplayed-item-list.tsx
56 lines (51 loc) · 1.64 KB
/
played-item-list.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import React from "react";
import { Droppable } from "react-beautiful-dnd";
import { Item } from "../types/item";
import ItemCard from "./item-card";
import styles from "../styles/played-item-list.module.scss";
interface PlayedItemListProps {
badlyPlacedIndex: number | null;
isDragging: boolean;
items: Item[];
}
export default function PlayedItemList(props: PlayedItemListProps) {
const { badlyPlacedIndex, isDragging, items } = props;
const [flippedId, setFlippedId] = React.useState<null | string>(null);
React.useEffect(() => {
if (isDragging && flippedId !== null) {
setFlippedId(null);
}
}, [flippedId, isDragging]);
return (
<div className={styles.wrapper}>
<div className={styles.listContainer}>
<Droppable droppableId="played" direction="horizontal">
{(provided) => (
<div
ref={provided.innerRef}
{...provided.droppableProps}
className={styles.list}
>
<div className={styles.timelineContainer}>
<div className={styles.timeline}></div>
</div>
<div className={styles.items}>
{items.map((item, index) => (
<ItemCard
draggable={badlyPlacedIndex !== null}
flippedId={flippedId}
index={index}
item={item}
key={item.id}
setFlippedId={setFlippedId}
/>
))}
</div>
{provided.placeholder}
</div>
)}
</Droppable>
</div>
</div>
);
}