Skip to content

Commit eaecd23

Browse files
Merge pull request #86 from ShipFriend0516/fix/when-edit-mode-series-not-matched
fix: 수정시 시리즈 기본 값으로 지정되는 문제 해결
2 parents f5302e2 + 95ee7ad commit eaecd23

File tree

4 files changed

+27
-7
lines changed

4 files changed

+27
-7
lines changed

app/admin/write/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export const generateMetadata = async (): Promise<Metadata> => {
99

1010
const BlogWritePage = () => {
1111
return (
12-
<section className={'p-6 max-w-7xl mx-auto'}>
12+
<section className={'py-6 px-2 max-w-8xl mx-auto'}>
1313
<BlogForm />
1414
</section>
1515
);

app/api/posts/[slug]/route.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,17 @@ export async function PUT(
4747
const body = await req.json();
4848
const post = await Post.findOne({ slug: params.slug });
4949

50+
let thumbnailOfPost = getThumbnailInMarkdown(body.content);
51+
if (!thumbnailOfPost) {
52+
const seriesThumbnail = await Series.findById(body.seriesId).select('thumbnailImage');
53+
thumbnailOfPost =
54+
seriesThumbnail?.thumbnailImage ||
55+
'/images/placeholder/thumbnail_example2.webp';
56+
}
57+
5058
const updatedPost = await Post.findOneAndUpdate(
5159
{ slug: params.slug },
52-
{ ...body, thumbnailImage: getThumbnailInMarkdown(body.content) },
60+
{ ...body, thumbnailImage: thumbnailOfPost },
5361
{
5462
new: true,
5563
runValidators: true,

app/entities/post/write/BlogForm.tsx

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ const BlogForm = () => {
240240
};
241241

242242
return (
243-
<div className={'px-4'}>
243+
<div className={'px-2'}>
244244
<h1 className={'text-2xl text-center mb-4'}>
245245
{slug ? '수정' : '작성'}
246246
</h1>
@@ -294,7 +294,11 @@ const BlogForm = () => {
294294
<MDEditor
295295
value={formData.content}
296296
onChange={(value) => setFormData({ content: value })}
297-
extraCommands={[calloutCommand, commands.divider, ...commands.getExtraCommands()]}
297+
extraCommands={[
298+
calloutCommand,
299+
commands.divider,
300+
...commands.getExtraCommands(),
301+
]}
298302
height={500}
299303
minHeight={500}
300304
visibleDragbar={false}
@@ -304,8 +308,13 @@ const BlogForm = () => {
304308
'data-color-mode': theme,
305309
},
306310
components: {
307-
callout: ({ emoji, children }: { emoji?: string; children?: React.ReactNode }) =>
308-
<Callout emoji={emoji}>{children}</Callout>,
311+
callout: ({
312+
emoji,
313+
children,
314+
}: {
315+
emoji?: string;
316+
children?: React.ReactNode;
317+
}) => <Callout emoji={emoji}>{children}</Callout>,
309318
} as any,
310319
rehypeRewrite: (node, index?, parent?) => {
311320
asideToCallout(node);

app/hooks/post/usePost.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,10 @@ const usePost = (slug = '') => {
8080
try {
8181
const data = await getAllSeriesData();
8282
setSeriesList(data);
83-
setFormData((prev) => ({ ...prev, seriesId: data[0]._id }));
83+
// 편집 모드(slug 존재)에서는 getPostDetail이 seriesId를 설정하므로 덮어쓰지 않음
84+
if (!slug) {
85+
setFormData((prev) => ({ ...prev, seriesId: data[0]._id }));
86+
}
8487
setUIState((prev) => ({ ...prev, seriesLoading: false }));
8588
} catch (e) {
8689
console.error('시리즈 조회 중 오류 발생', e);

0 commit comments

Comments
 (0)