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
12 changes: 7 additions & 5 deletions src/app/home/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ interface Movie {
id: number;
title: string;
poster_path: string;
backdrop_path: string;
overview: string;
}

function Home() {
Expand Down Expand Up @@ -62,15 +64,15 @@ function Home() {
<h3 className="pl-[0.25rem] text-white mb-[1.44rem] text-preview font-bold">
Previews
</h3>
<ImageBox className="flex wrap space-x-[0.44rem] w-[100%] justify-start">
<ImageBox className="flex wrap space-x-[0.44rem] w-full justify-start">
{renderRoundMovies(topRated)}
</ImageBox>

<ImageBox className="pl-[0.75rem] w-[100%] flex flex-col">
<ImageBox className="pl-[0.75rem] w-full flex flex-col">
<h3 className="pl-[0.25rem] text-white mt-[14px] mb-[1.44rem] text-popular font-bold">

Choose a reason for hiding this comment

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

Next에서 CSS적용할 때, SSR 방식으로 구현하는 점을 생각하면 Tailwind css 사용하는 게 제일 좋은 방법인 거 같아요:) 막상도입하는데 쉽지 않으셨을 거 같은데, 고생많으셨습니다!

Continue Watching for Emenalo
</h3>
<ImageBox className="flex wrap space-x-[7px] w-[100%] justify-start">
<ImageBox className="flex wrap space-x-[7px] w-full justify-start">
{renderBoxMovies(nowPlaying)}
</ImageBox>
</ImageBox>
Expand All @@ -79,12 +81,12 @@ function Home() {
<h3 className="pl-[0.25rem] text-white mt-[14px] mb-[1.44rem] text-popular font-bold">
Popular on Netflix
</h3>
<ImageBox className="flex wrap space-x-[7px] w-[100%] justify-start">
<ImageBox className="flex wrap space-x-[7px] w-full justify-start">
{renderBoxMovies(popular)}
</ImageBox>
</ImageBox>

<ImageBox className="pl-[0.75rem] w-[100%] flex flex-col">
<ImageBox className="pl-[0.75rem] w-full flex flex-col">
<h3 className="pl-[0.25rem] text-white mt-[14px] mb-[1.44rem] text-popular font-bold">
Tranding Now
</h3>
Expand Down
34 changes: 34 additions & 0 deletions src/app/movie-detail/[movieId]/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"use client";

import React from "react";
import NavBar from "@/components/navbar";
import { BackgroundImg } from "@/components/ImageType";
import { getImageUrl } from "@/app/utils/movieFunctions";
import { PlayButton } from "@/components/Play";
import { useSearchParams } from "next/navigation";
type Props = {};

function MovieId({}: Props) {
const searchParams = useSearchParams();
const backdrop_path = searchParams.get("path");
const overview = searchParams.get("overview");

return (
<div className="flex flex-col items-center justify-center">
{backdrop_path ? (
<BackgroundImg imageUrl={getImageUrl(backdrop_path)} />
) : null}
<PlayButton />

<h3 className="pl-[0.25rem] text-white mt-[2rem] pl-[2rem] text-preview font-bold w-[375px]">
Previews
</h3>
<div className="text-custom-white text-explain mt-[1.5rem] px-[2rem] leading-[0.88rem] w-[375px]">
{overview}
</div>
<NavBar />
</div>
);
}

export default MovieId;
30 changes: 27 additions & 3 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,11 +1,14 @@
import { SquareImg, Previews, BackgroundImg } from "@/components/ImageType";
import { useEffect, useState, useMemo } from "react";
import { SquareForRankingIcon, Top10Icon } from "../../../public/svgs";
import Link from "next/link";

interface Movie {
id: number;
title: string;
poster_path: string;
backdrop_path: string;
overview: string;
}

//페이지의 가장 위쪽에 랜덤으로 함수를 보여주는 함수
Expand All @@ -32,7 +35,14 @@ export const RandomMovie = ({ movies }: { movies: Movie[] }) => {

return movie ? (
<div className="flex flex-col items-center justify-center w-[100%]">
<BackgroundImg imageUrl={getImageUrl(movie.poster_path)} />
<Link
href={{
pathname: `/movie-detail/${movie.id}`,
query: { path: movie.backdrop_path, overview: movie.overview },
}}
>
<BackgroundImg imageUrl={getImageUrl(movie.poster_path)} />
</Link>
<span className="flex align-center mt-2 md-2">
<div className="relative mr-2">
<SquareForRankingIcon />
Expand All @@ -50,7 +60,14 @@ export const RandomMovie = ({ movies }: { movies: Movie[] }) => {
export const renderRoundMovies = (movies: Movie[]) => {
return movies.map((movie) => (
<div key={movie.id}>
<Previews imageUrl={getImageUrl(movie.poster_path)} />
<Link
href={{
pathname: `/movie-detail/${movie.id}`,
query: { path: movie.backdrop_path, overview: movie.overview },
}}
>
Comment on lines +72 to +77

Choose a reason for hiding this comment

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

Link 태그에서 이런 식으로 쿼리파라미터를 지정해서 넘겨줄 수 있는 점 배워갑니다!
찾아보니까 데이터 노출을 방지하기 위해 as 라는 속성을 이용하면 URL 를 마스킹 할 수도 있다고 해서 참고하시면 좋을 거 같아요!
query데이터 이동방법

Copy link
Member Author

@leejin-rho leejin-rho Nov 18, 2023

Choose a reason for hiding this comment

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

as를 쓰니까 왜인지 useSearchParam이 읽지를 못하더라구요... ㅠㅠ

Choose a reason for hiding this comment

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

저도 배워갑니다!

<Previews imageUrl={getImageUrl(movie.poster_path)} />
</Link>
</div>
));
};
Expand All @@ -59,7 +76,14 @@ export const renderRoundMovies = (movies: Movie[]) => {
export const renderBoxMovies = (movies: Movie[]) => {
return movies.map((movie) => (
<div key={movie.id}>
<SquareImg imageUrl={getImageUrl(movie.poster_path)} />
<Link
href={{
pathname: `/movie-detail/${movie.id}`,
query: { path: movie.backdrop_path, overview: movie.overview },
}}
>
<SquareImg imageUrl={getImageUrl(movie.poster_path)} />
</Link>
</div>
));
};
Expand Down
2 changes: 1 addition & 1 deletion src/components/ImageType.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export const Previews = ({ imageUrl }: { imageUrl: string }) => {
);
};

//홈화면 아래쪽에 보니는 image
//홈화면 아래쪽에 보이는 image
export const SquareImg = ({ imageUrl }: { imageUrl: string }) => {
return (
<div
Expand Down
34 changes: 34 additions & 0 deletions src/components/Play.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"use client";
import styled from "styled-components";
import { MainPlayIcon } from "../../public/svgs";

export const PlayButton = () => {
return (
<Button>
<MainPlayIcon className="mr-[0.94rem]" />
<ButtonText>Play</ButtonText>
</Button>
);
};

const Button = styled.div`
display: flex;
justify-content: center;
align-items: center;
width: 303px;
height: 45px;
display: flex;
border-radius: 5.625px;
margin-top: 0.81rem;
background-color: #c4c4c4;
&:hover {
background-color: #a3a3a3;
}
`;

const ButtonText = styled.span`
color: #000000;
text-align: center;
font-size: 1.27rem;
line-height: 146.61%;
`;
4 changes: 4 additions & 0 deletions tailwind.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,14 @@ const config: Config = {
spacing: {
"25": "1.6rem",
},
colors: {
"custom-white": "rgba(255,255,255,0.83)",
},
fontSize: {
header: "1.1rem",
preview: "1.7rem",
popular: "1.3rem",
explain: "0.7rem",
},
},
},
Expand Down