Skip to content

Commit 1f44063

Browse files
committed
Fixes velopert#9
1 parent 6e06298 commit 1f44063

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/containers/write/MarkdownEditorContainer.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import useSaveHotKey from './hooks/useSaveHotkey';
4040
import embedPlugin from '../../lib/remark/embedPlugin';
4141
import { Helmet } from 'react-helmet-async';
4242
import { toast } from 'react-toastify';
43+
import { usePrevious } from 'react-use';
4344

4445
export type MarkdownEditorContainerProps = {};
4546

@@ -122,6 +123,7 @@ const MarkdownEditorContainer: React.FC<MarkdownEditorContainerProps> = () => {
122123

123124
const [upload, file] = useUpload();
124125
const [s3Upload, image] = useS3Upload();
126+
const prevImage = usePrevious(image);
125127

126128
useEffect(() => {
127129
if (!file) return;
@@ -131,10 +133,10 @@ const MarkdownEditorContainer: React.FC<MarkdownEditorContainerProps> = () => {
131133
}, [file, s3Upload]);
132134

133135
useEffect(() => {
134-
if (!thumbnail && image) {
136+
if (image !== prevImage && !thumbnail && image) {
135137
actionCreators.setThumbnail(image);
136138
}
137-
}, [actionCreators, image, thumbnail]);
139+
}, [actionCreators, image, prevImage, thumbnail]);
138140

139141
const onDragDropUpload = useCallback(
140142
(file: File) => {
@@ -252,7 +254,7 @@ const MarkdownEditorContainer: React.FC<MarkdownEditorContainerProps> = () => {
252254
</Helmet>
253255
<MarkdownEditor
254256
onUpload={upload}
255-
lastUploadedImage={publish ? null : image}
257+
lastUploadedImage={image}
256258
initialBody={initialBody}
257259
title={title}
258260
markdown={markdown}

0 commit comments

Comments
 (0)