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

Commit 41d75bd

Browse files
authored
refactor(drinks): re-org layout, add some terms (#1197)
* refactor(drink): add some cool-data items * refactor(sponsor): re-org into layout * refactor(drink): move refresh callback to children
1 parent a02065a commit 41d75bd

File tree

12 files changed

+221
-75
lines changed

12 files changed

+221
-75
lines changed

src/containers/content/HaveADrinkContent/Body/Content.tsx

Lines changed: 0 additions & 53 deletions
This file was deleted.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { FC, memo } from 'react'
2+
3+
import Linker from '@/widgets/Linker'
4+
5+
import type { TDrinkItem } from '../../spec'
6+
import { refreshDrink } from '../../logic'
7+
8+
import { Wrapper, Image, Desc } from '../../styles/body/content/image_layout'
9+
10+
type TProps = {
11+
item: TDrinkItem
12+
}
13+
const ImageLayout: FC<TProps> = ({ item }) => {
14+
const { reference, images, imageSize, text } = item
15+
const imageSrc = images[0]
16+
17+
return (
18+
<Wrapper>
19+
<Image src={imageSrc} size={imageSize} onClick={() => refreshDrink()} />
20+
{reference && <Linker src={reference} hint="参考" top={8} />}
21+
<Desc onClick={() => refreshDrink()}>{text}</Desc>
22+
</Wrapper>
23+
)
24+
}
25+
26+
export default memo(ImageLayout)
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { FC, memo } from 'react'
2+
3+
import Linker from '@/widgets/Linker'
4+
5+
import type { TDrinkItem } from '../../spec'
6+
import { refreshDrink } from '../../logic'
7+
8+
import {
9+
Wrapper,
10+
Desc,
11+
NumWrapper,
12+
Num,
13+
Unit,
14+
} from '../../styles/body/content/number_layout'
15+
16+
type TProps = {
17+
item: TDrinkItem
18+
}
19+
const NumberLayout: FC<TProps> = ({ item }) => {
20+
const { num, unit, text, reference } = item
21+
22+
return (
23+
<Wrapper>
24+
<NumWrapper onClick={() => refreshDrink()}>
25+
<Num>{num}</Num>
26+
<Unit>{unit}</Unit>
27+
</NumWrapper>
28+
<Desc onClick={() => refreshDrink()}>{text}</Desc>
29+
{reference && <Linker src={reference} hint="参考" top={8} />}
30+
</Wrapper>
31+
)
32+
}
33+
34+
export default memo(NumberLayout)
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { FC, memo } from 'react'
2+
3+
import Linker from '@/widgets/Linker'
4+
5+
import type { TDrinkItem } from '../../spec'
6+
import { refreshDrink } from '../../logic'
7+
8+
import { Wrapper, Title, Desc } from '../../styles/body/content/title_layout'
9+
10+
type TProps = {
11+
item: TDrinkItem
12+
}
13+
const TitleLayout: FC<TProps> = ({ item }) => {
14+
const { title, text, reference } = item
15+
16+
return (
17+
<Wrapper>
18+
<Title onClick={() => refreshDrink()}>{title}</Title>
19+
<Desc onClick={() => refreshDrink()}>{text}</Desc>
20+
{reference && <Linker src={reference} hint="参考" top={8} />}
21+
</Wrapper>
22+
)
23+
}
24+
25+
export default memo(TitleLayout)
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { FC, memo } from 'react'
2+
3+
import Linker from '@/widgets/Linker'
4+
5+
import ImageLayout from './ImageLayout'
6+
import NumberLayout from './NumberLayout'
7+
import TitleLayout from './TitleLayout'
8+
9+
import type { TDrinkItem } from '../../spec'
10+
import { refreshDrink } from '../../logic'
11+
12+
import { Wrapper, TextWrapper } from '../../styles/body/content'
13+
14+
type TProps = {
15+
item: TDrinkItem
16+
}
17+
18+
const Content: FC<TProps> = ({ item }) => {
19+
const { title, num, images, text, reference } = item
20+
21+
if (num) {
22+
return <NumberLayout item={item} />
23+
}
24+
25+
if (images && images.length === 1) {
26+
return <ImageLayout item={item} />
27+
}
28+
29+
if (title) {
30+
return <TitleLayout item={item} />
31+
}
32+
33+
// default layout
34+
return (
35+
<Wrapper>
36+
<TextWrapper onClick={() => refreshDrink()}>{text}</TextWrapper>
37+
{reference && <Linker src={reference} hint="参考" top={8} />}
38+
</Wrapper>
39+
)
40+
}
41+
42+
export default memo(Content)

src/containers/content/HaveADrinkContent/Body/index.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*
55
*/
66

7-
import { FC, memo, useCallback } from 'react'
7+
import { FC, memo } from 'react'
88
import { AnimateOnChange } from 'react-animation'
99

1010
import { buildLog } from '@/utils/logger'
@@ -19,7 +19,6 @@ import Publish from './Publish'
1919
import Content from './Content'
2020

2121
import { Wrapper, SentenceWrapper, Sentence, Hint } from '../styles/body'
22-
import { refreshDrink } from '../logic'
2322

2423
/* eslint-disable-next-line */
2524
const log = buildLog('C:HaveADrinkContent')
@@ -74,7 +73,7 @@ const View: FC<TViewProps> = ({ view, category, drink, settingOptions }) => {
7473

7574
const Body = (props) => {
7675
return (
77-
<Wrapper onClick={() => refreshDrink()}>
76+
<Wrapper>
7877
<View {...props} />
7978
</Wrapper>
8079
)

src/containers/content/HaveADrinkContent/demo.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,31 @@ const demo = [
8585
upvoteAlias: '喜欢',
8686
entries: [
8787
{
88-
text: '抱歉,该条目下还没有内容,欢迎任何形式的参与',
88+
num: '755',
89+
unit: '万',
90+
reference:
91+
'https://octoverse.github.com/#lets-look-back-at-the-code-and-communities-built-on-git-hub-this-year',
92+
text: '根据 2021 Github Octoverse 公布的数据,全球共有 7300 万用户,其中中国开发者 755 万, 位居全球第二,仅次于美国的 1350 万。',
93+
},
94+
{
95+
num: '217',
96+
unit: '个',
97+
reference: 'https://github.com/e3b0c442/keywords',
98+
text: '据统计主流语言中关键字数目最多的是 Visual Basic,其包含 217 个语言关键字, 最少的是 Elixir, 数量为 15 个。',
99+
},
100+
{
101+
num: '3500',
102+
unit: '个',
103+
reference:
104+
'https://www.cnbc.com/2021/10/05/tesla-shares-higher-in-past-month-oppenheimer-charts-stock-moves.html?utm_term=Autofeed&utm_medium=Social&utm_content=Main&utm_source=Twitter#Echobox=1633454183',
105+
text: '据 CNBC 采访报道,每辆特斯拉有 3500 个或更多芯片,而传统引擎有 1000 个芯片。',
106+
},
107+
{
108+
num: '64.67',
109+
unit: '%',
110+
reference:
111+
'https://gs.statcounter.com/browser-market-share#monthly-202106-202106-bar',
112+
text: '截止 2021 年底,Google 的 Chrome 浏览器已占据超 6 成全球浏览器市场份额,苹果的 Safari(18.3%) 和 微软的 Edge(3.4%) 分列 2,3 位。',
89113
},
90114
],
91115
},

src/containers/content/HaveADrinkContent/spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ export type TDrinkItem = {
1515
reference?: string
1616
images?: string[]
1717
imageSize?: string
18+
num?: number
19+
unit?: string
1820
}
1921

2022
export type TDrinkCategory = {

src/containers/content/HaveADrinkContent/styles/body/content.ts renamed to src/containers/content/HaveADrinkContent/styles/body/content/image_layout.ts

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,6 @@ import Img from '@/Img'
55
import css from '@/utils/css'
66

77
export const Wrapper = styled.div`
8-
${css.flexColumn('align-both')};
9-
`
10-
export const Title = styled.div`
11-
margin-bottom: 25px;
12-
margin-top: -10px;
13-
font-weight: bold;
14-
`
15-
export const Desc = styled.div`
16-
font-size: 18px;
17-
opacity: 0.8;
18-
padding: 0 10%;
19-
margin-bottom: 10px;
20-
`
21-
22-
export const TextWrapper = styled.div``
23-
24-
export const ImageContentWrapper = styled(Wrapper)`
258
${css.flexColumn('align-both')}
269
margin-top: -30px;
2710
`
@@ -30,6 +13,6 @@ export const Image = styled(Img)<{ size: string }>`
3013
object-fit: cover;
3114
border-radius: 8px;
3215
`
33-
export const Text = styled.div`
16+
export const Desc = styled.div`
3417
margin-top: 25px;
3518
`
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import styled from 'styled-components'
2+
3+
// import { theme } from '@/utils/themes'
4+
import css from '@/utils/css'
5+
6+
export const Wrapper = styled.div`
7+
${css.flexColumn('align-both')};
8+
`
9+
10+
export const TextWrapper = styled.div``

0 commit comments

Comments
 (0)