-
Notifications
You must be signed in to change notification settings - Fork 0
/
FruitSection.tsx
45 lines (40 loc) · 1.31 KB
/
FruitSection.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
import { useStoreContext } from "../../Context";
import { Flipper } from "react-flip-toolkit";
import styles from "./FruitSection.module.css";
import filterFruits from "../../utils/filterFruits";
import FruitItem from "./FruitItem/FruitItem";
import ActiveFilters from "./ActiveFilters/ActiveFilters";
const FruitSection = () => {
const { fruits, filters } = useStoreContext();
const filteredFruits = filterFruits(fruits, filters);
return (
<div className={styles.fruitSection}>
<h2 className={styles.title}>
Items ({filteredFruits.length})
{filters.favorite && (
<span className={styles.favoritesTitle}>
<span className={styles.emDash}>—</span>Favorites
</span>
)}
</h2>
<ActiveFilters />
{filteredFruits.length === 0 ? (
<p className={styles.noMatch}>No fruits match the current filters.</p>
) : (
<Flipper
flipKey={filteredFruits.map((item) => item.id).join("-")}
spring={{
stiffness: 700,
damping: 70,
}}>
<div className={styles.fruitGrid}>
{filteredFruits.map((fruit) => (
<FruitItem key={fruit.id} fruit={fruit} />
))}
</div>
</Flipper>
)}
</div>
);
};
export default FruitSection;