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

Commit df068c9

Browse files
authored
refactor(thread): common articles card comp (#1111)
* refactor(thread): extract article card comp * refactor(ThreadCard): adjust styles * refactor(ThreadCard): fix
1 parent 3735094 commit df068c9

File tree

12 files changed

+89
-50
lines changed

12 files changed

+89
-50
lines changed

src/components/JobItem/DesktopView/Footer.tsx renamed to src/components/ArticleCard/Footer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import Upvote from '@/components/Upvote'
55
import DotDivider from '@/components/DotDivider'
66
import IconText from '@/components/IconText'
77

8-
import { Wrapper, PublishWrapper, Bottom } from '../styles/desktop_view/footer'
8+
import { Wrapper, PublishWrapper, Bottom } from './styles/footer'
99

1010
const Footer: FC = () => {
1111
return (

src/components/JobItem/DesktopView/Header.tsx renamed to src/components/ArticleCard/Header.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type { TTag } from '@/spec'
44
import { cutRest } from '@/utils'
55
import InlineTags from '@/components/InlineTags'
66

7-
import { Wrapper, Title } from '../styles/desktop_view/header'
7+
import { Wrapper, Title } from './styles/header'
88

99
type TProps = {
1010
title: string
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { FC, memo } from 'react'
2+
3+
import type { TJob } from '@/spec'
4+
// import { THREAD } from '@/constant'
5+
6+
import { cutRest } from '@/utils'
7+
import DigestSentence from '@/components/DigestSentence'
8+
import { Br, SpaceGrow } from '@/components/Common'
9+
import ArticleImgWindow from '@/components/ArticleImgWindow'
10+
11+
import Header from './Header'
12+
import Footer from './Footer'
13+
14+
import { Wrapper } from './styles'
15+
import { SIZE } from '@/constant'
16+
17+
type TProps = {
18+
data: TJob
19+
// thread?: TThread
20+
}
21+
const fakeDigest =
22+
'网络监测数据显示,从 7 月 12 日开始古巴限制了社交媒体和消息应用,此举被认为旨在限制信息流动。古巴上周末爆发了罕见的大规模反政府抗议。受到干扰的通讯平台包括了 WhatsApp、Facebook、Instagram 和部分 Telegram 服务。VPN 服务可以绕过这一干扰。古巴的反政府抗议与经济困难,疫苗短缺等问题有关。'
23+
24+
const ArticleCard: FC<TProps> = ({ data }) => {
25+
const { title, tags } = data
26+
27+
return (
28+
<Wrapper>
29+
<Header title={title} tags={tags} />
30+
<Br top={15} />
31+
<DigestSentence
32+
top={5}
33+
bottom={15}
34+
size={SIZE.MEDIUM}
35+
onPreview={() => console.log('send preview')}
36+
>
37+
{cutRest(fakeDigest, 150)}
38+
</DigestSentence>
39+
<Br top={4} />
40+
<ArticleImgWindow />
41+
<Br top={16} />
42+
<SpaceGrow />
43+
<Footer />
44+
</Wrapper>
45+
)
46+
}
47+
48+
export default memo(ArticleCard)

src/components/JobItem/styles/desktop_view/footer.ts renamed to src/components/ArticleCard/styles/footer.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export const Wrapper = styled.div`
88
export const PublishWrapper = styled.div`
99
${css.flex('align-center')};
1010
margin-left: 3px;
11+
margin-bottom: 3px;
1112
font-size: 13px;
1213
`
1314
export const Bottom = styled.div`
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 ArticleCard from '../index'
5+
6+
describe('TODO <ArticleCard />', () => {
7+
it('Expect to have unit tests specified', () => {
8+
expect(true).toEqual(true)
9+
})
10+
})

src/components/DigestSentence/index.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
import { FC, ReactNode, memo } from 'react'
88

9+
import type { TSIZE_SM } from '@/spec'
10+
import { SIZE } from '@/constant'
911
import { ICON } from '@/config'
1012
import { buildLog } from '@/utils'
1113

@@ -31,6 +33,7 @@ type TProps = {
3133
bottom?: number
3234
left?: number
3335
right?: number
36+
size?: TSIZE_SM
3437
onPreview: () => void
3538
}
3639

@@ -42,6 +45,7 @@ const DigestSentence: FC<TProps> = ({
4245
bottom = 0,
4346
left = 0,
4447
right = 0,
48+
size = SIZE.SMALL,
4549
}) => {
4650
return (
4751
<Wrapper
@@ -51,6 +55,7 @@ const DigestSentence: FC<TProps> = ({
5155
bottom={bottom}
5256
left={left}
5357
right={right}
58+
size={size}
5459
>
5560
{children}
5661
<Space left={8} />

src/components/DigestSentence/styles/index.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
import styled from 'styled-components'
22

3-
import type { TTestable, TSpace } from '@/spec'
3+
import type { TTestable, TSpace, TSIZE_SM } from '@/spec'
44
import Img from '@/Img'
55
import { css, theme } from '@/utils'
66

7+
import { getFontSize } from './metric'
8+
9+
type TWrapper = TTestable & TSpace & { size: TSIZE_SM }
710
export const Wrapper = styled.div.attrs(({ testid }: TTestable) => ({
811
'data-test-id': testid,
9-
}))<TTestable & TSpace>`
12+
}))<TWrapper>`
1013
color: ${theme('thread.articleDigest')};
11-
font-size: 13px;
14+
font-size: ${({ size }) => getFontSize(size)};
1215
1316
padding-top: ${({ top }) => `${top}px`};
1417
padding-bottom: ${({ bottom }) => `${bottom}px`};
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import type { TSIZE_SM } from '@/spec'
2+
import { SIZE } from '@/constant'
3+
4+
export const getFontSize = (size: TSIZE_SM): string => {
5+
switch (size) {
6+
case SIZE.MEDIUM: {
7+
return '14px'
8+
}
9+
10+
default:
11+
return '13px'
12+
}
13+
}
14+
15+
export const holder = 1

0 commit comments

Comments
 (0)