diff --git a/src/app/page.tsx b/src/app/page.tsx index c10b270..1fe21bb 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -1,7 +1,9 @@ +import { SearchMovies } from "@/components/molecules/SearchMovies"; + export default async function Home() { return (
-

Hello World

+
); } diff --git a/src/components/molecules/SearchMovies/index.tsx b/src/components/molecules/SearchMovies/index.tsx new file mode 100644 index 0000000..b75f312 --- /dev/null +++ b/src/components/molecules/SearchMovies/index.tsx @@ -0,0 +1,37 @@ +"use client"; +import { SearchInput } from "@/components/atoms/SearchInput"; +import { useState } from "react"; +import { TMDB } from "@/lib/tmdb"; +import { MovieCard } from "@/components/atoms/MovieCard"; +import { SearchResult } from "@/lib/tmdb/types"; + +export const SearchMovies = () => { + const [results, setResults] = useState([]); + + const handleSearch = async (query: string) => { + const data = await TMDB.search(query); + setResults(data.results); + }; + + return ( +
+
+
+ +
+
+
+ {results.map((result) => ( + + ))} +
+
+ ); +}; diff --git a/src/lib/tmdb/index.ts b/src/lib/tmdb/index.ts new file mode 100644 index 0000000..6cc8129 --- /dev/null +++ b/src/lib/tmdb/index.ts @@ -0,0 +1,5 @@ +import { search } from "./server"; + +export const TMDB = { + search, +}; diff --git a/src/lib/tmdb/server.ts b/src/lib/tmdb/server.ts new file mode 100644 index 0000000..2e91dd6 --- /dev/null +++ b/src/lib/tmdb/server.ts @@ -0,0 +1,19 @@ +"use server"; + +import { SearchResult } from "./types"; + +const fetchTmbd = async (url: string) => { + const response = await fetch(url, { + headers: { + Authorization: `Bearer ${process.env.TMDB_BEARER}`, + }, + }); + const data = await response.json(); + return data; +}; + +const url = "https://api.themoviedb.org/3"; + +export async function search(query: string): Promise { + return await fetchTmbd(`${url}/search/movie?query=${query}`); +} diff --git a/src/lib/tmdb/types.ts b/src/lib/tmdb/types.ts new file mode 100644 index 0000000..6e94fff --- /dev/null +++ b/src/lib/tmdb/types.ts @@ -0,0 +1,19 @@ +export type SearchResult = { + page: number; + results: { + adult: boolean; + backdrop_path: string; + genre_ids: number[]; + id: number; + original_language: string; + original_title: string; + overview: string; + popularity: number; + poster_path: string; + release_date: string; + title: string; + video: boolean; + vote_average: number; + vote_count: number; + }[]; +};