-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[6주차] Reddigg 미션 제출합니다. #16
base: master
Are you sure you want to change the base?
Changes from 1 commit
53decb6
a9080c0
8b3043d
f04e1db
b4924aa
d2d191d
c096392
37d627d
f272385
b2bc562
3b08625
311dfd8
86c4616
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,48 @@ | ||
"use client"; | ||
|
||
import React from "react"; | ||
import React, { useEffect, useState } from "react"; | ||
import tmdbApi, { requests } from "@/components/api"; | ||
import NavBar from "@/components/navbar"; | ||
import SearchBar from "./searchBar"; | ||
import { renderMovieLists } from "../utils/movieFunctions"; | ||
import { render } from "react-dom"; | ||
|
||
type Props = {}; | ||
interface Movie { | ||
id: number; | ||
title: string; | ||
poster_path: string; | ||
backdrop_path: string; | ||
overview: string; | ||
} | ||
|
||
function Search({}: Props) { | ||
const [topRated, setTopRated] = useState<Movie[]>([]); | ||
useEffect(() => { | ||
const fetchMovies = async () => { | ||
try { | ||
const [topRatedData] = await Promise.all([ | ||
tmdbApi.get(requests.fetchTopRated), | ||
]); | ||
setTopRated(topRatedData.data.results); | ||
} catch (error) { | ||
console.error("Failed to fetch movies:", error); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. try-cath문으로 에러처리까지 고려하신 점 잘하신 거 같아요:) |
||
}; | ||
fetchMovies(); | ||
}, []); | ||
|
||
return ( | ||
<div className="flex flex-col items-center justify-center w-full h-screen"> | ||
<div className="flex flex-col items-center w-full h-screen"> | ||
<SearchBar /> | ||
<h3 className="pl-[0.25rem] text-white text-preview font-bold"> | ||
|
||
<h3 className="pl-[0.63rem] pt-[117px] text-start text-white text-preview font-bold mb-[1.3rem] w-[375px]"> | ||
Top Searches | ||
</h3> | ||
|
||
<div className="flex flex-col items-center justify-center w-full pb-[60px] overflow-y-auto"> | ||
{renderMovieLists(topRated)} | ||
</div> | ||
<NavBar /> | ||
</div> | ||
); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. utils 함수에 render 관련 함수들을 모아준게 가독성이 좋습니다!! |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,15 @@ | ||
import { SquareImg, Previews, BackgroundImg } from "@/components/ImageType"; | ||
import { | ||
SquareImg, | ||
Previews, | ||
BackgroundImg, | ||
SearchMovieImg, | ||
} from "@/components/ImageType"; | ||
import { useEffect, useState, useMemo } from "react"; | ||
import { SquareForRankingIcon, Top10Icon } from "../../../public/svgs"; | ||
import { | ||
SquareForRankingIcon, | ||
Top10Icon, | ||
PlayCircleIcon, | ||
} from "../../../public/svgs"; | ||
import Link from "next/link"; | ||
|
||
interface Movie { | ||
|
@@ -92,3 +101,25 @@ export const renderBoxMovies = (movies: Movie[]) => { | |
export const getImageUrl = (posterPath: string) => { | ||
return `https://image.tmdb.org/t/p/w500${posterPath}`; | ||
}; | ||
|
||
//search 페이지에 사용될 함수 | ||
export const renderMovieLists = (movies: Movie[]) => { | ||
return movies.map((movie) => ( | ||
<div key={movie.id}> | ||
<Link | ||
href={{ | ||
pathname: `/movie-detail/${movie.id}`, | ||
query: { path: movie.backdrop_path, overview: movie.overview }, | ||
}} | ||
> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 검색 페이지에서 클릭하면 상세 화면으로 이동하게 구현하신 점 좋아요 👍 |
||
<div className="flex flex-row items-center justify-between bg-[#424242] w-[375px] h-[76px] mb-[0.2rem] relative"> | ||
<SearchMovieImg imageUrl={getImageUrl(movie.poster_path)} /> | ||
<span className="text-start w-[160px] text-white text-sm font-normal"> | ||
{movie.title} | ||
</span> | ||
<PlayCircleIcon className="mr-[0.75rem]" /> | ||
</div> | ||
</Link> | ||
</div> | ||
)); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이렇게 바꿀 수 있을 거 같습니다!