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

Commit bb12365

Browse files
committed
refactor(drawer): re-org addon code
1 parent 7b77380 commit bb12365

File tree

10 files changed

+270
-213
lines changed

10 files changed

+270
-213
lines changed

src/containers/tool/Drawer/AddOn.tsx

Lines changed: 0 additions & 94 deletions
This file was deleted.
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import { FC, memo } from 'react'
2+
3+
import IconButton from '@/components/Buttons/IconButton'
4+
5+
import type { TArticleNavi } from '../spec'
6+
7+
import {
8+
Wrapper,
9+
SwitchBlock,
10+
ArticleWrapper,
11+
IndexDesc,
12+
ArticleTitle,
13+
} from '../styles/add_on/article_navi'
14+
15+
import { naviToArticle } from '../logic'
16+
17+
type TProps = {
18+
articleNavi?: TArticleNavi
19+
// show?: boolean
20+
}
21+
22+
const ArticleNavi: FC<TProps> = ({ articleNavi }) => {
23+
// console.log('-- type: ', type)
24+
return (
25+
<Wrapper show>
26+
{articleNavi?.previous && (
27+
<SwitchBlock>
28+
<IconButton
29+
path="shape/previous-article.svg"
30+
size={23}
31+
mRight={0}
32+
mLeft={2}
33+
onClick={() => naviToArticle(articleNavi.previous)}
34+
dimWhenIdle
35+
/>
36+
<ArticleWrapper onClick={() => naviToArticle(articleNavi.previous)}>
37+
<IndexDesc>上一篇</IndexDesc>
38+
<ArticleTitle>{articleNavi.previous.title}</ArticleTitle>
39+
</ArticleWrapper>
40+
</SwitchBlock>
41+
)}
42+
{articleNavi?.next && (
43+
<SwitchBlock>
44+
<IconButton
45+
path="shape/next-article.svg"
46+
size={23}
47+
mTop={10}
48+
mRight={6}
49+
onClick={() => naviToArticle(articleNavi.next)}
50+
dimWhenIdle
51+
/>
52+
<ArticleWrapper onClick={() => naviToArticle(articleNavi.next)} next>
53+
<IndexDesc>下一篇</IndexDesc>
54+
<ArticleTitle>{articleNavi.next.title}</ArticleTitle>
55+
</ArticleWrapper>
56+
</SwitchBlock>
57+
)}
58+
</Wrapper>
59+
)
60+
}
61+
62+
export default memo(ArticleNavi)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { FC, memo } from 'react'
2+
3+
import IconButton from '@/components/Buttons/IconButton'
4+
import { closeDrawer } from '../logic'
5+
6+
const CloseButton: FC = () => {
7+
return (
8+
<IconButton
9+
path="shape/close.svg"
10+
onClick={closeDrawer}
11+
size={26}
12+
dimWhenIdle
13+
/>
14+
)
15+
}
16+
17+
export default memo(CloseButton)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { FC, memo } from 'react'
2+
3+
import IconButton from '@/components/Buttons/IconButton'
4+
5+
const ShareButton: FC = () => {
6+
return (
7+
<IconButton
8+
path="article/share.svg"
9+
size={19}
10+
mTop={7}
11+
mLeft={-1}
12+
hint="分享本文"
13+
hintPlacement="bottom"
14+
dimWhenIdle
15+
/>
16+
)
17+
}
18+
19+
export default memo(ShareButton)
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { FC, memo } from 'react'
2+
import { includes } from 'ramda'
3+
4+
import { SpaceGrow } from '@/components/Common'
5+
import GotoTop from '@/components/GotoTop'
6+
7+
import ArticleNavi from './ArticleNavi'
8+
9+
import type { TArticleNavi } from '../spec'
10+
import { ARTICLE_VIEWER_TYPES } from '../constant'
11+
12+
import CloseButton from './CloseButton'
13+
import ShareButton from './ShareButton'
14+
import { Wrapper, TopArea, BottomWrapper } from '../styles/add_on'
15+
16+
type TProps = {
17+
type: string
18+
articleNavi?: TArticleNavi
19+
}
20+
21+
const AddOn: FC<TProps> = ({ type, articleNavi }) => {
22+
const showArticleNavi = includes(type, ARTICLE_VIEWER_TYPES)
23+
24+
return (
25+
<Wrapper>
26+
<TopArea type={type}>
27+
<CloseButton />
28+
<ShareButton />
29+
</TopArea>
30+
31+
{showArticleNavi && <ArticleNavi articleNavi={articleNavi} />}
32+
33+
<SpaceGrow />
34+
<BottomWrapper>
35+
<GotoTop type="drawer" />
36+
</BottomWrapper>
37+
</Wrapper>
38+
)
39+
}
40+
41+
export default memo(AddOn)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { concat, keys, reduce } from 'ramda'
2+
3+
import { TYPE, ARTICLE_THREAD } from '@/constant'
4+
5+
export const ARTICLE_VIEWER_TYPES = reduce(
6+
concat,
7+
// @ts-ignore
8+
[],
9+
keys(ARTICLE_THREAD).map((T) => [TYPE.DRAWER[`${T}_VIEW`]]),
10+
)
11+
12+
export const ARTICLE_THREAD_CURD_TYPES = reduce(
13+
concat,
14+
// @ts-ignore
15+
[...ARTICLE_VIEWER_TYPES],
16+
keys(ARTICLE_THREAD).map((T) => [
17+
TYPE.DRAWER[`${T}_CREATE`],
18+
TYPE.DRAWER[`${T}_EDIT`],
19+
]),
20+
)

src/containers/tool/Drawer/store.ts

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

66
import { types as T, getParent, Instance } from 'mobx-state-tree'
7-
import { concat, keys, reduce, merge, contains, values, findIndex } from 'ramda'
7+
import { merge, contains, values, findIndex } from 'ramda'
88

99
import type { TRootStore, TCommunity, TThread, TArticle, TWorks } from '@/spec'
1010
import { TYPE, ARTICLE_THREAD, THREAD } from '@/constant'
@@ -16,27 +16,11 @@ import { WIDTH, mediaBreakPoints } from '@/utils/css/metric'
1616
import { User } from '@/model'
1717

1818
import { TSwipeOption, TArticleNavi } from './spec'
19+
import { ARTICLE_VIEWER_TYPES, ARTICLE_THREAD_CURD_TYPES } from './constant'
1920
import { SWIPE_THRESHOLD } from './styles/metrics'
2021

2122
const defaultOptions: TSwipeOption = { direction: 'bottom', position: 'M' }
2223

23-
const ARTICLE_VIEWER_TYPES = reduce(
24-
concat,
25-
// @ts-ignore
26-
[],
27-
keys(ARTICLE_THREAD).map((T) => [TYPE.DRAWER[`${T}_VIEW`]]),
28-
)
29-
30-
const ARTICLE_THREAD_CURD_TYPES = reduce(
31-
concat,
32-
// @ts-ignore
33-
[...ARTICLE_VIEWER_TYPES],
34-
keys(ARTICLE_THREAD).map((T) => [
35-
TYPE.DRAWER[`${T}_CREATE`],
36-
TYPE.DRAWER[`${T}_EDIT`],
37-
]),
38-
)
39-
4024
const Options = T.model('Options', {
4125
direction: T.optional(
4226
T.enumeration('direction', ['top', 'bottom']),

src/containers/tool/Drawer/styles/add_on.ts

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

0 commit comments

Comments
 (0)