Skip to content
This repository was archived by the owner on Nov 8, 2022. It is now read-only.

Commit 35eb989

Browse files
authored
refactor(comments): time divider , pin concept && re-org (#1058)
* style(comment-concepet): pin & time divider UI * refactor(comment-list): re-org codebase
1 parent 27b4bc7 commit 35eb989

File tree

11 files changed

+220
-126
lines changed

11 files changed

+220
-126
lines changed

src/containers/unit/Comments/Comment/DesktopView.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ import {
1717
CommentWrapper,
1818
CommentContent,
1919
CommentBodyInfo,
20+
PinState,
21+
PinIcon,
22+
PinText,
2023
} from '../styles/comment/desktop_view'
2124

2225
const getSelection = () => {
@@ -33,8 +36,16 @@ type TProps = {
3336
}
3437

3538
const Comment: React.FC<TProps> = ({ data, tobeDeleteId, accountInfo }) => {
39+
const pined = data.id === '360' || data.id === '377'
40+
3641
return (
37-
<Wrapper>
42+
<Wrapper pined={pined}>
43+
{pined && (
44+
<PinState>
45+
<PinIcon />
46+
<PinText>置顶评论</PinText>
47+
</PinState>
48+
)}
3849
<DeleteMask show={data.id === tobeDeleteId} />
3950
<CommentWrapper tobeDelete={data.id === tobeDeleteId}>
4051
<Upvote data={data} />
@@ -45,7 +56,6 @@ const Comment: React.FC<TProps> = ({ data, tobeDeleteId, accountInfo }) => {
4556
{data.replyTo && <ReplyBar data={data.replyTo} />}
4657
<MarkDownRender body={data.body} />
4758
</CommentContent>
48-
4959
<Footer data={data} accountInfo={accountInfo} />
5060
</CommentBodyInfo>
5161
</CommentWrapper>

src/containers/unit/Comments/CommentsList.tsx

Lines changed: 0 additions & 108 deletions
This file was deleted.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import React from 'react'
2+
3+
import { Wrapper, SlashSign, DateText } from '../styles/list/date_divider'
4+
5+
type TProps = {
6+
text: string
7+
}
8+
9+
const DateDivider: React.FC<TProps> = ({ text }) => (
10+
<Wrapper>
11+
<SlashSign>&#47;&#47;</SlashSign> <DateText>{text}</DateText>
12+
</Wrapper>
13+
)
14+
15+
export default React.memo(DateDivider)
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import React from 'react'
2+
3+
import Filter from '../CommentsFilter'
4+
5+
import {
6+
Wrapper,
7+
TotalTitle,
8+
TotalCountWrapper,
9+
TotalNum,
10+
} from '../styles/list/header'
11+
12+
type TProps = {
13+
totalCount: number
14+
filterType: string
15+
}
16+
17+
const Header: React.FC<TProps> = ({ totalCount, filterType }) => {
18+
return (
19+
<Wrapper>
20+
<TotalCountWrapper>
21+
{totalCount > 0 && (
22+
<TotalTitle id="lists-info">
23+
共收到 <TotalNum>{totalCount}</TotalNum> 条评论:
24+
</TotalTitle>
25+
)}
26+
</TotalCountWrapper>
27+
<Filter filterType={filterType} show={totalCount >= 2} />
28+
</Wrapper>
29+
)
30+
}
31+
32+
export default React.memo(Header)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import React from 'react'
2+
3+
import type { TAccount, TComment } from '@/spec'
4+
import Comment from '../Comment'
5+
6+
import DateDivider from './DateDivider'
7+
8+
type TProps = {
9+
entries: TComment[]
10+
tobeDeleteId: string
11+
accountInfo: TAccount
12+
}
13+
14+
const List: React.FC<TProps> = ({ entries, tobeDeleteId, accountInfo }) => (
15+
<React.Fragment>
16+
{entries.map((c, index) => (
17+
<React.Fragment key={c.id}>
18+
<Comment
19+
data={c}
20+
tobeDeleteId={tobeDeleteId}
21+
accountInfo={accountInfo}
22+
/>
23+
{(index === 1 || index === 3) && <DateDivider text="一个月后" />}
24+
</React.Fragment>
25+
))}
26+
</React.Fragment>
27+
)
28+
29+
export default React.memo(List)
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import React from 'react'
2+
3+
import type { TPagedComments, TUser } from '@/spec'
4+
import Pagi from '@/components/Pagi'
5+
import { CommentLoading } from '@/components/LoadingEffects'
6+
7+
import Header from './Header'
8+
import List from './List'
9+
10+
import { pageChange } from '../logic'
11+
12+
import { ListsWrapper, CommentBlock } from '../styles/list'
13+
14+
type TProps = {
15+
accountInfo: TUser
16+
pagedComments: TPagedComments
17+
restProps: {
18+
loading: boolean
19+
loadingFresh: boolean
20+
tobeDeleteId: string
21+
filterType: string
22+
}
23+
}
24+
25+
const CommentsList: React.FC<TProps> = ({
26+
accountInfo,
27+
pagedComments: { entries, totalCount, pageSize, pageNumber },
28+
restProps: { loading, loadingFresh, tobeDeleteId, filterType },
29+
}) => (
30+
<React.Fragment>
31+
<Header totalCount={totalCount} filterType={filterType} />
32+
{loadingFresh && (
33+
<CommentBlock>
34+
<CommentLoading />
35+
</CommentBlock>
36+
)}
37+
<ListsWrapper>
38+
{loading ? (
39+
<CommentBlock>
40+
<CommentLoading />
41+
</CommentBlock>
42+
) : (
43+
<List
44+
entries={entries}
45+
accountInfo={accountInfo}
46+
tobeDeleteId={tobeDeleteId}
47+
/>
48+
)}
49+
</ListsWrapper>
50+
<Pagi
51+
pageNumber={pageNumber}
52+
pageSize={pageSize}
53+
totalCount={totalCount}
54+
onChange={pageChange}
55+
showBottomMsg
56+
noMoreMsg="没有更多的评论了"
57+
emptyMsg="目前还没有评论"
58+
/>
59+
</React.Fragment>
60+
)
61+
62+
export default React.memo(CommentsList)

src/containers/unit/Comments/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { pluggedIn, buildLog } from '@/utils'
1010
import Modal from '@/components/Modal'
1111

1212
import CommentEditor from './CommentEditor'
13-
import CommentsList from './CommentsList'
13+
import List from './List'
1414
import CommentReplyEditor from './CommentReplyEditor'
1515
import LockedMessage from './LockedMessage'
1616

@@ -75,7 +75,7 @@ const CommentsContainer: React.FC<TProps> = ({
7575
/>
7676
)}
7777

78-
<CommentsList
78+
<List
7979
accountInfo={accountInfo}
8080
pagedComments={pagedCommentsData}
8181
restProps={{ ...store }}

src/containers/unit/Comments/styles/comment/desktop_view.ts

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,39 @@ import styled from 'styled-components'
33
import Img from '@/Img'
44
import { theme, css } from '@/utils'
55

6-
export const Wrapper = styled.div`
6+
import PinSVG from '@/SvgIcons/PinSVG'
7+
8+
export const Wrapper = styled.div<{ pined: boolean }>`
9+
position: relative;
710
${css.flex()};
8-
/* margin-bottom: 16px; */
911
margin-bottom: 14px;
1012
padding: 15px 5px;
11-
/* padding-left: 20px; */
13+
padding-top: ${({ pined }) => (pined ? '24px' : '15px')};
1214
position: relative;
13-
/* box-shadow: 0 1px 4px rgba(0, 0, 0, 0.04); */
14-
/* border-radius: 3px; */
15-
/* background: ${theme('comment.bg')}; */
1615
background: transparent;
1716
border-bottom: 1px solid;
1817
border-bottom-color: #0b4252;
1918
`
19+
export const PinState = styled.div`
20+
position: absolute;
21+
top: 0;
22+
left: 0;
23+
${css.flex('align-center')};
24+
margin-left: 5px;
25+
`
26+
export const PinIcon = styled(PinSVG)`
27+
fill: ${theme('thread.articleDigest')};
28+
${css.size(14)};
29+
opacity: 0.8;
30+
transform: rotate(-30deg);
31+
`
32+
export const PinText = styled.div`
33+
font-size: 12px;
34+
color: ${theme('thread.articleDigest')};
35+
margin-left: 12px;
36+
opacity: 0.8;
37+
`
38+
2039
// filter: blur(3px);
2140
export const CommentWrapper = styled.div<{ tobeDelete: boolean }>`
2241
${css.flexGrow()};
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import styled from 'styled-components'
2+
3+
import { theme, css } from '@/utils'
4+
5+
export const Wrapper = styled.div`
6+
${css.flex('align-center')};
7+
color: ${theme('thread.articleDigest')};
8+
padding-bottom: 10px;
9+
`
10+
export const SlashSign = styled.div`
11+
font-size: 10px;
12+
font-weight: bolder;
13+
font-family: cursive;
14+
margin-right: 10px;
15+
margin-left: 6px;
16+
opacity: 0.8;
17+
`
18+
export const DateText = styled.div`
19+
font-size: 12px;
20+
opacity: 0.8;
21+
`

src/containers/unit/Comments/styles/comments_list.ts renamed to src/containers/unit/Comments/styles/list/header.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,10 @@ import styled from 'styled-components'
22

33
import { theme, css } from '@/utils'
44

5-
// min-height: 300px;
6-
export const ListsContainer = styled.div`
7-
${css.flexColumn('')};
8-
border-radius: 4px;
9-
`
10-
export const TotalHeader = styled.div`
5+
export const Wrapper = styled.div`
116
${css.flex('align-center')};
127
margin-top: 25px;
13-
margin-bottom: 10px;
8+
margin-bottom: 20px;
149
1510
${css.media.mobile`
1611
border-bottom: 1px solid;
@@ -22,7 +17,7 @@ export const TotalHeader = styled.div`
2217
export const TotalCountWrapper = styled.div`
2318
flex-grow: 1;
2419
`
25-
export const ListTitle = styled.div`
20+
export const TotalTitle = styled.div`
2621
color: ${theme('comment.title')};
2722
font-size: 14px;
2823
margin-left: 2px;

0 commit comments

Comments
 (0)