From 2359cfc5821037cbd354d091e2c3020cea659e02 Mon Sep 17 00:00:00 2001 From: Norbert Maciaszek Date: Tue, 5 Aug 2025 21:51:51 +0200 Subject: [PATCH] Enhance movie management features by adding MovieList component to display user's watchlist; update MovieCard to include add/remove functionality for watchlist; refactor SearchMovies layout for improved structure; adjust global styles for primary color. --- src/app/globals.css | 2 +- src/app/page.tsx | 2 + src/components/atoms/MovieCard/index.tsx | 67 +++++++++++++++++-- src/components/molecules/MovieList/index.tsx | 31 +++++++++ .../molecules/SearchMovies/index.tsx | 39 ++++++----- 5 files changed, 118 insertions(+), 23 deletions(-) create mode 100644 src/components/molecules/MovieList/index.tsx 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 && ( + + )} + {alreadyInStore && ( + + )} +
{ + 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) => ( - - ))} -
-
+ ); };