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

Commit 7b77380

Browse files
authored
refactor(drawer): article navi (#1159)
* refactor(drawer): preview navi & style adjust * refactor(drawer): preview navi with works
1 parent b23318d commit 7b77380

File tree

17 files changed

+150
-89
lines changed

17 files changed

+150
-89
lines changed

src/components/AvatarsRow/styles/metric.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export const getLiSize = (size: TAvatarSize): string => {
1616
}
1717

1818
default: {
19-
return '24px'
19+
return '22px'
2020
}
2121
}
2222
}
@@ -27,7 +27,7 @@ export const getAvatarSize = (
2727
): string | number => {
2828
switch (size) {
2929
case SIZE.SMALL: {
30-
return fmt === 'string' ? '24px' : 24
30+
return fmt === 'string' ? '22px' : 22
3131
}
3232

3333
case SIZE.MEDIUM: {

src/components/AvatarsRow/styles/real_avatar.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,12 @@ type TAvatarsImg = { size: string; onClick: () => void; scrollPosition: any }
3434
export const AvatarsImg = styled(Img)<TAvatarsImg>`
3535
border: 2px solid;
3636
border-color: ${theme('thread.commentsUserBorder')};
37-
border-radius: 100px 100px 100px 100px;
3837
color: #ffffff;
3938
font-family: sans-serif;
4039
font-size: 12px;
4140
font-weight: 100;
4241
43-
width: ${({ size }) => getAvatarSize(size)};
44-
height: ${({ size }) => getAvatarSize(size)};
45-
display: block;
42+
${({ size }) => css.circle(getAvatarSize(size))};
4643
4744
text-align: center;
4845
`
@@ -61,6 +58,7 @@ export const AvatarsMore = styled.span<TAvatarsMore>`
6158
height: ${({ size }) => getAvatarSize(size)};
6259
6360
padding-left: ${({ total }) => (total >= 1000 ? '5px' : '3px')};
61+
padding-top: 1px;
6462
6563
&:hover {
6664
cursor: pointer;

src/components/DigestSentence/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,9 @@ const DigestSentence: FC<TProps> = ({
5858
const { scrollHeight, clientHeight } = textRef.current
5959
// console.log('clientHeight: ', clientHeight)
6060
// console.log('scrollHeight: ', scrollHeight)
61+
// console.log('scrollHeight - clientHeight: ', scrollHeight - clientHeight)
6162
// 确保只有超过两行才是折叠的情况
62-
scrollHeight - clientHeight >= 22 ? setFold(true) : setFold(false)
63+
scrollHeight - clientHeight >= 21 ? setFold(true) : setFold(false)
6364
}
6465
}, [textRef])
6566

src/containers/tool/Drawer/AddOn.tsx

Lines changed: 41 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import { FC, memo } from 'react'
22

3+
import { previewArticle } from '@/utils/helper'
34
import { SpaceGrow } from '@/components/Common'
45
import GotoTop from '@/components/GotoTop'
56
import IconButton from '@/components/Buttons/IconButton'
67

8+
import type { TArticleNavi } from './spec'
79
import {
810
Wrapper,
911
CloseWrapper,
@@ -15,13 +17,15 @@ import {
1517
GotoTopWrapper,
1618
} from './styles/add_on'
1719

18-
import { closeDrawer } from './logic'
20+
import { closeDrawer, naviToArticle } from './logic'
1921

2022
type TProps = {
2123
type: string
24+
articleNavi?: TArticleNavi
2225
}
2326

24-
const AddOn: FC<TProps> = ({ type }) => {
27+
const AddOn: FC<TProps> = ({ type, articleNavi }) => {
28+
// console.log('-- type: ', type)
2529
return (
2630
<Wrapper>
2731
<CloseWrapper type={type}>
@@ -43,34 +47,41 @@ const AddOn: FC<TProps> = ({ type }) => {
4347
</CloseWrapper>
4448

4549
<SwitchArticleWrapper show>
46-
<SwitchBlock>
47-
<IconButton
48-
path="shape/previous-article.svg"
49-
size={23}
50-
mRight={0}
51-
mLeft={2}
52-
dimWhenIdle
53-
/>
54-
<ArticleWrapper>
55-
<IndexDesc>上一篇</IndexDesc>
56-
<ArticleTitle>
57-
可能是最性感的开发者社区诚邀内侧,来为你心爱的作品建立一个社区吧!
58-
</ArticleTitle>
59-
</ArticleWrapper>
60-
</SwitchBlock>
61-
<SwitchBlock>
62-
<IconButton
63-
path="shape/next-article.svg"
64-
size={23}
65-
mTop={10}
66-
mRight={6}
67-
dimWhenIdle
68-
/>
69-
<ArticleWrapper next>
70-
<IndexDesc>下一篇</IndexDesc>
71-
<ArticleTitle>这是下一篇文章的标题!</ArticleTitle>
72-
</ArticleWrapper>
73-
</SwitchBlock>
50+
{articleNavi?.previous && (
51+
<SwitchBlock>
52+
<IconButton
53+
path="shape/previous-article.svg"
54+
size={23}
55+
mRight={0}
56+
mLeft={2}
57+
onClick={() => naviToArticle(articleNavi.previous)}
58+
dimWhenIdle
59+
/>
60+
<ArticleWrapper onClick={() => naviToArticle(articleNavi.previous)}>
61+
<IndexDesc>上一篇</IndexDesc>
62+
<ArticleTitle>{articleNavi.previous.title}</ArticleTitle>
63+
</ArticleWrapper>
64+
</SwitchBlock>
65+
)}
66+
{articleNavi?.next && (
67+
<SwitchBlock>
68+
<IconButton
69+
path="shape/next-article.svg"
70+
size={23}
71+
mTop={10}
72+
mRight={6}
73+
onClick={() => naviToArticle(articleNavi.next)}
74+
dimWhenIdle
75+
/>
76+
<ArticleWrapper
77+
onClick={() => naviToArticle(articleNavi.next)}
78+
next
79+
>
80+
<IndexDesc>下一篇</IndexDesc>
81+
<ArticleTitle>{articleNavi.next.title}</ArticleTitle>
82+
</ArticleWrapper>
83+
</SwitchBlock>
84+
)}
7485
</SwitchArticleWrapper>
7586
<SpaceGrow />
7687
<GotoTopWrapper>

src/containers/tool/Drawer/Viewer/DesktopView.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { FC, ReactNode, memo } from 'react'
22

3-
import type { TSwipeOption } from '../spec'
3+
import type { TSwipeOption, TArticleNavi } from '../spec'
44
import AddOn from '../AddOn'
55

66
import { DrawerOverlay, DrawerWrapper, DrawerContent } from '../styles'
@@ -12,6 +12,7 @@ type TProps = {
1212
visible: boolean
1313
rightOffset: string
1414
type: string
15+
articleNavi?: TArticleNavi
1516
children: ReactNode
1617
}
1718

@@ -21,6 +22,7 @@ const DesktopView: FC<TProps> = ({
2122
visible,
2223
rightOffset,
2324
type,
25+
articleNavi,
2426
children,
2527
}) => {
2628
return (
@@ -34,7 +36,7 @@ const DesktopView: FC<TProps> = ({
3436
mobile={false}
3537
options={options}
3638
>
37-
<AddOn type={type} />
39+
<AddOn type={type} articleNavi={articleNavi} />
3840
<DrawerContent>{children}</DrawerContent>
3941
</DrawerWrapper>
4042
</React.Fragment>

src/containers/tool/Drawer/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ const DrawerContainer: FC<TProps> = ({ drawer: store }) => {
4040
headerText,
4141
showHeaderText,
4242
disableContentDrag,
43+
articleNavi,
4344
} = store
4445

4546
return (
@@ -52,6 +53,7 @@ const DrawerContainer: FC<TProps> = ({ drawer: store }) => {
5253
canBeClose={canBeClose}
5354
showHeaderText={showHeaderText}
5455
disableContentDrag={disableContentDrag}
56+
articleNavi={articleNavi}
5557
>
5658
<Content
5759
type={type}

src/containers/tool/Drawer/logic.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { useEffect } from 'react'
22
import { contains, values } from 'ramda'
33

4-
import type { TDirection } from '@/spec'
4+
import type { TArticle, TDirection } from '@/spec'
55
import { TYPE, EVENT } from '@/constant'
66

77
import { toggleGlobalBlur, clearGlobalBlur } from '@/utils/dom'
8-
import { Global, send, debounce } from '@/utils/helper'
8+
import { Global, send, debounce, previewArticle } from '@/utils/helper'
99
import { buildLog } from '@/utils/logger'
1010
import asyncSuit from '@/utils/async'
1111

@@ -40,6 +40,11 @@ export const closeDrawer = (): void => {
4040
}, 200)
4141
}
4242

43+
export const naviToArticle = (article: TArticle): void => {
44+
previewArticle(article)
45+
send(EVENT.RELOAD_ARTICLE)
46+
}
47+
4348
// handler swiped event for up/down swipe
4449
// 判断最终是回到原来的位置还是隐藏 panel
4550
export const onSwipedYHandler = (
@@ -146,6 +151,7 @@ export const toggleHeaderTextVisiable = (bool: boolean): void => {
146151

147152
export const resetSwipeAviliable = (): void => store.resetSwipeAviliable()
148153

154+
//
149155
const DataResolver = [
150156
{
151157
match: asyncRes(EVENT.DRAWER.OPEN),

src/containers/tool/Drawer/spec.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { TTestable, TActive } from '@/spec'
1+
import type { TTestable, TActive, TArticle } from '@/spec'
22

33
export type TSwipeOption = {
44
direction: 'bottom' | 'top'
@@ -19,3 +19,8 @@ export type TDrawer = TTestable &
1919
rightOffset?: string
2020
type: string
2121
}
22+
23+
export type TArticleNavi = {
24+
previous: TArticle | null
25+
next: TArticle | null
26+
}

src/containers/tool/Drawer/store.ts

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

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

9-
import type { TRootStore, TCommunity, TThread, TArticle } from '@/spec'
10-
import { TYPE, ARTICLE_THREAD } from '@/constant'
9+
import type { TRootStore, TCommunity, TThread, TArticle, TWorks } from '@/spec'
10+
import { TYPE, ARTICLE_THREAD, THREAD } from '@/constant'
1111

1212
import { markStates, toJS } from '@/utils/mobx'
1313
import { toggleGlobalBlur, lockPage, unlockPage } from '@/utils/dom'
14-
import { Global } from '@/utils/helper'
14+
import { Global, titleCase } from '@/utils/helper'
1515
import { WIDTH, mediaBreakPoints } from '@/utils/css/metric'
1616
import { User } from '@/model'
1717

18-
import { TSwipeOption } from './spec'
18+
import { TSwipeOption, TArticleNavi } from './spec'
1919
import { SWIPE_THRESHOLD } from './styles/metrics'
2020

2121
const defaultOptions: TSwipeOption = { direction: 'bottom', position: 'M' }
@@ -117,10 +117,42 @@ const DrawerStore = T.model('DrawerStore', {
117117
get modalVisible() {
118118
return self.visible && Global.innerWidth > mediaBreakPoints.desktopL
119119
},
120-
121120
get slideVisible() {
122121
return self.visible && Global.innerWidth <= mediaBreakPoints.desktopL
123122
},
123+
get viewingArticle(): TArticle {
124+
const root = getParent(self) as TRootStore
125+
return root.viewing.viewingArticle
126+
},
127+
get articleNavi(): TArticleNavi {
128+
const slf = self as TStore
129+
const root = getParent(self) as TRootStore
130+
const viewingArticleId = slf.viewingArticle.id
131+
132+
let pagedArticles
133+
switch (slf.curThread) {
134+
case THREAD.WORKS: {
135+
pagedArticles = toJS(root.worksContent.pagedWorks)
136+
break
137+
}
138+
139+
default: {
140+
pagedArticles = toJS(
141+
root.articlesThread[`paged${titleCase(slf.curThread)}s`],
142+
)
143+
break
144+
}
145+
}
146+
147+
const curIndex = findIndex(
148+
(a: TWorks) => a.id === viewingArticleId,
149+
pagedArticles.entries,
150+
)
151+
return {
152+
previous: pagedArticles.entries[curIndex - 1] || null,
153+
next: pagedArticles.entries[curIndex + 1] || null,
154+
}
155+
},
124156
}))
125157
.actions((self) => ({
126158
open({ type, data, options = {} }): void {

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ export const SwitchArticleWrapper = styled.div<TActive>`
6161
6262
transition: opacity 0.2s linear;
6363
`
64-
export const SwitchBlock = styled.div``
64+
export const SwitchBlock = styled.div`
65+
cursor: pointer;
66+
`
6567
export const ArticleWrapper = styled.div<{ next?: boolean }>`
6668
${css.flexColumn('align-start')};
6769
position: absolute;
@@ -73,6 +75,7 @@ export const ArticleWrapper = styled.div<{ next?: boolean }>`
7375
display: none;
7476
${SwitchBlock}:hover & {
7577
display: block;
78+
cursor: pointer;
7679
}
7780
`
7881
export const IndexDesc = styled.div`

0 commit comments

Comments
 (0)