Skip to content

Commit 4d5e874

Browse files
authored
Merge pull request velopert#10 from velopert/fix/editor-post-thumbnail
Fix/editor post thumbnail
2 parents b840aeb + 1f44063 commit 4d5e874

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

src/containers/post/PostViewer.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,12 @@ const PostViewer: React.FC<PostViewerProps> = ({
321321
tags={post.tags}
322322
username={username}
323323
date={post.released_at}
324-
thumbnail={post.thumbnail}
324+
thumbnail={
325+
post.thumbnail &&
326+
(post.body.includes(encodeURI(post.thumbnail))
327+
? null
328+
: post.thumbnail)
329+
}
325330
series={post.series}
326331
hideThumbnail={!!post.thumbnail && post.body.includes(post.thumbnail)}
327332
postId={post.id}

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)