diff --git a/src/app/globals.css b/src/app/globals.css index f241e20..ad1c5c9 100644 --- a/src/app/globals.css +++ b/src/app/globals.css @@ -4,7 +4,7 @@ @theme { --color-background: #0e1428; - --color-primary: #d95d39; + --color-primary: #c73b6f; --color-accent: #7b9e89; --color-text: #eaeaea; --color-textSecondary: #aaaaaa; diff --git a/src/app/page.tsx b/src/app/page.tsx index 1fe21bb..155308a 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -1,9 +1,11 @@ +import { MovieList } from "@/components/molecules/MovieList"; import { SearchMovies } from "@/components/molecules/SearchMovies"; export default async function Home() { return ( + ); } diff --git a/src/components/atoms/MovieCard/index.tsx b/src/components/atoms/MovieCard/index.tsx index cadae9f..dca007e 100644 --- a/src/components/atoms/MovieCard/index.tsx +++ b/src/components/atoms/MovieCard/index.tsx @@ -1,26 +1,65 @@ -import { FC } from "react"; +"use client"; +import { FC, useState } from "react"; import { ReadMore } from "../ReadMore"; +import { addMovie, deleteMovie } from "@/lib/db"; +import { useGlobalStore } from "@/app/store/globalStore"; type Props = { + id: number; title: string; overview: string; releaseDate: string; popularity: number; imagePath: string; + seen: boolean; + favorite: boolean; + notes?: string; }; export const MovieCard: FC = ({ + id, title, releaseDate, popularity, overview, imagePath, + seen, + favorite, + notes, }) => { + const { + movies, + addMovie: addMovieToStore, + deleteMovie: deleteMovieFromStore, + } = useGlobalStore(); + const alreadyInStore = movies.find((m) => m.id === id); + + const handleAdd = async () => { + const movie = { + id, + title, + overview, + popularity, + releaseDate, + posterPath: imagePath, + seen: 0, + favorite: 0, + notes: "", + }; + await addMovie(movie); + addMovieToStore(movie); + }; + + const handleRemove = async () => { + await deleteMovie(id); + deleteMovieFromStore(id); + }; + return ( - + - + @@ -35,17 +74,35 @@ export const MovieCard: FC = ({ - + Popularity: {popularity} - + Release date: {releaseDate} + + {!alreadyInStore && ( + + Add to watchlist + + )} + {alreadyInStore && ( + + Remove from watchlist + + )} + { + const { movies } = useGlobalStore(); + + return ( + + + My Watchlist + {movies.length === 0 && ( + No movies found + )} + + {movies + .sort((a, b) => a.title.localeCompare(b.title)) + .map((movie) => ( + + ))} + + + + ); +}; diff --git a/src/components/molecules/SearchMovies/index.tsx b/src/components/molecules/SearchMovies/index.tsx index b75f312..209b653 100644 --- a/src/components/molecules/SearchMovies/index.tsx +++ b/src/components/molecules/SearchMovies/index.tsx @@ -14,24 +14,29 @@ export const SearchMovies = () => { }; return ( - - - - + + + + + + + + + {results.map((result) => ( + + ))} - - {results.map((result) => ( - - ))} - - + ); };
No movies found