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

Commit d7b4d1e

Browse files
authored
refactor(home): promotion redesign (#1047)
* refactor(PromotionList): UI redesign * refactor(PromotionList): UX redesign
1 parent 9385304 commit d7b4d1e

File tree

16 files changed

+249
-217
lines changed

16 files changed

+249
-217
lines changed
Lines changed: 1 addition & 0 deletions
Loading
Lines changed: 1 addition & 0 deletions
Loading

src/components/PromotionList/Holder.js

Lines changed: 0 additions & 26 deletions
This file was deleted.

src/components/PromotionList/PartnerBanner.js

Lines changed: 0 additions & 33 deletions
This file was deleted.
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 { TItem } from './spec'
4+
import {
5+
Wrapper,
6+
ItemWrapper,
7+
Header,
8+
Logo,
9+
Title,
10+
Desc,
11+
} from './styles/spotlight'
12+
13+
type TProps = {
14+
item: TItem
15+
}
16+
17+
const Spotlight: React.FC<TProps> = ({ item }) => (
18+
<Wrapper>
19+
<ItemWrapper>
20+
<Header>
21+
<Title>{item.title}</Title>
22+
<Logo src={item.cover} />
23+
</Header>
24+
<Desc>{item.desc}</Desc>
25+
</ItemWrapper>
26+
</Wrapper>
27+
)
28+
29+
export default React.memo(Spotlight)
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import React from 'react'
2+
3+
import type { TItem } from './spec'
4+
import { Wrapper, Item } from './styles/wait_list'
5+
6+
type TProps = {
7+
items: TItem[]
8+
activeId: string
9+
setActiveId: (id: string) => void
10+
}
11+
12+
const WaitList: React.FC<TProps> = ({ items, activeId, setActiveId }) => {
13+
return (
14+
<Wrapper>
15+
{items.map((item) => (
16+
<Item
17+
key={item.id}
18+
active={item.id === activeId}
19+
onClick={() => setActiveId(item.id)}
20+
>
21+
{item.title}
22+
</Item>
23+
))}
24+
</Wrapper>
25+
)
26+
}
27+
28+
export default React.memo(WaitList)
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { ICON_CMD } from '@/config'
2+
3+
const items = [
4+
{
5+
id: '1',
6+
title: 'xaudiopro',
7+
link: 'https://xxxx',
8+
desc: '音频剪辑,格式转换, 音频剪辑,格式转换 音频剪辑',
9+
cover: `${ICON_CMD}/test_ad.jpg`,
10+
},
11+
{
12+
id: '2',
13+
title: 'github',
14+
link: 'https://xxxx',
15+
desc: 'github 就不用多介绍了吧',
16+
cover: `${ICON_CMD}/test_ad.jpg`,
17+
},
18+
{
19+
id: '3',
20+
title: 'xxoo',
21+
link: 'https://xxxx',
22+
desc: 'xxx 就不用多介绍了吧',
23+
cover: `${ICON_CMD}/test_ad.jpg`,
24+
},
25+
{
26+
id: '4',
27+
title: 'xxoo2',
28+
link: 'https://xxxx',
29+
desc: 'xxx2 就不用多介绍了吧',
30+
cover: `${ICON_CMD}/test_ad.jpg`,
31+
},
32+
]
33+
34+
export default items

src/components/PromotionList/index.js

Lines changed: 0 additions & 48 deletions
This file was deleted.
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
*
3+
* PromotionList
4+
*
5+
*/
6+
7+
import React, { useState, useRef } from 'react'
8+
import { findIndex } from 'ramda'
9+
10+
import { ICON } from '@/config'
11+
import { buildLog } from '@/utils'
12+
import { useInterval } from '@/hooks'
13+
14+
import useHoverDirty from 'react-use/lib/useHoverDirty'
15+
16+
import type { TItem } from './spec'
17+
import Spotlight from './Spotlight'
18+
import WaitList from './WaitList'
19+
20+
import { Wrapper, Header, Title, AboutIcon } from './styles'
21+
import fakeItems from './fakeItems'
22+
23+
/* eslint-disable-next-line */
24+
const log = buildLog('c:PromotionList:index')
25+
26+
type TProps = {
27+
show?: boolean
28+
onAbout?: () => void
29+
items: TItem[]
30+
intervalSec?: number
31+
}
32+
33+
const PromotionList: React.FC<TProps> = ({
34+
show = true,
35+
onAbout = log,
36+
items = fakeItems,
37+
intervalSec = 5000,
38+
}) => {
39+
const [activeId, setActiveId] = useState<string>(items[0].id)
40+
const activeItemIndex = findIndex((item) => item.id === activeId, items)
41+
const activeItem = items[activeItemIndex]
42+
43+
const ref = useRef(null)
44+
45+
const isHovering = useHoverDirty(ref)
46+
47+
useInterval(() => {
48+
if (isHovering) return
49+
const nextIndex =
50+
activeItemIndex < items.length - 1 ? activeItemIndex + 1 : 0
51+
setActiveId(items[nextIndex].id)
52+
}, intervalSec)
53+
54+
return (
55+
<Wrapper ref={ref}>
56+
{show && (
57+
<>
58+
<Header>
59+
<Title>产品推广</Title>
60+
<div onClick={onAbout}>
61+
<AboutIcon src={`${ICON}/shape/question.svg`} />
62+
</div>
63+
</Header>
64+
<Spotlight item={activeItem} />
65+
<WaitList
66+
items={items}
67+
activeId={activeId}
68+
setActiveId={setActiveId}
69+
/>
70+
</>
71+
)}
72+
</Wrapper>
73+
)
74+
}
75+
76+
export default React.memo(PromotionList)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export type TItem = {
2+
id: string
3+
title: string
4+
link: string
5+
desc: string
6+
cover?: string
7+
}

0 commit comments

Comments
 (0)