Skip to content
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

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
2 changes: 2 additions & 0 deletions public/svgs/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import PlusIcon from "./plusIcon.svg";
import Top10Icon from "./top10Icon.svg";
import SearchIcon2 from "./searchIcon2.svg";
import XIcon from "./xIcon.svg";
import PlayCircleIcon from "./playCircleIcon.svg";
import SquareForRankingIcon from "./squareForRanking.svg";
export {
HomeIcon,
Expand All @@ -25,4 +26,5 @@ export {
SquareForRankingIcon,
SearchIcon2,
XIcon,
PlayCircleIcon,
};
4 changes: 4 additions & 0 deletions public/svgs/playCircleIcon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 32 additions & 3 deletions src/app/search/page.tsx
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),
]);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이렇게 바꿀 수 있을 거 같습니다!

Suggested change
const [topRatedData] = await Promise.all([
tmdbApi.get(requests.fetchTopRated),
]);
const topRatedData = await tmdbApi.get(requests.fetchTopRated);

setTopRated(topRatedData.data.results);
} catch (error) {
console.error("Failed to fetch movies:", error);
}

Choose a reason for hiding this comment

The 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>
);
Expand Down
35 changes: 33 additions & 2 deletions src/app/utils/movieFunctions.tsx
Copy link

Choose a reason for hiding this comment

The 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 {
Expand Down Expand Up @@ -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 },
}}
>

Choose a reason for hiding this comment

The 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>
));
};
14 changes: 14 additions & 0 deletions src/components/ImageType.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,17 @@ export const SquareImg = ({ imageUrl }: { imageUrl: string }) => {
</div>
);
};

//search화면에 보이는 영화 리스트 아이템
export const SearchMovieImg = ({ imageUrl }: { imageUrl: string }) => {
return (
<div style={{ width: "9.125rem", height: "4.75rem", position: "relative" }}>
<Image
src={imageUrl}
alt="popularimage"
layout="fill"
objectFit="cover"
/>
</div>
);
};