-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: 변경된 DTO에 따른 로직 변경 및 blogId 전역관리 * chore: 변수명 변경 * Update src/components/UserContext/index.tsx Co-authored-by: SeongMin Kim <[email protected]> * refactor: 성능 최적화를 위한 useMemo 사용 * fix: 빌드 오류 * fix: 경로 오류 수정 * refactor: userContextWrapper 파일 구조 리팩토링 * fix: 빌드 오류 수정 * feat: blog api 연결 * feat: 앨범 렌더링을 위한 Slider 구현 * feat: 확대 및 축소 아이콘 추가 * refactor: pr 리뷰 반영 * refactor: useSlider구현을 통한 비지니스 로직 분리 --------- Co-authored-by: SeongMin Kim <[email protected]>
- Loading branch information
1 parent
af4615f
commit 5fffbdb
Showing
19 changed files
with
296 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
'use client'; | ||
|
||
import React from 'react'; | ||
import Image from 'next/image'; | ||
import { Button } from '@/components/Common'; | ||
import { useSlider } from './useSlider'; | ||
|
||
export default function Slider({ photos }: { photos: string[] }) { | ||
const temp = '/tempImage/6.jpg'; | ||
const { currentIndex, nextSlide, prevSlide } = useSlider(photos.length); | ||
|
||
return ( | ||
<div className="relative w-full overflow-hidden shadow-lg"> | ||
<div | ||
className="flex transform transition-transform duration-1000 ease-in-out" | ||
style={{ transform: `translateX(-${currentIndex * 100}%)` }} | ||
> | ||
{photos.map((photo) => ( | ||
<div key={photo} className="relative flex-none w-1/5 h-200"> | ||
<div className="w-full h-full"> | ||
<Image | ||
alt="photo" | ||
src={photo || temp} | ||
layout="fill" | ||
objectFit="cover" | ||
/> | ||
</div> | ||
</div> | ||
))} | ||
</div> | ||
<div className="absolute inset-0 flex items-center justify-between px-4"> | ||
<Button | ||
className="p-2 bg-[#f1efef] rounded-full opacity-50 hover:opacity-90" | ||
onClick={prevSlide} | ||
> | ||
< Prev | ||
</Button> | ||
<Button | ||
className="p-2 bg-[#f1efef] rounded-full opacity-50 hover:opacity-90" | ||
onClick={nextSlide} | ||
> | ||
Next > | ||
</Button> | ||
</div> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,26 @@ | ||
import Image from 'next/image'; | ||
import { range } from '@/utils'; | ||
'use client'; | ||
|
||
import { useBlogPageContext } from '../BlogFetcher/BlogContext'; | ||
import Slider from './\bSlider'; | ||
|
||
export default function Albums() { | ||
const imageCount = 5; | ||
const images = range(0, imageCount); | ||
const { | ||
blogPostItem: { postItems }, | ||
} = useBlogPageContext(); | ||
|
||
// FIXME: photoUrl 적용 | ||
const photos = Array(20) | ||
.fill(null) | ||
.map((_, index) => postItems[index]?.photo || '/tempImage/6.jpg'); | ||
|
||
return ( | ||
<article className="flex flex-col px-100 items-start"> | ||
<article className="flex flex-col w-full gap-20 px-100 items-start"> | ||
<div className="flex flex-col justify-center items-center"> | ||
<div className="font-extrabold text-4xl">Albums</div> | ||
<p className="w-135 h-3 bg-primary mb-2" /> | ||
<p className="w-145 h-3 bg-primary mb-2" /> | ||
</div> | ||
<div className="flex flex-row gap-10 py-40"> | ||
{images.map((image) => ( | ||
<div key={image} className="w-150 h-150 relative overflow-hidden"> | ||
<Image | ||
alt={`Image ${image}`} | ||
src={`/tempImage/${image}.jpg`} | ||
layout="fill" | ||
objectFit="cover" | ||
/> | ||
</div> | ||
))} | ||
</div> | ||
<Slider photos={photos} /> | ||
</article> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { useState, useCallback } from 'react'; | ||
|
||
export function useSlider(totalSlides: number) { | ||
const [currentIndex, setCurrentIndex] = useState(0); | ||
|
||
const nextSlide = useCallback(() => { | ||
setCurrentIndex((prevIndex) => | ||
prevIndex === Math.ceil(totalSlides / 5) - 1 ? 0 : prevIndex + 1, | ||
); | ||
}, [totalSlides]); | ||
|
||
const prevSlide = useCallback(() => { | ||
setCurrentIndex((prevIndex) => | ||
prevIndex === 0 ? Math.ceil(totalSlides / 5) - 1 : prevIndex - 1, | ||
); | ||
}, [totalSlides]); | ||
|
||
return { currentIndex, nextSlide, prevSlide }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
'use client'; | ||
|
||
import { Button } from '@/components/Common'; | ||
import { useErrorBoundaryContext } from '@/react-utils/ErrorboundaryContext'; | ||
import { StrictPropsWithChildren } from '@/types'; | ||
|
||
export default function BlogFallback({ children }: StrictPropsWithChildren) { | ||
const { error, resetErrorBoundary } = useErrorBoundaryContext(); | ||
|
||
if (error !== null) { | ||
// TODO: 변경 | ||
return <Button onClick={() => resetErrorBoundary()}>다시 시도하기</Button>; | ||
} | ||
return children; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
'use client'; | ||
|
||
import { generateContext } from '@/react-utils'; | ||
import { BlogPageInfo } from './types'; | ||
|
||
export const [BlogPageProvider, useBlogPageContext] = | ||
generateContext<BlogPageInfo>({ | ||
name: 'blog-page', | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { http } from '@/api'; | ||
import { BlogPageInfo } from './types'; | ||
|
||
export const getBlogPageInfo = (blogId: number) => | ||
http.get<BlogPageInfo>({ | ||
url: `/blogs/${blogId}`, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
'use client'; | ||
|
||
import { ReactNode } from 'react'; | ||
import { BlogPageProvider } from './BlogContext'; | ||
import { useBlogPage } from './queries'; | ||
|
||
interface BlogPageFetcherProps { | ||
children: ReactNode; | ||
blogId: number; | ||
} | ||
|
||
export function BlogPageFetcher({ children, blogId }: BlogPageFetcherProps) { | ||
const { data } = useBlogPage(blogId); | ||
|
||
return <BlogPageProvider {...data}>{children}</BlogPageProvider>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
'use client'; | ||
|
||
import { useSuspenseQuery } from '@tanstack/react-query'; | ||
import { getBlogPageInfo } from './api'; | ||
|
||
export const useBlogPage = (blogId: number) => | ||
useSuspenseQuery({ | ||
queryKey: ['blog-page', blogId], | ||
queryFn: () => getBlogPageInfo(blogId), | ||
refetchOnMount: false, | ||
select: (data) => data.result, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
export interface BlogPageInfo { | ||
blogInfo: { | ||
title: string; | ||
description: string; | ||
profile: string; | ||
background: string; | ||
}; | ||
blogPostItem: { | ||
postItems: [ | ||
{ | ||
blogId: number; | ||
postId: number; | ||
title: string; | ||
preview: string; | ||
photo: string; | ||
}, | ||
]; | ||
hashtagNames: string[]; | ||
}; | ||
memberName: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,27 @@ | ||
import { AsyncBoundaryWithQuery } from '@/react-utils'; | ||
import type { Metadata } from 'next'; | ||
import BlogFallback from './components/BlogFallback'; | ||
import { BlogPageFetcher } from './components/BlogFetcher'; | ||
|
||
export const metadata: Metadata = { | ||
title: 'myblog', | ||
description: 'Glue - myblog', | ||
title: 'Glue - blog', | ||
description: 'Glue - blog', | ||
}; | ||
|
||
export default function layout({ children }: { children: React.ReactNode }) { | ||
return <main>{children}</main>; | ||
export default function layout({ | ||
children, | ||
params: { blogId }, | ||
}: { | ||
children: React.ReactNode; | ||
params: { blogId: number }; | ||
}) { | ||
return ( | ||
<AsyncBoundaryWithQuery pendingFallback={<div> Loading...</div>}> | ||
<BlogFallback> | ||
<BlogPageFetcher blogId={blogId}> | ||
<main className="text-[#171717]">{children}</main>; | ||
</BlogPageFetcher> | ||
</BlogFallback> | ||
</AsyncBoundaryWithQuery> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.