-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFavorites.tsx
56 lines (51 loc) · 1.71 KB
/
Favorites.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 { FC, useContext } from 'react';
import { Box, Grid } from '@chakra-ui/react';
import { PageHeader, EmptyState, StarShipCard } from '@/components';
import { FavoritesContext } from '@/context/FavoritesContext';
import { NotesContext } from '@/context/NotesContext';
import { useIsShipFavorite, useToggleFavoriteShip } from '@/hooks';
import { PageTitles } from '@/constants';
import { Starship } from '@/types';
/**
* Favorites page with the list of starships marked as favorites
*
* @component
*
* @author Carlos Knopel
*/
const Favorites: FC = () => {
const { favorites } = useContext(FavoritesContext);
const { notes, setNote } = useContext(NotesContext);
const handleToggleShipFavorite = useToggleFavoriteShip();
const isShipFavorite = useIsShipFavorite();
return (
<Box h="100%" w="100%">
<PageHeader title={PageTitles.FAVORITES} />
{favorites.length === 0 ? (
<EmptyState text="Sorry, you don't have any favorites here" />
) : (
<Grid
templateColumns={{
base: 'repeat(1, 1fr)',
md: 'repeat(2, 1fr)',
}}
gap={6}
mt={{ base: '42px', md: '60px' }}
>
{favorites.map((ship: Starship) => (
<StarShipCard
key={`${ship.name}-${ship.manufacturer}`}
data={ship}
isFavorite={isShipFavorite(ship)}
favoriteButtonOnClick={() => handleToggleShipFavorite(ship)}
isNotesBoxVisible
notesText={notes[`${ship.name}-${ship.manufacturer}`] || ''}
onNotesChange={(event) => setNote(ship, event.target.value)}
/>
))}
</Grid>
)}
</Box>
);
};
export default Favorites;