인프런 커뮤니티 질문&답변

장산님의 프로필 이미지

작성한 질문수

기초부터 배우는 Next YTMusic 클론 코딩 (with next.js 14, UI 마스터)

11.5 Channel 노래,앨범 section

11.5 Channel 노래,앨범 section 강의중

해결된 질문

24.07.30 01:04 작성

·

91

0

안녕하세요 선생님 ㅎ

channel쪽 진행하고 있었는데 앨범 밑에 PlayListCarousel이

크기가 이상하게 나오네여 ㅠㅠ 코드를 다똑같이 써도 안되서 질문드립니다!

스크린샷 2024-07-30 오전 12.57.25.png

channel/[id]/page.tsx

import HeaderBgChanger from "@/components/HeaderBgChanger";
import PagePadding from "@/components/PagePadding";
import PlayListCarousel from "@/components/PlayListCarousel";
import SongCardRowExpand from "@/components/SongCardRowExpand";
import DarkButton from "@/components/elements/DarkButton";
import WhiteButton from "@/components/elements/WhiteButton";
import { getChannelById } from "@/lib/dummyData";
import { getRandomElementFromArray } from "@/lib/utils";
import { permanentRedirect } from "next/navigation";
import React from "react";
import { FiMusic, FiShuffle } from "react-icons/fi";

interface ChannelPageProps {
  params: {
    id: string;
  };
}

const page = async (props: ChannelPageProps) => {
  const channel = await getChannelById(Number(props.params.id));

  if (!channel) permanentRedirect("/");

  const imageSrc = getRandomElementFromArray(channel.songList)?.imageSrc;

  return (
    <PagePadding>
      <HeaderBgChanger imageSrc={imageSrc} />
      <div className="mt-[150px]"></div>
      <section>
        <div className=" text-[28px] font-bold">{channel.name}</div>
        <article className="mt-4 lg:hidden">
          <div>
            <DarkButton
              className={"w-[230px] flex justify-center"}
              label={"구독중 99만"}
            />
          </div>
          <div className="flex flex-row gap-4 mt-4">
            <WhiteButton
              label={"셔플"}
              icon={<FiShuffle size={16}></FiShuffle>}
            />
            <WhiteButton label={"뮤직 스테이션"} icon={<FiMusic size={16} />} />
          </div>
        </article>
        <div className="hidden lg:flex flex-row items-center gap-4 text-[14px] mt-4">
          <WhiteButton
            label={"셔플"}
            icon={<FiShuffle size={16}></FiShuffle>}
          />
          <WhiteButton label={"뮤직 스테이션"} icon={<FiMusic size={16} />} />
          <DarkButton
            className={"w-[230px] flex justify-center"}
            label={"구독중 99만"}
          />
        </div>
      </section>
      <section className="mt-[80px]">
        <div className=" text-[28px] font-bold">노래</div>
        <div className="mt-[20px]">
          <ul className="flex flex-col gap-2">
            {channel.songList.map((song, key) => {
              return <SongCardRowExpand song={song} key={key} />;
            })}
          </ul>
        </div>
      </section>
      <section className="mt-[80px]">
        <div className=" text-[28px] font-bold">앨범</div>
        <PlayListCarousel playlistArray={channel.playlistArray} />
      </section>
      <section className="mt-[80px]"></section>
    </PagePadding>
  );
};

export default page;

PlayListCarousel.tsx

import { Playlist } from "@/types";
import React from "react";
import {
  Carousel,
  CarouselContent,
  CarouselItem,
  CarouselNext,
  CarouselPrevious,
} from "@/components/ui/carousel";
import PlayListCard from "./PlayListCard";

interface PlayListCarouselProps {
  title?: string;
  subTitle?: string;
  Thumbnail?: React.ReactNode;
  playlistArray?: Playlist[];
}

const PlayListCarousel: React.FC<PlayListCarouselProps> = ({
  title,
  subTitle,
  Thumbnail,
  playlistArray,
}) => {
  return (
    <div className="w-full">
      <Carousel>
        <div className="flex flex-row justify-between items-end my-2">
          <article className="flex flex-row gap-3">
            {Thumbnail}
            <div className="flex flex-col justify-center">
              <div>
                {subTitle && (
                  <div className=" text-neutral-500">{subTitle}</div>
                )}
              </div>
              <div className="text-[34px] font-bold leading-[34px] ">
                {title}
              </div>
            </div>
          </article>
          <div className="relative left-[-45px]">
            <div className="absolute bottom-[20px]">
              <CarouselPrevious className="right-2" />
              <CarouselNext className=" left-2" />
            </div>
          </div>
        </div>
        <CarouselContent className="mt-4">
          {playlistArray?.map((playlist, index) => {
            return (
              <CarouselItem
                key={index}
                className="basis-1/2 md:basis-1/3 lg:basis-1/4 xl:basis-1/5"
              >
                <PlayListCard playlist={playlist} />
              </CarouselItem>
            );
          })}
        </CarouselContent>
      </Carousel>
    </div>
  );
};

export default PlayListCarousel;

답변 1

1

도도(코딩루팡)님의 프로필 이미지
도도(코딩루팡)
지식공유자

2024. 07. 30. 21:13

안녕하세요.!

 

UI화면을 보니, 상위 컴포넌트의 너비값에 문제가 있는것 같습니다.

 

1.아래 컴포넌트를 살펴보면서 디버깅을 해주세요.!

https://github.com/dodokyo/yt-music-clone/blob/main/components/PagePadding.jsx

https://github.com/dodokyo/yt-music-clone/blob/main/app/channel/%5Bid%5D/layout.tsx

  • 높은 확률로 layout 컴포넌트에서 w-full 이 빠졌을까 예측해봅니다.

2.크롬 개발자 도구를 통해서 어떤 요소에서 너비가 줄어들었는지 알면 좋습니다.

 

장산님의 프로필 이미지
장산
질문자

2024. 07. 30. 21:19

  1. 확인 결과

layout

import Header from "@/components/Header";
import React from "react";

const layout = ({ children }: { children: React.ReactNode }) => {
  return (
    <div className="w-full h-full">
      <Header>{children}</Header>
    </div>
  );
};

export default layout;

pagepadding

import React from "react";

const PagePadding = ({ children }) => {
  return (
    <div className=" mx-auto px-[10px] py-2 lg:px-[100px]">{children}</div>
  );
};

export default PagePadding;

코드에서 이상은 없는데

2.지금 개발자 도구를 통해서 보고있는데 테일윈드라 가독성이 좀 떨어져서 오래걸리네여 ㅠㅠ

장산님의 프로필 이미지
장산
질문자

2024. 07. 30. 22:08

안녕하세요 도도님!

해결했습니다!

원인이 Header.jsx에서 96줄

  <section className="relative">{children}</section>

relative 부분이 absolute로 되어있었습니다! 감사합니다

도도(코딩루팡)님의 프로필 이미지
도도(코딩루팡)
지식공유자

2024. 07. 30. 22:16

원인을 찾아서 다행입니다.! 또 질문있으면 언제든 주세요.

장산님의 프로필 이미지

작성한 질문수

질문하기