Skip to content

Commit 56f67c8

Browse files
committed
add cleartimout
1 parent 5a6a133 commit 56f67c8

File tree

3 files changed

+34
-9
lines changed

3 files changed

+34
-9
lines changed

src/components/write/PublishSeriesCreate.tsx

+21-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState, useEffect, FormEvent } from 'react';
1+
import React, { useState, useEffect, FormEvent, useRef } from 'react';
22
import styled, { css, keyframes } from 'styled-components';
33
import { themedPalette } from '../../lib/styles/themes';
44
import OutsideClickHandler from 'react-outside-click-handler';
@@ -110,8 +110,8 @@ const PublishSeriesCreate: React.FC<PublishSeriesCreateProps> = ({
110110
urlSlug: '',
111111
});
112112
const [editing, setEditing] = useState<boolean>(false);
113-
114113
const [defaultUrlSlug, setDefaultUrlSlug] = useState('');
114+
const hideTimeoutId = useRef<NodeJS.Timeout | null>(null);
115115

116116
useEffect(() => {
117117
let timeoutId: ReturnType<typeof setTimeout> | null = null;
@@ -137,15 +137,33 @@ const PublishSeriesCreate: React.FC<PublishSeriesCreateProps> = ({
137137
setEditing(true);
138138
}, [form.urlSlug]);
139139

140+
useEffect(() => {
141+
return () => {
142+
if (hideTimeoutId.current) {
143+
clearTimeout(hideTimeoutId.current);
144+
}
145+
};
146+
}, [hideTimeoutId]);
147+
140148
const onHide = () => {
141149
setDisappear(true);
142-
setTimeout(() => {
150+
const timeout = setTimeout(() => {
143151
setOpen(false);
144152
setDisappear(false);
145153
setShowOpenBlock(false);
146154
}, 125);
155+
const timeoutId = timeout;
156+
hideTimeoutId.current = timeoutId;
147157
};
148158

159+
useEffect(() => {
160+
return () => {
161+
if (hideTimeoutId.current) {
162+
clearTimeout(hideTimeoutId.current);
163+
}
164+
};
165+
}, []);
166+
149167
const submit = (e: FormEvent) => {
150168
e.preventDefault();
151169
if (form.name.trim() === '') {

src/containers/write/MarkdownEditorContainer.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ const MarkdownEditorContainer: React.FC<MarkdownEditorContainerProps> = () => {
180180
},
181181
});
182182

183-
if (!response || !response.data) return;
183+
if (!response.data?.writePost) return;
184184
const { id } = response.data.writePost;
185185
dispatch(setWritePostId(id));
186186
history.replace(`/write?id=${id}`);
@@ -277,7 +277,7 @@ const MarkdownEditorContainer: React.FC<MarkdownEditorContainerProps> = () => {
277277
},
278278
});
279279

280-
if (!response || !response.data) return;
280+
if (!response.data?.writePost) return;
281281
id = response.data.writePost.id;
282282
dispatch(setWritePostId(id));
283283
history.replace(`/write?id=${id}`);

src/containers/write/PublishActionButtonsContainer.tsx

+11-4
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,15 @@ const PublishActionButtonsContainer: React.FC<
100100
variables: variables,
101101
});
102102

103-
if (!response || !response.data) return;
103+
if (!response.data?.writePost) {
104+
toast.error('포스트 작성 실패');
105+
return;
106+
}
107+
104108
const { user, url_slug } = response.data.writePost;
105109
await client.resetStore();
106110
history.push(`/@${user.username}/${url_slug}`);
107111
} catch (error) {
108-
console.log('writePost error', error);
109112
toast.error('포스트 작성 실패');
110113
}
111114
};
@@ -119,12 +122,16 @@ const PublishActionButtonsContainer: React.FC<
119122
...variables,
120123
},
121124
});
122-
if (!response || !response.data) return;
125+
126+
if (!response.data?.editPost) {
127+
toast.error('포스트 수정 실패');
128+
return;
129+
}
130+
123131
const { user, url_slug } = response.data.editPost;
124132
await client.resetStore();
125133
history.push(`/@${user.username}/${url_slug}`);
126134
} catch (error) {
127-
console.log('editPost error', error);
128135
toast.error('포스트 수정 실패');
129136
}
130137
};

0 commit comments

Comments
 (0)