Skip to content

Commit 5a6a133

Browse files
committed
fix: createPostHistory bug
1 parent 99775b8 commit 5a6a133

File tree

3 files changed

+37
-23
lines changed

3 files changed

+37
-23
lines changed

src/containers/write/MarkdownEditorContainer.tsx

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -179,12 +179,14 @@ const MarkdownEditorContainer: React.FC<MarkdownEditorContainerProps> = () => {
179179
token: null,
180180
},
181181
});
182+
182183
if (!response || !response.data) return;
183184
const { id } = response.data.writePost;
184185
dispatch(setWritePostId(id));
185186
history.replace(`/write?id=${id}`);
186187
notifySuccess();
187188
}
189+
188190
// tempsaving unreleased post:
189191
if (isTemp) {
190192
await editPost({
@@ -212,14 +214,16 @@ const MarkdownEditorContainer: React.FC<MarkdownEditorContainerProps> = () => {
212214
if (shallowEqual(lastSavedData, { title, body: markdown })) {
213215
return;
214216
}
215-
await createPostHistory({
216-
variables: {
217-
post_id: postId,
218-
title,
219-
body: markdown,
220-
is_markdown: true,
221-
},
222-
});
217+
if (postId) {
218+
await createPostHistory({
219+
variables: {
220+
post_id: postId,
221+
title,
222+
body: markdown,
223+
is_markdown: true,
224+
},
225+
});
226+
}
223227
setLastSavedData({
224228
title,
225229
body: markdown,
@@ -272,6 +276,7 @@ const MarkdownEditorContainer: React.FC<MarkdownEditorContainerProps> = () => {
272276
token: null,
273277
},
274278
});
279+
275280
if (!response || !response.data) return;
276281
id = response.data.writePost.id;
277282
dispatch(setWritePostId(id));

src/containers/write/PublishActionButtonsContainer.tsx

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ const PublishActionButtonsContainer: React.FC<
9090
};
9191

9292
const onPublish = async () => {
93-
if (writePostLoading || editPostLoading) return;
93+
if (writePostLoading) return;
9494
if (options.title.trim() === '') {
9595
toast.error('제목이 비어있습니다.');
9696
return;
@@ -99,27 +99,34 @@ const PublishActionButtonsContainer: React.FC<
9999
const response = await writePost({
100100
variables: variables,
101101
});
102+
102103
if (!response || !response.data) return;
103104
const { user, url_slug } = response.data.writePost;
104105
await client.resetStore();
105106
history.push(`/@${user.username}/${url_slug}`);
106-
} catch (e) {
107+
} catch (error) {
108+
console.log('writePost error', error);
107109
toast.error('포스트 작성 실패');
108110
}
109111
};
110112

111113
const onEdit = async () => {
112114
if (editPostLoading) return;
113-
const response = await editPost({
114-
variables: {
115-
id: options.postId,
116-
...variables,
117-
},
118-
});
119-
if (!response || !response.data) return;
120-
const { user, url_slug } = response.data.editPost;
121-
await client.resetStore();
122-
history.push(`/@${user.username}/${url_slug}`);
115+
try {
116+
const response = await editPost({
117+
variables: {
118+
id: options.postId,
119+
...variables,
120+
},
121+
});
122+
if (!response || !response.data) return;
123+
const { user, url_slug } = response.data.editPost;
124+
await client.resetStore();
125+
history.push(`/@${user.username}/${url_slug}`);
126+
} catch (error) {
127+
console.log('editPost error', error);
128+
toast.error('포스트 수정 실패');
129+
}
123130
};
124131

125132
return (

src/index.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@ import darkMode from './modules/darkMode';
1919
import { UncachedApolloProvider } from './lib/graphql/UncachedApolloContext';
2020
import { ssrEnabled } from './lib/utils';
2121

22-
Sentry.init({
23-
dsn: 'https://[email protected]/1886813',
24-
});
22+
if (process.env.NODE_ENV === 'production') {
23+
Sentry.init({
24+
dsn: 'https://[email protected]/1886813',
25+
});
26+
}
2527

2628
const store = createStore(
2729
rootReducer,

0 commit comments

Comments
 (0)