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

Commit 3735094

Browse files
authored
feat(upvote-button): fancy, animated upvote component (#1110)
* refactor(Upvote): make it awesome * refactor(Upvote): re-org codebase & naming * refactor(Upvote): rm warning
1 parent ac85cf8 commit 3735094

File tree

20 files changed

+586
-30
lines changed

20 files changed

+586
-30
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
*
3+
* ArticleImgWindow
4+
*
5+
*/
6+
7+
import { FC, memo } from 'react'
8+
9+
import { buildLog } from '@/utils'
10+
11+
import { Wrapper, Block } from './styles'
12+
13+
/* eslint-disable-next-line */
14+
const log = buildLog('c:ArticleImgWindow:index')
15+
16+
type TProps = {
17+
testid?: string
18+
}
19+
20+
const ArticleImgWindow: FC<TProps> = ({ testid = 'article-img-window' }) => {
21+
return (
22+
<Wrapper testid={testid}>
23+
<Block />
24+
<Block />
25+
</Wrapper>
26+
)
27+
}
28+
29+
export default memo(ArticleImgWindow)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import styled from 'styled-components'
2+
3+
import type { TTestable } from '@/spec'
4+
5+
// import Img from '@/Img'
6+
import { css } from '@/utils'
7+
8+
export const Wrapper = styled.div.attrs(({ testid }: TTestable) => ({
9+
'data-test-id': testid,
10+
}))<TTestable>`
11+
${css.flex('align-center')};
12+
`
13+
export const Block = styled.div`
14+
width: 30%;
15+
height: 60px;
16+
background: #06303b;
17+
margin-right: 10px;
18+
border-radius: 5px;
19+
`
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// import React from 'react'
2+
// import { shallow } from 'enzyme'
3+
4+
// import ArticleImgWindow from '../index'
5+
6+
describe('TODO <ArticleImgWindow />', () => {
7+
it('Expect to have unit tests specified', () => {
8+
expect(true).toEqual(true)
9+
})
10+
})

src/components/AvatarsRow/index.tsx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,9 @@ const getUniqueArray = (arr, comp) => {
4242
export type TProps = {
4343
users?: TUser[]
4444
size?: TAvatarSize
45-
total: number
45+
total?: number | null
4646
limit: number
47+
showMore?: boolean
4748
showTotalNumber?: boolean
4849
reverse?: boolean
4950
scrollPosition?: any
@@ -54,11 +55,12 @@ export type TProps = {
5455

5556
const AvatarsRow: FC<TProps> = ({
5657
size = SIZE.SMALL,
57-
total,
58+
total = null,
5859
users = [],
5960
limit = AVATARS_LIST_LENGTH.POSTS,
6061
onUserSelect = log,
6162
onTotalSelect = log,
63+
showMore = true,
6264
showTotalNumber = false,
6365
reverse = true,
6466
// see https://github.com/Aljullu/react-lazy-load-image-component/issues/42
@@ -68,23 +70,25 @@ const AvatarsRow: FC<TProps> = ({
6870
return <span />
6971
}
7072

73+
const totalCount = total || users.length
74+
7175
users = filter(validUser, getUniqueArray(users, 'id'))
7276
const sortedUsers = reverse ? users : reverseFn(users)
7377

7478
return (
75-
<Wrapper total={total}>
76-
{total <= 1 ? (
79+
<Wrapper total={totalCount}>
80+
{totalCount <= 1 || !showMore ? (
7781
<TotalOneOffset />
7882
) : (
7983
<MoreItem
8084
size={size}
81-
total={total}
85+
total={totalCount}
8286
showTotalNumber={showTotalNumber}
8387
onTotalSelect={onTotalSelect}
8488
/>
8589
)}
8690

87-
{total === 1 ? (
91+
{totalCount === 1 ? (
8892
<RealAvatar
8993
user={sortedUsers[0]}
9094
size={size}

src/components/IconText/styles/metric.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import { SIZE } from '@/constant'
44
export const getIconSize = (size: TSIZE): string => {
55
switch (size) {
66
case SIZE.LARGE: {
7-
return '14px'
7+
return '16px'
88
}
99
case SIZE.MEDIUM: {
10-
return '13px'
10+
return '15px'
1111
}
1212
case SIZE.TINY: {
1313
return '11px'
@@ -26,6 +26,9 @@ export const getTextSize = (size: TSIZE): string => {
2626
case SIZE.LARGE: {
2727
return '15px'
2828
}
29+
case SIZE.MEDIUM: {
30+
return '14px'
31+
}
2932
case SIZE.TINY: {
3033
return '11px'
3134
}

src/components/JobItem/DesktopView/Footer.tsx

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,26 @@
11
import { FC, memo } from 'react'
22

3+
import { ICON } from '@/config'
4+
import Upvote from '@/components/Upvote'
5+
import DotDivider from '@/components/DotDivider'
6+
import IconText from '@/components/IconText'
7+
8+
import { Wrapper, PublishWrapper, Bottom } from '../styles/desktop_view/footer'
9+
310
const Footer: FC = () => {
411
return (
5-
<div>
6-
<div>mydearxym 发布于: 3 天前</div>
7-
<div>
8-
你和 头像 Raw 等 24 人觉得不错 -- 评论 35,收藏, 分享, 举报(more 里面)
9-
</div>
10-
</div>
12+
<Wrapper>
13+
<PublishWrapper>
14+
mydearxym <DotDivider space={6} /> 3 天前
15+
</PublishWrapper>
16+
<Bottom>
17+
{/* 你和 头像 Raw 等 24 人觉得很赞 -- 评论 35,收藏, 分享, 举报(more 里面) */}
18+
<Upvote />
19+
<IconText iconSrc={`${ICON}/article/comment.svg`} size="medium">
20+
9
21+
</IconText>
22+
</Bottom>
23+
</Wrapper>
1124
)
1225
}
1326

src/components/JobItem/DesktopView/index.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import type { TJob } from '@/spec'
44

55
import { cutRest } from '@/utils'
66
import DigestSentence from '@/components/DigestSentence'
7-
import { Br } from '@/components/Common'
7+
import { Br, SpaceGrow } from '@/components/Common'
8+
import ArticleImgWindow from '@/components/ArticleImgWindow'
89

910
import Header from './Header'
1011
import Footer from './Footer'
@@ -28,9 +29,10 @@ const DesktopView: FC<TProps> = ({ entry }) => {
2829
100,
2930
)}
3031
</DigestSentence>
31-
<Br top={10} />
32-
<div>图片列表,可预览</div>
33-
<Br top={20} />
32+
<Br top={4} />
33+
<ArticleImgWindow />
34+
<Br top={16} />
35+
<SpaceGrow />
3436
<Footer />
3537
</Wrapper>
3638
)

src/components/JobItem/index.tsx

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import { FC, memo } from 'react'
88

99
import type { TJob, TID } from '@/spec'
10-
import { buildLog, getRandomInt } from '@/utils'
10+
import { buildLog } from '@/utils'
1111
import { useAccount } from '@/hooks'
1212

1313
import ArticleItemPrefixLabel from '@/components/ArticleItemPrefixLabel'
@@ -18,21 +18,16 @@ import { Wrapper } from './styles'
1818
/* eslint-disable-next-line */
1919
const log = buildLog('c:JobItem:index')
2020

21-
const randomHeight = () => {
22-
return `${getRandomInt(200, 420)}px`
23-
}
24-
2521
type TProps = {
2622
entry: TJob
2723
activeId: TID | null
2824
}
2925

3026
const JobItem: FC<TProps> = ({ entry, activeId }) => {
31-
const height = randomHeight()
3227
const { c11n } = useAccount()
3328

3429
return (
35-
<Wrapper entry={entry} activeId={activeId} c11n={c11n} height={height}>
30+
<Wrapper entry={entry} activeId={activeId} c11n={c11n}>
3631
<ArticleItemPrefixLabel entry={entry} topOffset="9px" />
3732
<DesktopView entry={entry} />
3833
</Wrapper>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import styled from 'styled-components'
2+
3+
import { theme, css } from '@/utils'
4+
5+
export const Wrapper = styled.div`
6+
color: ${theme('thread.articleDigest')};
7+
`
8+
export const PublishWrapper = styled.div`
9+
${css.flex('align-center')};
10+
margin-left: 3px;
11+
font-size: 13px;
12+
`
13+
export const Bottom = styled.div`
14+
${css.flex('justify-between', 'align-center')};
15+
`
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import styled from 'styled-components'
22

3-
// import { theme, css } from '@/utils'
3+
import { css } from '@/utils'
44

5-
export const Wrapper = styled.div``
5+
export const Wrapper = styled.div`
6+
${css.flexColumn()};
7+
height: 100%;
8+
`
69

710
export const Holder = styled.div``

0 commit comments

Comments
 (0)