Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 1 addition & 40 deletions pages/techblog/[id]/index.page.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import React from 'react';

import { GetServerSidePropsContext } from 'next';
import { useRouter } from 'next/router';

import { QueryClient, dehydrate } from '@tanstack/react-query';

import DevLoadingComponent from '@pages/loading/index.page';

import { useLoginStatusStore } from '@stores/loginStore';
Expand All @@ -20,49 +17,13 @@ import { LoginModal } from '@components/common/modals/modal';
import { ROUTES } from '@/constants/routes';
import { useMediaQueryContext } from '@/contexts/MediaQueryContext';

import { getDetailTechBlog, useGetDetailTechBlog } from '../api/useGetTechBlogDetail';
import { useGetDetailTechBlog } from '../api/useGetTechBlogDetail';
import { usePostMainComment } from '../api/usePostComment';
import CommentTechSection from '../components/CommentTechSection';
import CompanyInfoCard from '../components/CompanyInfoCard';
import TechDetailCard from '../components/TechDetailCard';
import { TechCardProps } from '../types/techBlogType';

export async function getServerSideProps(context: GetServerSidePropsContext) {
const id = context.params?.id;

if (!id || typeof id !== 'string') {
return {
notFound: true,
};
}

const queryClient = new QueryClient();

try {
const postData = await getDetailTechBlog(id);
const post = postData.data;

await queryClient.setQueryData(['techDetail', id], postData);

const meta = {
title: post.title,
description: post.contents.substring(0, 150) + '...',
};

return {
props: {
dehydratedState: dehydrate(queryClient),
meta: meta,
},
};
} catch (error) {
console.error(`Error fetching post data for id: ${id}`, error);
return {
notFound: true,
};
}
}

export default function Page() {
const router = useRouter();
const techArticleId = router.query.id as string | undefined;
Expand Down