diff --git a/src/api/watchlist.api.ts b/src/api/watchlist.api.ts new file mode 100644 index 0000000..cfbdd5a --- /dev/null +++ b/src/api/watchlist.api.ts @@ -0,0 +1,21 @@ +import axios from 'axios'; + +const BASE_URL: string = 'http://localhost:3000'; + +interface Movie { + id: number; + title: string; + overview: string; + release_date: string; + userId: number; +} + +export const getWatchlist = async (accessToken: string): Promise => { + const res = await axios.get(`${BASE_URL}/movies/watchlist`, { + headers: { + Authorization: `Bearer ${accessToken}`, + }, + }); + const movies: Movie[] = res.data; + return movies; +}; diff --git a/src/app/watchlist/page.tsx b/src/app/watchlist/page.tsx new file mode 100644 index 0000000..1c7aa30 --- /dev/null +++ b/src/app/watchlist/page.tsx @@ -0,0 +1,5 @@ +import WatchlistModule from '@/modules/watchlist/watchlist'; + +export default function Page() { + return ; +} diff --git a/src/components/header/header.tsx b/src/components/header/header.tsx index f91ebe2..737067c 100644 --- a/src/components/header/header.tsx +++ b/src/components/header/header.tsx @@ -55,23 +55,31 @@ const Header: React.FC = () => { Movies Catalog - {user ? ( - - ) : ( +
-

Login

- + Watchlist - )} + {user ? ( + + ) : ( + +

Login

+ + + )} +
); diff --git a/src/modules/watchlist/watchlist.tsx b/src/modules/watchlist/watchlist.tsx new file mode 100644 index 0000000..0a55ad1 --- /dev/null +++ b/src/modules/watchlist/watchlist.tsx @@ -0,0 +1,71 @@ +'use client'; + +import React, { useEffect, useState } from 'react'; +import { getCookie } from 'cookies-next'; +import { getWatchlist } from '@/api/watchlist.api'; +import { SquareArrowOutUpRight } from 'lucide-react'; +import Link from 'next/link'; + +interface Movie { + id: number; + title: string; + overview: string; + release_date: string; + userId: number; +} + +const WatchlistModule = () => { + const [watchlist, setWatchlist] = useState([]); + const accessToken = getCookie('accessToken') as string; + + useEffect(() => { + const fetchWatchlist = async () => { + try { + const res = await getWatchlist(accessToken); + console.log('WATCHLIST'); + console.log(res); + setWatchlist(res); + } catch (e) { + console.log(e); + } + }; + fetchWatchlist(); + }, []); + + return ( +
+ {watchlist.length === 0 ? ( +
+ Your watchlist is empty :{`(`} +
+ ) : ( +
+

+ Watchlist +

+
+
+ {watchlist.map((movie, index) => ( +
+
+

+ {movie.title} {movie.release_date.split('-')[0]} +

+

{movie.overview}

+
+ + + +
+ ))} +
+
+ )} +
+ ); +}; + +export default WatchlistModule;