Skip to content

Commit 51959a0

Browse files
committed
Fix thumbnail / short_description bug
1 parent ece6cb7 commit 51959a0

File tree

7 files changed

+28
-30
lines changed

7 files changed

+28
-30
lines changed

src/components/write/PublishPreview.tsx

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as React from 'react';
1+
import React, { useState, useEffect } from 'react';
22
import styled, { css } from 'styled-components';
33
import PublishSection from './PublishSection';
44
import palette from '../../lib/styles/palette';
@@ -179,7 +179,6 @@ const { useCallback } = React;
179179
export interface PublishPreviewProps {
180180
title: string;
181181
description: string;
182-
defaultDescription: string;
183182
thumbnail: string | null;
184183
onChangeDescription: (description: string) => void;
185184
onResetThumbnail: () => void;
@@ -190,12 +189,11 @@ const PublishPreview: React.FC<PublishPreviewProps> = ({
190189
title,
191190
thumbnail,
192191
description,
193-
defaultDescription,
194192
onChangeDescription,
195193
onUpload,
196194
onResetThumbnail,
197195
}) => {
198-
const descriptionToShow: string = description || defaultDescription;
196+
// const descriptionToShow: string = description || defaultDescription;
199197
const onChange = (e: React.ChangeEvent<HTMLTextAreaElement>) => {
200198
onChangeDescription(e.target.value);
201199
};
@@ -220,17 +218,12 @@ const PublishPreview: React.FC<PublishPreviewProps> = ({
220218
<h4>{title}</h4>
221219
<ShortDescriptionTextarea
222220
placeholder="당신의 포스트를 짧게 소개해보세요."
223-
value={descriptionToShow}
221+
value={description}
224222
onChange={onChange}
225223
onKeyDown={onKeyDown}
226224
/>
227-
<TextLimit
228-
limit={
229-
descriptionToShow !== defaultDescription &&
230-
descriptionToShow.length === 150
231-
}
232-
>
233-
{descriptionToShow.length}/150
225+
<TextLimit limit={description.length === 150}>
226+
{description.length}/150
234227
</TextLimit>
235228
</PostInfo>
236229
</PublishPreviewBlock>

src/components/write/__tests__/PublishPreview.test.tsx

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ describe('PublishPreview', () => {
77
const initialProps: PublishPreviewProps = {
88
title: '타이틀',
99
description: '',
10-
defaultDescription: '',
1110
onChangeDescription: () => {},
1211
onResetThumbnail: () => {},
1312
onUpload: () => {},
@@ -33,19 +32,7 @@ describe('PublishPreview', () => {
3332
const utils = setup({ title: '타이틀 입니다.' });
3433
utils.getByText('타이틀 입니다.');
3534
});
36-
it('shows default description', () => {
37-
const utils = setup({
38-
defaultDescription: 'default',
39-
});
40-
expect(utils.textarea.value).toBe('default');
41-
});
42-
it('shows description', () => {
43-
const utils = setup({
44-
description: 'hello',
45-
defaultDescription: 'default',
46-
});
47-
expect(utils.textarea.value).toBe('hello');
48-
});
35+
4936
it('calls onChangeDescription', () => {
5037
const onChangeDescription = jest.fn();
5138
const utils = setup({

src/containers/post/PostViewer.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ const PostViewer: React.FC<PostViewerProps> = ({
205205
tags: post.tags,
206206
title: post.title,
207207
urlSlug: post.url_slug,
208+
thumbnail: post.thumbnail,
208209
}),
209210
);
210211
history.push(`/write?id=${post.id}`);

src/containers/write/ActiveEditor.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ const ActiveEditor: React.FC<ActiveEditorProps> = () => {
8787
isPrivate: post.is_private,
8888
isMarkdown: post.is_markdown,
8989
isTemp: post.is_temp,
90+
thumbnail: post.thumbnail,
9091
}),
9192
);
9293
dispatch(setInitialBody(post.body));

src/containers/write/PublishActionButtonsContainer.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ const PublishActionButtonsContainer: React.FC<PublishActionButtonsContainerProps
6464
is_private: options.isPrivate,
6565
url_slug: options.urlSlug || escapeForUrl(options.title),
6666
thumbnail: options.thumbnail,
67-
meta: {},
67+
meta: {
68+
short_description: options.description,
69+
},
6870
series_id: safe(() => options.selectedSeries!.id),
6971
};
7072

src/containers/write/PublishPreviewContainer.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useEffect, useCallback } from 'react';
1+
import React, { useEffect, useCallback, useRef } from 'react';
22
import { connect } from 'react-redux';
33
import { RootState } from '../../modules';
44
import PublishPreview from '../../components/write/PublishPreview';
@@ -33,6 +33,7 @@ const PublishPreviewContainer: React.FC<PublishPreviewContainerProps> = ({
3333
thumbnail,
3434
setThumbnail,
3535
}) => {
36+
const mounted = useRef(false);
3637
const onChangeDescription = useCallback(
3738
(description: string) => changeDescription(description),
3839
[changeDescription],
@@ -41,6 +42,17 @@ const PublishPreviewContainer: React.FC<PublishPreviewContainerProps> = ({
4142
const [upload, file] = useUpload();
4243
const [s3Upload, image] = useS3Upload();
4344

45+
// fills description with defaultDescription when it is empty
46+
useEffect(() => {
47+
if (mounted.current) return;
48+
49+
if (!description) {
50+
changeDescription(defaultDescription);
51+
}
52+
53+
mounted.current = true;
54+
}, [changeDescription, defaultDescription, description]);
55+
4456
const onUpload = () => {
4557
upload();
4658
};
@@ -64,7 +76,6 @@ const PublishPreviewContainer: React.FC<PublishPreviewContainerProps> = ({
6476
return (
6577
<PublishPreview
6678
title={title}
67-
defaultDescription={defaultDescription}
6879
description={description}
6980
onChangeDescription={onChangeDescription}
7081
onUpload={onUpload}

src/modules/write.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ export type PrepareEditPayload = {
7171
isPrivate: boolean;
7272
isMarkdown: boolean;
7373
isTemp?: boolean;
74+
thumbnail: string | null;
7475
};
7576

7677
export const prepareEdit = createStandardAction(PREPARE_EDIT)<
@@ -199,13 +200,14 @@ const write = createReducer(
199200
id,
200201
isPrivate,
201202
isTemp,
203+
thumbnail,
202204
} = payload;
203205
const key = isMarkdown ? 'markdown' : 'html';
204206
return {
205207
...state,
206208
title,
207209
tags,
208-
description,
210+
description: description.slice(0, 150),
209211
urlSlug,
210212
isPrivate,
211213
isTemp: isTemp || false,
@@ -215,6 +217,7 @@ const write = createReducer(
215217
postId: id,
216218
initialBody: body,
217219
initialTitle: title,
220+
thumbnail,
218221
};
219222
},
220223
[SET_WRITE_POST_ID]: (state, action: SetWritePostId) => ({

0 commit comments

Comments
 (0)