From 79aa8a6539111e0f49e862481019c4c9e325c81e Mon Sep 17 00:00:00 2001 From: mydearxym Date: Tue, 10 May 2022 18:26:59 +0800 Subject: [PATCH 1/7] refactor(comments): re-org file structure --- .../unit/Comments/HeadBar/Actions.tsx | 83 ++++++++++++ .../unit/Comments/HeadBar/index.tsx | 63 +++++++++ src/containers/unit/Comments/List/Header.tsx | 126 ------------------ src/containers/unit/Comments/List/index.tsx | 15 +-- src/containers/unit/Comments/index.tsx | 16 ++- .../{list/header.ts => head_bar/index.ts} | 8 +- src/widgets/AnimatedCount/styles/metric.ts | 2 +- src/widgets/Common/index.ts | 2 +- 8 files changed, 169 insertions(+), 146 deletions(-) create mode 100644 src/containers/unit/Comments/HeadBar/Actions.tsx create mode 100644 src/containers/unit/Comments/HeadBar/index.tsx delete mode 100644 src/containers/unit/Comments/List/Header.tsx rename src/containers/unit/Comments/styles/{list/header.ts => head_bar/index.ts} (94%) diff --git a/src/containers/unit/Comments/HeadBar/Actions.tsx b/src/containers/unit/Comments/HeadBar/Actions.tsx new file mode 100644 index 000000000..5de68d558 --- /dev/null +++ b/src/containers/unit/Comments/HeadBar/Actions.tsx @@ -0,0 +1,83 @@ +import { FC, memo, Fragment } from 'react' + +import { ICON } from '@/config' +import { SVG } from '@/constant' + +import IconButton from '@/widgets/Buttons/IconButton' +import { IconSwitcher } from '@/widgets/Switcher' + +import { MODE, API_MODE } from '../constant' +import type { TMode } from '../spec' +import type { TProps as TBase } from './index' +import { foldAllComments, expandAllComments, onModeChange } from '../logic' + +type TProps = Pick + +const actionIconConfig = { + right: 11, + hintDelay: 200, +} + +const switchItems = [ + { + key: MODE.REPLIES, + iconSrc: `${ICON}/article/comment-reply-mode.svg`, + desc: '回复模式', + }, + { + key: MODE.TIMELINE, + iconSrc: `${ICON}/article/comment-timeline-mode.svg`, + desc: '时间线模式', + }, +] + +const Actions: FC = ({ mode, isAllFolded, apiMode }) => { + return ( + + {/* {apiMode === API_MODE.ARTICLE && ( + + )} */} + + {/* {apiMode === API_MODE.ARTICLE && ( + + )} */} + + {isAllFolded ? ( + + ) : ( + + )} + {apiMode === API_MODE.ARTICLE && ( + onModeChange(key as TMode)} + /> + )} + + ) +} + +export default memo(Actions) diff --git a/src/containers/unit/Comments/HeadBar/index.tsx b/src/containers/unit/Comments/HeadBar/index.tsx new file mode 100644 index 000000000..a1ce145a4 --- /dev/null +++ b/src/containers/unit/Comments/HeadBar/index.tsx @@ -0,0 +1,63 @@ +import { FC, memo } from 'react' + +import type { TCommentsState } from '@/spec' + +import { LineDivider } from '@/widgets/Common' +import Button from '@/widgets/Buttons/Button' +import { LavaLampLoading } from '@/widgets/Loading' + +import Actions from './Actions' + +import { + Wrapper, + TotalTitle, + TotalCountWrapper, + TotalNum, + ActionsWrapper, + EditIcon, +} from '../styles/head_bar' + +import type { TMode, TAPIMode } from '../spec' + +export type TProps = { + mode: TMode + apiMode: TAPIMode + isAllFolded: boolean + loading: boolean + basicState: TCommentsState +} + +const Header: FC = ({ + basicState, + mode, + isAllFolded, + loading, + apiMode, +}) => { + return ( + + + + 共 + + {basicState.totalCount} + + 条讨论 + + + + {loading && } + + + + + + + + ) +} + +export default memo(Header) diff --git a/src/containers/unit/Comments/List/Header.tsx b/src/containers/unit/Comments/List/Header.tsx deleted file mode 100644 index f23151dc1..000000000 --- a/src/containers/unit/Comments/List/Header.tsx +++ /dev/null @@ -1,126 +0,0 @@ -import { FC, memo } from 'react' - -import type { TCommentsState } from '@/spec' -import { ICON } from '@/config' -import { SVG } from '@/constant' - -import { LineDivider } from '@/widgets/Common' -import Button from '@/widgets/Buttons/Button' -import IconButton from '@/widgets/Buttons/IconButton' -import { IconSwitcher } from '@/widgets/Switcher' -import { LavaLampLoading } from '@/widgets/Loading' - -import { - Wrapper, - TotalTitle, - TotalCountWrapper, - TotalNum, - ActionsWrapper, - EditIcon, -} from '../styles/list/header' - -import { MODE, API_MODE } from '../constant' -import type { TMode, TAPIMode } from '../spec' -import { foldAllComments, expandAllComments, onModeChange } from '../logic' - -type TProps = { - mode: TMode - apiMode: TAPIMode - isAllFolded: boolean - loading: boolean - basicState: TCommentsState -} - -const actionIconConfig = { - right: 11, - hintDelay: 200, -} - -const switchItems = [ - { - key: MODE.REPLIES, - iconSrc: `${ICON}/article/comment-reply-mode.svg`, - desc: '回复模式', - }, - { - key: MODE.TIMELINE, - iconSrc: `${ICON}/article/comment-timeline-mode.svg`, - desc: '时间线模式', - }, -] - -const Header: FC = ({ - basicState, - mode, - isAllFolded, - loading, - apiMode, -}) => { - return ( - - - - 共 - - {basicState.totalCount} - - 条讨论 - - - - {loading && } - - - - - {/* {apiMode === API_MODE.ARTICLE && ( - - )} */} - - {/* {apiMode === API_MODE.ARTICLE && ( - - )} */} - - {isAllFolded ? ( - - ) : ( - - )} - {apiMode === API_MODE.ARTICLE && ( - onModeChange(key as TMode)} - /> - )} - - - ) -} - -export default memo(Header) diff --git a/src/containers/unit/Comments/List/index.tsx b/src/containers/unit/Comments/List/index.tsx index e74ff61ce..1146949ea 100644 --- a/src/containers/unit/Comments/List/index.tsx +++ b/src/containers/unit/Comments/List/index.tsx @@ -4,7 +4,6 @@ import type { TPagedComments, TCommentsState } from '@/spec' import Pagi from '@/widgets/Pagi' import { Br } from '@/widgets/Common' -import Header from './Header' import List from './List' import type { TMode, TFoldState, TRepliesState, TAPIMode } from '../spec' @@ -18,7 +17,7 @@ type TProps = { mode: TMode apiMode: TAPIMode repliesState: TRepliesState - basicState: TCommentsState + // basicState: TCommentsState loading: boolean } @@ -28,23 +27,13 @@ const CommentsList: FC = ({ mode, apiMode, repliesState, - basicState, loading, }) => { const { entries, totalCount, pageSize, pageNumber } = pagedComments - const { foldedIds, isAllFolded } = foldState + const { foldedIds } = foldState return ( - {totalCount > 0 && ( -
- )} = ({ basicState, } = store + const { isAllFolded } = foldState + const { totalCount } = pagedCommentsData + return ( {apiMode === API_MODE.ARTICLE && } @@ -61,8 +66,17 @@ const CommentsContainer: FC = ({ isArticleAuthor={false} /> */} + {totalCount > 0 && ( + + )} + ` color: ${({ highlight }) => highlight ? theme('comment.number') : theme('thread.articleTitle')}; font-weight: bold; - font-size: 17px; - margin-left: 6px; - margin-right: 6px; + font-size: 15px; + margin-left: 5px; + margin-right: 5px; ` export const CommentBlock = styled.div` ${css.flex()}; diff --git a/src/widgets/AnimatedCount/styles/metric.ts b/src/widgets/AnimatedCount/styles/metric.ts index d4a8f695e..dac4f9402 100644 --- a/src/widgets/AnimatedCount/styles/metric.ts +++ b/src/widgets/AnimatedCount/styles/metric.ts @@ -6,7 +6,7 @@ import { theme } from '@/utils/css' export const getFontSize = (size: TSIZE): string => { switch (size) { case SIZE.TINY: { - return '13px' + return '14px' } case SIZE.MEDIUM: { return '18px' diff --git a/src/widgets/Common/index.ts b/src/widgets/Common/index.ts index bc2c90514..9d78eba91 100755 --- a/src/widgets/Common/index.ts +++ b/src/widgets/Common/index.ts @@ -25,7 +25,7 @@ export const Divider = styled.div` type TLineDivider = TSpace & { height?: number } export const LineDivider = styled.div` background: ${theme('thread.articleDigest')}; - opacity: 0.85; + opacity: 0.7; width: 1px; height: ${({ height }) => `${height || 12}px`}; From fa0207cc27659e05f38a3e6e166968983356f08c Mon Sep 17 00:00:00 2001 From: mydearxym Date: Tue, 10 May 2022 21:41:00 +0800 Subject: [PATCH 2/7] refactor(comments): switch bar mode ux --- .../editor/RichEditor/styles/index.ts | 4 +- .../editor/RichEditor/styles/metric.ts | 2 +- .../editor/RichEditor/styles/overwrite.ts | 2 +- .../unit/Comments/Editor/PublishEditor.tsx | 32 ++++------ src/containers/unit/Comments/Editor/index.tsx | 12 ---- .../unit/Comments/HeadBar/PublishBar.tsx | 46 ++++++++++++++ .../HeadBar/{ => StateBar}/Actions.tsx | 18 +++--- .../unit/Comments/HeadBar/StateBar/index.tsx | 60 ++++++++++++++++++ .../unit/Comments/HeadBar/index.tsx | 63 +++++++++---------- src/containers/unit/Comments/index.tsx | 1 + .../Comments/styles/editor/publish_editor.ts | 28 ++------- .../unit/Comments/styles/head_bar/index.ts | 45 +------------ .../Comments/styles/head_bar/publish_bar.ts | 29 +++++++++ .../styles/head_bar/state_bar/actions.ts | 8 +++ .../styles/head_bar/state_bar/index.ts | 49 +++++++++++++++ src/widgets/Switcher/styles/icon_selector.ts | 12 ++-- 16 files changed, 258 insertions(+), 153 deletions(-) create mode 100644 src/containers/unit/Comments/HeadBar/PublishBar.tsx rename src/containers/unit/Comments/HeadBar/{ => StateBar}/Actions.tsx (86%) create mode 100644 src/containers/unit/Comments/HeadBar/StateBar/index.tsx create mode 100644 src/containers/unit/Comments/styles/head_bar/publish_bar.ts create mode 100644 src/containers/unit/Comments/styles/head_bar/state_bar/actions.ts create mode 100644 src/containers/unit/Comments/styles/head_bar/state_bar/index.ts diff --git a/src/containers/editor/RichEditor/styles/index.ts b/src/containers/editor/RichEditor/styles/index.ts index dbfbd9c80..c1100d488 100755 --- a/src/containers/editor/RichEditor/styles/index.ts +++ b/src/containers/editor/RichEditor/styles/index.ts @@ -19,8 +19,8 @@ export const EditorWrapper = styled(EditWrapperBase).attrs(() => ({ }))` color: ${theme('thread.articleTitle')}; min-height: ${({ type }) => getMinHeight(type)}; - border-top: 1px solid; - border-top-color: #1a3a40; + border-bottom: 3px solid; + border-bottom-color: ${theme('border')}; // media therdhold is 651 width: 100%; padding-top: 10px; diff --git a/src/containers/editor/RichEditor/styles/metric.ts b/src/containers/editor/RichEditor/styles/metric.ts index 066275a63..1ebb8424a 100644 --- a/src/containers/editor/RichEditor/styles/metric.ts +++ b/src/containers/editor/RichEditor/styles/metric.ts @@ -1,7 +1,7 @@ export const getWidth = (type) => { switch (type) { case 'comment': { - return '600px' + return '620px' } default: { return '680px' diff --git a/src/containers/editor/RichEditor/styles/overwrite.ts b/src/containers/editor/RichEditor/styles/overwrite.ts index 03727dc36..ac93f65ec 100644 --- a/src/containers/editor/RichEditor/styles/overwrite.ts +++ b/src/containers/editor/RichEditor/styles/overwrite.ts @@ -16,7 +16,7 @@ const RichEditorStyle = createGlobalStyle` } .ce-paragraph[data-placeholder]:empty::before { - color: #4d666c !important; + color: #a2a2a2 !important; } .codex-editor svg { diff --git a/src/containers/unit/Comments/Editor/PublishEditor.tsx b/src/containers/unit/Comments/Editor/PublishEditor.tsx index 387f4b5fc..c33d495bc 100644 --- a/src/containers/unit/Comments/Editor/PublishEditor.tsx +++ b/src/containers/unit/Comments/Editor/PublishEditor.tsx @@ -1,45 +1,35 @@ import { FC, memo } from 'react' -import type { TAccount, TSubmitState } from '@/spec' +import type { TSubmitState } from '@/spec' -import Header from './Header' +// import Header from './Header' import BodyEditor from './BodyEditor' -import Footer from './Footer' -import { Wrapper, ExpandWrapper } from '../styles/editor/publish_editor' -import { commentOnChange, createComment, closeEditor } from '../logic' +import { Wrapper } from '../styles/editor/publish_editor' +// import { commentOnChange, createComment, closeEditor } from '../logic' +import { commentOnChange } from '../logic' type TProps = { - accountInfo: TAccount body: string submitState: TSubmitState - showEditor: boolean } -const PublishEditor: FC = ({ - accountInfo, - submitState, - showEditor, - body, -}) => { - if (!showEditor) { - return - } +const PublishEditor: FC = ({ submitState, body }) => { return ( - -
+ + {/*
*/} commentOnChange(v, 'commentBody')} /> -