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

홈 페이지 API 연동 #283

Merged
merged 10 commits into from
Dec 17, 2024
2 changes: 1 addition & 1 deletion src/app/(home)/_components/Header.css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export const headerWrapper = style({
width: '100%',
height: '40px',
padding: '10px 16px',
margin: '0 0 12px',
margin: '0 0 16px',
});

export const entireWrapper = style({
Expand Down
12 changes: 8 additions & 4 deletions src/app/(home)/_components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Link from 'next/link';
import Image from 'next/image';
import { useQuery } from '@tanstack/react-query';

import SearchBarComponent from '@/components/SearchBar';
import SearchBarArea from './SearchBarArea';
import Modal from '@/components/Modal/Modal';
import LoginModal from '@/components/login/LoginModal';

Expand All @@ -24,7 +24,11 @@ import BellIcon from '/public/icons/ver3/bell.svg';
import Avatar from '/public/icons/ver3/Avatar.svg';

function Header() {
const { isOn: isSearchBarOpened, handleSetOn: handleSearchBarOpened } = useBooleanOutput();
const {
isOn: isSearchBarOpened,
handleSetOn: handleSearchBarOpened,
handleSetOff: handleSearchBarClosed,
} = useBooleanOutput();
const { isOn, handleSetOn, handleSetOff } = useBooleanOutput();
const [isLoggedIn, setIsLoggedIn] = useState(false); // 로그인 상태를 관리하는 useState 추가

Expand All @@ -41,7 +45,7 @@ function Header() {
};

const handleInactivateSearchBar = () => {
handleSearchBarOpened();
handleSearchBarClosed();
};

const handleSearchIconClick = () => {
Expand All @@ -55,7 +59,7 @@ function Header() {

return (
<header className={styles.headerWrapper}>
{isSearchBarOpened && <SearchBarComponent handleCancel={handleInactivateSearchBar} />}
{isSearchBarOpened && <SearchBarArea handleCancel={handleInactivateSearchBar} />}
{!isSearchBarOpened && (
<div className={styles.entireWrapper}>
<div className={styles.homeTitleContainer}>
Expand Down
Copy link
Contributor

Choose a reason for hiding this comment

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

나현님, 해당 파일은 3개의 컴포넌트로 구성되어 있는데 컨벤션을 조금 수정하면 좋을 것 같습니다. 👀

  1. 파일이름(HomeRecommendedLists) export 컴포넌트(TrendingList) 일치
  2. export 컴포넌트(TrendingList)의 export default 코드를 TrendingList 컴포넌트에 위치 (지금은 TrendingListItem 컴포넌트에 위치한것 같아요)

Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,19 @@ import { Swiper, SwiperSlide } from 'swiper/react';
import 'swiper/css';
import { Autoplay, EffectCoverflow } from 'swiper/modules';

import getTrendingLists from '@/app/_api/home/getTrendingLists';
import getHomeRecommendedLists from '@/app/_api/home/getHomeRecommendedLists';
import { QUERY_KEYS } from '@/lib/constants/queryKeys';
import { TrendingListType } from '@/lib/types/exploreType';
import { TRENDINGLISTS_DATA } from '../mock/mockdata';
import { HomeRecommendedListType } from '@/lib/types/homeType';

import * as styles from './TrendingLists.css';
import * as styles from './HomeRecommendedLists.css';
import { vars } from '@/styles/theme.css';
import { TrendingListsSkeleton } from '../../../components/exploreComponents/Skeleton';

function TrendingList() {
// 오류로인해 주석처리 해 둠
// const { data: trendingLists, isFetching } = useQuery({
// queryKey: [QUERY_KEYS.getTrendingLists],
// queryFn: () => getTrendingLists(),
// });
const { data: recommendedLists, isFetching } = useQuery({
queryKey: [QUERY_KEYS.getHomeRecommendedLists],
queryFn: () => getHomeRecommendedLists(),
});

const SWIPER_STYLE = useMemo(
() => ({
Expand All @@ -48,7 +46,7 @@ function TrendingList() {
<section className={styles.wrapper}>
<div className={styles.listWrapper}>
<div className={styles.slide}>
{TRENDINGLISTS_DATA && TRENDINGLISTS_DATA.length > 0 && (
{recommendedLists && recommendedLists.length > 0 && (
Comment on lines 43 to +44
Copy link
Contributor

Choose a reason for hiding this comment

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

한가지 궁금증이 혹시 추천리스트가 없을때는 무엇을 보여주는 것인가요?! 아니면 해당 API는 반드시 리스폰스(=리스트)가 존재하나요?! 👀

Copy link
Contributor Author

Choose a reason for hiding this comment

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

스켈레톤을 보여주어야 하는데 이 부분은 시간이 부족하여 작업을 하지 못했습니다 ㅠㅠ 추후 리팩토링 시 작업하겠습니다!

<Swiper
slidesPerView={'auto'}
grabCursor={true}
Expand All @@ -63,7 +61,7 @@ function TrendingList() {
className="mySwiper"
style={SWIPER_STYLE}
>
{TRENDINGLISTS_DATA.map((item, index) => (
{recommendedLists.map((item, index) => (
<SwiperSlide key={index} className={styles.sliderItem} style={SWIPER_SLIDER_STYLE}>
<TrendingListItem item={item} index={index} />
</SwiperSlide>
Expand All @@ -77,7 +75,7 @@ function TrendingList() {
}

interface TrendingListItemProps {
item: any;
item: HomeRecommendedListType;
index: number;
}

Expand Down Expand Up @@ -116,7 +114,7 @@ function TrendingListItem({ item }: TrendingListItemProps) {
export default TrendingList;

interface TrendingListInformationType {
item?: TrendingListType;
item?: HomeRecommendedListType;
}

function TrendingListInformation({ item }: TrendingListInformationType) {
Expand All @@ -133,11 +131,12 @@ function TrendingListInformation({ item }: TrendingListInformationType) {
<p className={styles.listOwner}>{item.ownerNickname}</p>
</div>
<ul className={styles.top3Wrapper}>
{item.top3.map((el, idx) => (
<li key={idx} className={item.itemImageUrl ? styles.top3ItemWithImage : styles.top3ItemNoImage}>
{`${idx + 1}. ${el.title}`}
</li>
))}
{item &&
item?.items?.map((el, idx) => (
<li key={idx} className={item.itemImageUrl ? styles.top3ItemWithImage : styles.top3ItemNoImage}>
{`${idx + 1}. ${el.title}`}
</li>
))}
</ul>
</div>
);
Expand Down
2 changes: 1 addition & 1 deletion src/app/(home)/_components/RecommendationFeed.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import UsersRecommendation from '@/components/exploreComponents/RecommendedUsers';
import TopicsRecommendation from '@/app/(home)/_components/TopicsRecommendation';
import TrendingList from '@/app/(home)/_components/TrendingLists';
import TrendingList from '@/app/(home)/_components/HomeRecommendedLists';

function RecommendationFeed() {
return (
Expand Down
35 changes: 35 additions & 0 deletions src/app/(home)/_components/SearchBarArea.css.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { style } from '@vanilla-extract/css';

export const wrapper = style({
width: '100%',

display: 'flex',
alignItems: 'center',
});

export const inputWrapper = style({
width: '100%',

display: 'flex',
alignItems: 'center',
});

export const input = style({
width: '100%',

fontSize: '1.6rem',
overflow: 'hidden',
'::placeholder': {
color: '#637587',
fontWeight: '400',
fontSize: '1.6rem',
},
});

export const cancelButton = style({
flexShrink: 0,
fontWeight: '400',
fontSize: '1.6rem',
letterSpacing: '-3%',
color: '#213752',
});
21 changes: 21 additions & 0 deletions src/app/(home)/_components/SearchBarArea.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import * as styles from './SearchBarArea.css';
import SearchBar from '@/components/SearchBar';

interface SearchBarProps {
handleCancel?: () => void;
}

function SearchBarArea({ handleCancel }: SearchBarProps) {
return (
<div className={styles.wrapper}>
<div className={styles.inputWrapper}>
<SearchBar />
</div>
<button className={styles.cancelButton} onClick={handleCancel}>
취소
</button>
</div>
);
}

export default SearchBarArea;
1 change: 1 addition & 0 deletions src/app/(home)/_components/TopicsRecommendation.css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export const topic = style({
fontSize: '1.5rem',
letterSpacing: '-3%',
color: '#292929',
cursor: 'pointer',
});

export const topicButton = style([
Expand Down
46 changes: 34 additions & 12 deletions src/app/(home)/_components/TopicsRecommendation.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,39 @@
'use client';
import Link from 'next/link';
import { useRouter } from 'next/navigation';
import { useQuery } from '@tanstack/react-query';
import { QUERY_KEYS } from '@/lib/constants/queryKeys';
import getRecommendedTopics from '@/app/_api/home/getRecommendedTopics';

import * as styles from './TopicsRecommendation.css';
/**목데이터 지우기 */
import { TopicsData } from '../mock/mockdata';

/* @TODO 스켈레톤 구현 */
function TopicsRecommendation() {
const { data: topicLists, isFetching } = useQuery({
queryKey: [QUERY_KEYS.getRecommendedTopics],
queryFn: () => getRecommendedTopics(),
});

return (
<section className={styles.wrapper}>
<div className={styles.sectionTitleWrapper}>
<div className={styles.sectionTitle}>이 주제로 만들어 보세요</div>
<Link href={'/'}>
<Link href={'/topics'}>
<span className={styles.showMoreButton}>더보기</span>
</Link>
</div>
<ul className={styles.itemsWrapper}>
{TopicsData.map((el, idx) => {
return (
<li key={idx}>
<TopicItem title={el} />
</li>
);
})}
<button className={styles.topicButton}>주제 요청하기→</button>
{topicLists &&
topicLists?.map((el, idx) => {
return (
<li key={idx}>
<TopicItem title={el.title} />
</li>
);
})}
<Link href={'/topics'}>
<button className={styles.topicButton}>주제 요청하기→</button>
</Link>
</ul>
</section>
);
Expand All @@ -34,5 +46,15 @@ interface TopicItemProps {
}

function TopicItem({ title }: TopicItemProps) {
return <div className={styles.topic}>{title}</div>;
const router = useRouter();

const handleTopicClick = (title: string) => {
router.push(`/list/create?title=${title}`);
};

return (
<div className={styles.topic} onClick={() => handleTopicClick(title)}>
{title}
</div>
);
}
Loading
Loading