diff --git a/src/components/Card.jsx b/src/components/Card.jsx index a06131a..5bed6ce 100644 --- a/src/components/Card.jsx +++ b/src/components/Card.jsx @@ -1,9 +1,24 @@ import React from "react"; +import Star from "./Star"; -const Card = ({ movie }) => { +const Card = ({ movie, favouriteList, setFavouriteList }) => { const { Title, Year, imdbID, Poster } = movie; return ( -
+
+ {favouriteList?.includes(imdbID) ? ( + + ) : ( + + )} {Title}
{Title}
diff --git a/src/components/Header.jsx b/src/components/Header.jsx index 4954f4e..6bba220 100644 --- a/src/components/Header.jsx +++ b/src/components/Header.jsx @@ -1,9 +1,10 @@ import React from 'react' +import { Link } from 'react-router-dom'; const Header = () => { return (
- DigiFlix + DigiFlix
) }; diff --git a/src/components/Star.jsx b/src/components/Star.jsx new file mode 100644 index 0000000..398b6be --- /dev/null +++ b/src/components/Star.jsx @@ -0,0 +1,56 @@ +import React from "react"; + +const Star = ({ + size = 5, + fill = "#00000000", + stroke = "#DAA520", + favouriteList, + setFavouriteList, + movie, +}) => { + // Calculate points for a five-pointed star + const points = []; + const outerRadius = size / 2; + const innerRadius = outerRadius * 0.382; // Golden ratio + + for (let i = 0; i < 10; i++) { + const radius = i % 2 === 0 ? outerRadius : innerRadius; + const angle = (Math.PI / 5) * i - Math.PI / 2; + const x = radius * Math.cos(angle) + size / 2; + const y = radius * Math.sin(angle) + size / 2; + points.push(`${x},${y}`); + } + + const handleFavouriteList = () => { + favouriteList?.includes(movie?.imdbID) + ? setFavouriteList((prevList) => + prevList?.filter((id) => id !== movie?.imdbID) + ) + : setFavouriteList((prevList) => [...prevList, movie?.imdbID]); + let localStorageData = JSON.parse(window.localStorage.getItem("favouriteMovies")); + console.log(localStorageData) + window.localStorage.setItem("favouriteMovies", JSON.stringify({movies: [...localStorageData, movie]})); + }; + + return ( + + + + ); +}; + +export default Star; diff --git a/src/pages/HomePage.jsx b/src/pages/HomePage.jsx index 7b9f261..2470691 100644 --- a/src/pages/HomePage.jsx +++ b/src/pages/HomePage.jsx @@ -11,10 +11,11 @@ const HomePage = () => { const [inputValue, setInputValue] = useState(""); const [searchValue, setSearchValue] = useState(""); const [page, setPage] = useState(1); + const [favouriteList, setFavouriteList] = useState([]); + const [showFavourite, setShowFavourite] = useState(false); const { data, loading, error } = useFetch( url + "&s=" + searchValue + "&page=" + page ); - const handlePageChange = (e) => { setPage(e?.target?.textContent); }; @@ -24,7 +25,7 @@ const HomePage = () => { }; return (
-
+
{ onChange={(event) => setInputValue(event?.target?.value) } - className="p-1 text-quadnary bg-primary rounded outline-none border border-ternary" + className="p-1 text-quadnary bg-secondary focus:bg-secondary rounded outline-none border border-ternary" />
-
- {data?.Search?.length > 0 && ( -
- {loading && ( - - )} -
- {data?.Search?.map((movie) => ( - - ))} -
- + + setShowFavourite((prev) => !prev)} />
- )} +
+ {(showFavourite && ( +
+ {favouriteList?.map((movie) => ( + + ))} +
+ )) || + (data?.Search?.length > 0 && ( +
+ {loading && ( + + )} +
+ {data?.Search?.map((movie) => ( + + ))} +
+ +
+ ))}
); }; diff --git a/tailwind.config.js b/tailwind.config.js index 73fb346..e21705e 100644 --- a/tailwind.config.js +++ b/tailwind.config.js @@ -2,10 +2,10 @@ export default { content: ["./index.html", "./src/**/*.{js,ts,jsx,tsx}"], theme: { colors: { - primary: "#191A19", - secondary: "#1E5128", - ternary: "#4E9F3D", - quadnary: "#D8E9A8", + primary: "#6B8A7A", + secondary: "#254336", + ternary: "#B7B597", + quadnary: "#DAD3BE", }, extend: {}, },