Skip to content

Commit c9b596f

Browse files
committed
feat: add 'load more' functionality to related posts section
1 parent ea0e26d commit c9b596f

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

pages/post/[id].tsx

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,13 @@ export const getStaticProps: ({params}: { params: any }) => Promise<{
5656

5757
export default function Post({ postData, relatedPosts }: InferGetStaticPropsType<typeof getStaticProps>) {
5858
const [toc, activeId] = useTocObserver();
59-
6059
const scrollRef = useRef<HTMLDivElement>(null);
6160
const [showScrollHint, setShowScrollHint] = useState(false);
6261

62+
const [visibleRelatedCount, setVisibleRelatedCount] = useState(3);
63+
const visibleRelatedPosts = relatedPosts.slice(0, visibleRelatedCount);
64+
const hasMoreRelated = visibleRelatedCount < relatedPosts.length;
65+
6366
useEffect(() => {
6467
const el = scrollRef.current;
6568
if (el && el.scrollHeight > el.clientHeight) {
@@ -120,12 +123,13 @@ export default function Post({ postData, relatedPosts }: InferGetStaticPropsType
120123
<h2 className="text-xl font-bold flex items-center gap-2 mb-6">
121124
🏷️ <span>같은 태그의 글 보기</span>
122125
</h2>
126+
123127
<ul className="space-y-4">
124-
{relatedPosts.map((post) => (
128+
{visibleRelatedPosts.map((post) => (
125129
<li key={post.id} className="flex flex-col">
126130
<Link
127131
href={`/post/${post.id}`}
128-
className="text-lg font-medium text-blue-600 hover:underline dark:text-blue-400"
132+
className="text-base font-medium text-gray-800 hover:text-blue-600 no-underline dark:text-gray-100 dark:hover:text-blue-400 transition"
129133
>
130134
{post.title}
131135
</Link>
@@ -135,6 +139,17 @@ export default function Post({ postData, relatedPosts }: InferGetStaticPropsType
135139
</li>
136140
))}
137141
</ul>
142+
{/* 더 보기 버튼 */}
143+
{hasMoreRelated && (
144+
<div className="mt-6 text-center">
145+
<button
146+
onClick={() => setVisibleRelatedCount((prev) => prev + 5)}
147+
className="px-5 py-2 text-sm font-medium rounded-md bg-gray-200 hover:bg-gray-300 text-gray-800 dark:bg-gray-700 dark:hover:bg-gray-600 dark:text-white transition"
148+
>
149+
더 보기
150+
</button>
151+
</div>
152+
)}
138153
</div>
139154
)}
140155
</main>

0 commit comments

Comments
 (0)