From 166fe024edcb6e249186dd3dcd86df0fa0d06fd4 Mon Sep 17 00:00:00 2001 From: Loi Phan Date: Sun, 8 Oct 2023 20:40:14 +0700 Subject: [PATCH] Updated code --- sample/use-popcorn/src/App.jsx | 97 ++++++++++++++++++---------------- 1 file changed, 51 insertions(+), 46 deletions(-) diff --git a/sample/use-popcorn/src/App.jsx b/sample/use-popcorn/src/App.jsx index 9a3a253..05c64de 100644 --- a/sample/use-popcorn/src/App.jsx +++ b/sample/use-popcorn/src/App.jsx @@ -51,20 +51,35 @@ const average = (arr) => arr.reduce((acc, cur, i, arr) => acc + cur / arr.length, 0); export default function App() { + const [movies, setMovies] = useState(tempMovieData); + const [watched, setWatched] = useState(tempWatchedData); + return ( <> - -
+ + + + + +
+ + + + + + + + +
); } -function NavBar() { +function NavBar({ children }) { return ( ); } @@ -91,42 +106,54 @@ function Search() { ); } -function NumResults() { +function NumResults({ movies }) { return (

- Found X results + Found {movies.length} results

); } -function Main() { - return ( -
- - -
- ); +function Main({ children }) { + return
{children}
; } -function ListBox() { - const [isOpen1, setIsOpen1] = useState(true); +function Box({ children }) { + const [isOpen, setIsOpen] = useState(true); return (
- - {isOpen1 && } + {isOpen && children}
); } -function MovieList() { - const [movies, setMovies] = useState(tempMovieData); +// function WatchedBox() { +// const [watched, setWatched] = useState(tempWatchedData); +// const [isOpen2, setIsOpen2] = useState(true); +// return ( +//
+// +// {isOpen2 && ( +// <> +// +// +// +// )} +//
+// ); +// } + +function MovieList({ movies }) { return (
    {movies?.map((movie) => ( @@ -151,28 +178,6 @@ function Movie({ movie }) { ); } -function WatchedBox() { - const [watched, setWatched] = useState(tempWatchedData); - const [isOpen2, setIsOpen2] = useState(true); - - return ( -
    - - {isOpen2 && ( - <> - - - - )} -
    - ); -} - function WatchedSummary({ watched }) { const avgImdbRating = average(watched.map((movie) => movie.imdbRating)); const avgUserRating = average(watched.map((movie) => movie.userRating));