Skip to content
This repository was archived by the owner on Nov 8, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions public/icons/static/shape/about.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions public/icons/static/shape/question.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 0 additions & 26 deletions src/components/PromotionList/Holder.js

This file was deleted.

33 changes: 0 additions & 33 deletions src/components/PromotionList/PartnerBanner.js

This file was deleted.

29 changes: 29 additions & 0 deletions src/components/PromotionList/Spotlight.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import React from 'react'

import type { TItem } from './spec'
import {
Wrapper,
ItemWrapper,
Header,
Logo,
Title,
Desc,
} from './styles/spotlight'

type TProps = {
item: TItem
}

const Spotlight: React.FC<TProps> = ({ item }) => (
<Wrapper>
<ItemWrapper>
<Header>
<Title>{item.title}</Title>
<Logo src={item.cover} />
</Header>
<Desc>{item.desc}</Desc>
</ItemWrapper>
</Wrapper>
)

export default React.memo(Spotlight)
28 changes: 28 additions & 0 deletions src/components/PromotionList/WaitList.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import React from 'react'

import type { TItem } from './spec'
import { Wrapper, Item } from './styles/wait_list'

type TProps = {
items: TItem[]
activeId: string
setActiveId: (id: string) => void
}

const WaitList: React.FC<TProps> = ({ items, activeId, setActiveId }) => {
return (
<Wrapper>
{items.map((item) => (
<Item
key={item.id}
active={item.id === activeId}
onClick={() => setActiveId(item.id)}
>
{item.title}
</Item>
))}
</Wrapper>
)
}

export default React.memo(WaitList)
34 changes: 34 additions & 0 deletions src/components/PromotionList/fakeItems.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { ICON_CMD } from '@/config'

const items = [
{
id: '1',
title: 'xaudiopro',
link: 'https://xxxx',
desc: '音频剪辑,格式转换, 音频剪辑,格式转换 音频剪辑',
cover: `${ICON_CMD}/test_ad.jpg`,
},
{
id: '2',
title: 'github',
link: 'https://xxxx',
desc: 'github 就不用多介绍了吧',
cover: `${ICON_CMD}/test_ad.jpg`,
},
{
id: '3',
title: 'xxoo',
link: 'https://xxxx',
desc: 'xxx 就不用多介绍了吧',
cover: `${ICON_CMD}/test_ad.jpg`,
},
{
id: '4',
title: 'xxoo2',
link: 'https://xxxx',
desc: 'xxx2 就不用多介绍了吧',
cover: `${ICON_CMD}/test_ad.jpg`,
},
]

export default items
48 changes: 0 additions & 48 deletions src/components/PromotionList/index.js

This file was deleted.

76 changes: 76 additions & 0 deletions src/components/PromotionList/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
*
* PromotionList
*
*/

import React, { useState, useRef } from 'react'
import { findIndex } from 'ramda'

import { ICON } from '@/config'
import { buildLog } from '@/utils'
import { useInterval } from '@/hooks'

import useHoverDirty from 'react-use/lib/useHoverDirty'

import type { TItem } from './spec'
import Spotlight from './Spotlight'
import WaitList from './WaitList'

import { Wrapper, Header, Title, AboutIcon } from './styles'
import fakeItems from './fakeItems'

/* eslint-disable-next-line */
const log = buildLog('c:PromotionList:index')

type TProps = {
show?: boolean
onAbout?: () => void
items: TItem[]
intervalSec?: number
}

const PromotionList: React.FC<TProps> = ({
show = true,
onAbout = log,
items = fakeItems,
intervalSec = 5000,
}) => {
const [activeId, setActiveId] = useState<string>(items[0].id)
const activeItemIndex = findIndex((item) => item.id === activeId, items)
const activeItem = items[activeItemIndex]

const ref = useRef(null)

const isHovering = useHoverDirty(ref)

useInterval(() => {
if (isHovering) return
const nextIndex =
activeItemIndex < items.length - 1 ? activeItemIndex + 1 : 0
setActiveId(items[nextIndex].id)
}, intervalSec)

return (
<Wrapper ref={ref}>
{show && (
<>
<Header>
<Title>产品推广</Title>
<div onClick={onAbout}>
<AboutIcon src={`${ICON}/shape/question.svg`} />
</div>
</Header>
<Spotlight item={activeItem} />
<WaitList
items={items}
activeId={activeId}
setActiveId={setActiveId}
/>
</>
)}
</Wrapper>
)
}

export default React.memo(PromotionList)
7 changes: 7 additions & 0 deletions src/components/PromotionList/spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export type TItem = {
id: string
title: string
link: string
desc: string
cover?: string
}
39 changes: 0 additions & 39 deletions src/components/PromotionList/styles/holder.ts

This file was deleted.

22 changes: 8 additions & 14 deletions src/components/PromotionList/styles/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,25 @@ import { css, theme } from '@/utils'

export const Wrapper = styled.div`
margin-left: 20px;
margin-top: 40px;
margin-top: 30px;
min-height: 150px;
max-width: 180px;
`
export const Header = styled.div`
${css.flex('justify-between', 'align-center')};
padding-top: 20px;
margin-bottom: 12px;
border-top: 1px solid;
border-top-color: ${theme('thread.articleSpliter')};
width: 80%;
`
export const Title = styled.div`
font-size: 12px;
color: ${theme('thread.articleDigest')};
border-top: 1px solid;
border-top-color: ${theme('thread.articleSpliter')};
padding-top: 15px;
width: 80px;

${Wrapper}:hover & {
width: 100%;
}

transition: width 0.3s;
transition-delay: 0.2s;
`
export const AboutIcon = styled(Img)`
${css.size(14)};
${css.size(15)};
fill: ${theme('thread.articleDigest')};
opacity: 0;
margin-top: 16px;
Expand All @@ -41,6 +36,5 @@ export const AboutIcon = styled(Img)`
${Wrapper}:hover & {
opacity: 1;
}
transition: all 0.2s;
transition-delay: 0.2s;
transition: all 0.25s;
`
Loading