Refactor movie filtering and management features: update MovieList and MovieCard components to use new filter props; enhance global store with updateMovie functionality; implement movie state updates for seen and favorite statuses.

This commit is contained in:
Norbert Maciaszek
2025-08-05 22:30:53 +02:00
parent b08cdea130
commit 3809110a39
5 changed files with 93 additions and 31 deletions

View File

@@ -5,10 +5,10 @@ import { useGlobalStore } from "@/app/store/globalStore";
type Props = {
heading: string;
onlySeen?: boolean;
onlyFavorites?: boolean;
onlyUpcoming?: boolean;
onlyReleased?: boolean;
filterSeen?: 0 | 1;
filterFavorites?: 0 | 1;
filterUpcoming?: 0 | 1;
filterReleased?: 0 | 1;
showFilters?: boolean;
sort?: "title" | "releaseDate" | "popularity";
@@ -17,10 +17,10 @@ type Props = {
export const MovieList: FC<Props> = ({
heading,
onlyFavorites,
onlySeen,
onlyUpcoming,
onlyReleased,
filterSeen,
filterFavorites,
filterUpcoming,
filterReleased,
showFilters = false,
sort = "title",
sortDirection = "asc",
@@ -31,11 +31,15 @@ export const MovieList: FC<Props> = ({
const { movies } = useGlobalStore();
const filteredMovies = movies.filter((movie) => {
if (onlySeen) return movie.seen === 1;
if (onlyFavorites) return movie.favorite === 1;
if (onlyUpcoming) return new Date(movie.releaseDate) > new Date();
if (onlyReleased) return new Date(movie.releaseDate) < new Date();
return true;
let result = true;
if (typeof filterSeen === "number") result = movie.seen === filterSeen;
if (typeof filterFavorites === "number")
result = result && movie.favorite === filterFavorites;
if (typeof filterUpcoming === "number")
result = result && new Date(movie.releaseDate) > new Date();
if (typeof filterReleased === "number")
result = result && new Date(movie.releaseDate) < new Date();
return result;
});
let sortedMovies = filteredMovies.sort((a, b) => {