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

Commit d288887

Browse files
authored
fix(drawer): fix drawer close error (#1066)
* fix(drawer): event cycle error * chore(drawer): covert js -> ts * chore(drawer): covert js -> ts
1 parent 31df66f commit d288887

File tree

23 files changed

+162
-60
lines changed

23 files changed

+162
-60
lines changed

src/containers/thread/PostsThread/logic.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const { SR71, $solver, asyncRes, asyncErr } = asyncSuit
2929
const sr71$ = new SR71({
3030
receive: [
3131
EVENT.REFRESH_POSTS,
32-
EVENT.DRAWER.CLOSE,
32+
EVENT.DRAWER.AFTER_CLOSE,
3333
EVENT.COMMUNITY_CHANGE,
3434
EVENT.THREAD_CHANGE,
3535
EVENT.C11N_DENSITY_CHANGE,
@@ -215,7 +215,7 @@ const DataSolver = [
215215
},
216216
},
217217
{
218-
match: asyncRes(EVENT.DRAWER.CLOSE),
218+
match: asyncRes(EVENT.DRAWER.AFTER_CLOSE),
219219
action: () => {
220220
store.setViewing({ post: {} })
221221
store.markRoute({ ...store.filtersData, ...store.tagQuery })

src/containers/tool/Drawer/AddOn.js renamed to src/containers/tool/Drawer/AddOn.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,15 @@ import {
1313

1414
import { closeDrawer } from './logic'
1515

16-
const AddOn = ({ type, imageUploading }) => {
16+
type TProps = {
17+
type: string
18+
imageUploading?: boolean
19+
}
20+
21+
const AddOn: React.FC<TProps> = ({ type, imageUploading = false }) => {
1722
return (
1823
<Wrapper>
19-
<CloseTab type={type} onClick={closeDrawer}>
24+
<CloseTab type={type} onClick={() => closeDrawer()}>
2025
<CloserInner />
2126
</CloseTab>
2227
<UploadingTab show={imageUploading}>

src/containers/tool/Drawer/Content/DesktopView.js renamed to src/containers/tool/Drawer/Content/DesktopView.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,14 @@ import CustomScroller from '@/components/CustomScroller'
55
import renderContent from './renderContent'
66
import { Wrapper } from '../styles/content'
77

8-
const Content = ({ visible, type, attachment, attUser }) => {
8+
type TProps = {
9+
visible: boolean
10+
type: string // TODO:
11+
attachment: any // TODO:
12+
attUser: any // TODO:
13+
}
14+
15+
const Content: React.FC<TProps> = ({ visible, type, attachment, attUser }) => {
916
const ref = useRef(null)
1017

1118
/*

src/containers/tool/Drawer/Content/MobileView.js renamed to src/containers/tool/Drawer/Content/MobileView.tsx

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,29 @@ import React, { useEffect, useRef, useState } from 'react'
22

33
import CustomScroller from '@/components/CustomScroller'
44

5+
import type { TSwipeOption } from '../spec'
56
import renderContent from './renderContent'
6-
7-
import { Wrapper } from '../styles/content'
87
import { getMobileContentHeight } from '../styles/metrics'
8+
import { Wrapper } from '../styles/content'
99
import { toggleSwipeAviliable, toggleHeaderTextVisiable } from '../logic'
1010

11-
const Content = ({ visible, options, type, attachment, attUser, mmType }) => {
11+
type TProps = {
12+
visible: boolean
13+
options: TSwipeOption
14+
type: string // TODO
15+
attachment: any // TODO
16+
attUser: any // TODO
17+
mmType: string // TODO
18+
}
19+
20+
const Content: React.FC<TProps> = ({
21+
visible,
22+
options,
23+
type,
24+
attachment,
25+
attUser,
26+
mmType,
27+
}) => {
1228
const ref = useRef(null)
1329

1430
const [topEnterTimer, setTopEnterTimer] = useState(null)
@@ -48,7 +64,7 @@ const Content = ({ visible, options, type, attachment, attUser, mmType }) => {
4864
* 注意这个值是在桌面浏览器上反复试出的最佳值,过大或过小都不自然
4965
*/
5066
const topEnterTimer = setTimeout(() => {
51-
toggleSwipeAviliable('Down', true)
67+
toggleSwipeAviliable('down', true)
5268
}, 800)
5369

5470
/*
@@ -76,10 +92,10 @@ const Content = ({ visible, options, type, attachment, attUser, mmType }) => {
7692
setTopEnterTimer(null)
7793
}
7894

79-
toggleSwipeAviliable('Down', false)
95+
toggleSwipeAviliable('down', false)
8096
}}
81-
onBottomEnter={() => toggleSwipeAviliable('Up', true)}
82-
onBottomLeave={() => toggleSwipeAviliable('Up', false)}
97+
onBottomEnter={() => toggleSwipeAviliable('up', true)}
98+
onBottomLeave={() => toggleSwipeAviliable('up', false)}
8399
autoHide
84100
>
85101
<Wrapper ref={ref}>

src/containers/tool/Drawer/Content/PlaceHolder.js renamed to src/containers/tool/Drawer/Content/PlaceHolder.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { ICON_CMD } from '@/config'
44
// import { ICON_CMD } from '../../config'
55
import { Wrapper, SiteLogo, Desc } from '../styles/content/place_holder'
66

7-
const PlaceHolder = () => {
7+
const PlaceHolder: React.FC = () => {
88
return (
99
<Wrapper>
1010
<SiteLogo src={`${ICON_CMD}/barcelona.png`} />

src/containers/tool/Drawer/Content/renderContent.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ import ModeLineMenu from '@/containers/unit/ModeLineMenu'
55

66
import PlaceHolder from './PlaceHolder'
77

8-
import { closeDrawer } from '../logic'
9-
108
import {
119
PostViewer,
1210
JobViewer,
@@ -33,20 +31,20 @@ const renderContent = (type, attachment, attUser, mmType) => {
3331
return <PostViewer attachment={attachment} />
3432

3533
case TYPE.DRAWER.POST_CREATE:
36-
return <PostEditor onClose={closeDrawer} />
34+
return <PostEditor />
3735

3836
case TYPE.DRAWER.POST_EDIT:
39-
return <PostEditor onClose={closeDrawer} attachment={attachment} />
37+
return <PostEditor attachment={attachment} />
4038

4139
// job
4240
case TYPE.DRAWER.JOB_CREATE:
43-
return <JobEditor onClose={closeDrawer} />
41+
return <JobEditor />
4442

4543
case TYPE.DRAWER.JOB_VIEW:
4644
return <JobViewer attachment={attachment} />
4745

4846
case TYPE.DRAWER.JOB_EDIT:
49-
return <JobEditor onClose={closeDrawer} attachment={attachment} />
47+
return <JobEditor attachment={attachment} />
5048

5149
// repo
5250
case TYPE.DRAWER.REPO_VIEW:

src/containers/tool/Drawer/Header/CloseLine.js renamed to src/containers/tool/Drawer/Header/CloseLine.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,13 @@ import { Wrapper, LeftLine, RightLine } from '../styles/header/close_line'
44

55
import { closeDrawer } from '../logic'
66

7-
const CloseLine = ({ curve }) => {
7+
type TProps = {
8+
curve: boolean
9+
}
10+
11+
const CloseLine: React.FC<TProps> = ({ curve }) => {
812
return (
9-
<Wrapper onClick={closeDrawer}>
13+
<Wrapper onClick={() => closeDrawer()}>
1014
<LeftLine curve={curve} />
1115
<RightLine curve={curve} />
1216
</Wrapper>

src/containers/tool/Drawer/Header/index.js renamed to src/containers/tool/Drawer/Header/index.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,23 @@ import React from 'react'
33
import { useSwipe } from '@/hooks'
44
import { nilOrEmpty } from '@/utils'
55

6+
import type { TSwipeOption } from '../spec'
67
import CloseLine from './CloseLine'
78
import { TopWrapper, BottomWrapper, TextWrapper } from '../styles/header'
89
import { onSwipedYHandler, onSwipingYHandler } from '../logic'
910

1011
/* <TextWrapper>评论共 167 条</TextWrapper> */
1112

12-
const Header = ({
13+
type TProps = {
14+
headerText?: string
15+
options: TSwipeOption
16+
setSwipeUpY: (i: number) => void
17+
setSwipeDownY: (i: number) => void
18+
canBeClose: boolean
19+
showHeaderText: boolean
20+
}
21+
22+
const Header: React.FC<TProps> = ({
1323
headerText,
1424
options,
1525
setSwipeUpY,

src/containers/tool/Drawer/Viewer/DesktopView.js renamed to src/containers/tool/Drawer/Viewer/DesktopView.tsx

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,23 @@
11
import React from 'react'
22

3+
import type { TSwipeOption } from '../spec'
34
import AddOn from '../AddOn'
45

56
import { DrawerOverlay, DrawerWrapper, DrawerContent } from '../styles'
67
import { closeDrawer } from '../logic'
78

8-
const DesktopView = ({
9+
type TProps = {
10+
testid?: string
11+
options: TSwipeOption
12+
visible: boolean
13+
rightOffset: string
14+
type: string
15+
imageUploading: boolean
16+
children: React.ReactNode
17+
}
18+
19+
const DesktopView: React.FC<TProps> = ({
20+
testid = 'drawer-sidebar-panel',
921
options,
1022
visible,
1123
rightOffset,
@@ -15,9 +27,9 @@ const DesktopView = ({
1527
}) => {
1628
return (
1729
<React.Fragment>
18-
<DrawerOverlay visible={visible} onClick={closeDrawer} />
30+
<DrawerOverlay visible={visible} onClick={() => closeDrawer()} />
1931
<DrawerWrapper
20-
testid="drawer-sidebar-panel"
32+
testid={testid}
2133
visible={visible}
2234
rightOffset={rightOffset}
2335
type={type}

src/containers/tool/Drawer/Viewer/MobileView.js renamed to src/containers/tool/Drawer/Viewer/MobileView.tsx

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import React, { useEffect, useState } from 'react'
22
import { useTheme } from 'styled-components'
33

4+
import type { TThemeMap } from '@/spec'
45
import { useSwipe } from '@/hooks'
56

7+
import type { TSwipeOption } from '../spec'
68
import AddOn from '../AddOn'
79
import Header from '../Header'
810

@@ -20,7 +22,21 @@ import {
2022
resetSwipeAviliable,
2123
} from '../logic'
2224

23-
const Viewer = ({
25+
type TProps = {
26+
testid?: string
27+
headerText: string
28+
options: TSwipeOption
29+
visible: boolean
30+
type: string
31+
imageUploading: boolean
32+
canBeClose: boolean
33+
showHeaderText: boolean
34+
disableContentDrag: boolean
35+
children: React.ReactNode
36+
}
37+
38+
const Viewer: React.FC<TProps> = ({
39+
testid = 'drawer-sidebar-panel',
2440
headerText,
2541
options,
2642
visible,
@@ -31,7 +47,7 @@ const Viewer = ({
3147
disableContentDrag,
3248
children,
3349
}) => {
34-
const theme = useTheme()
50+
const theme: TThemeMap = useTheme()
3551
// swipe action state for top && bottom
3652
// null means restore and close
3753
const [swipeDownY, setSwipeDownY] = useState(null)
@@ -65,9 +81,9 @@ const Viewer = ({
6581

6682
return (
6783
<div>
68-
<DrawerOverlay visible={visible} onClick={closeDrawer} />
84+
<DrawerOverlay visible={visible} onClick={() => closeDrawer()} />
6985
<DrawerWrapper
70-
testid="drawer-sidebar-panel"
86+
testid={testid}
7187
visible={visible}
7288
type={type}
7389
swipeUpY={swipeUpY}

src/containers/tool/Drawer/dynamics.js renamed to src/containers/tool/Drawer/dynamics.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
const CommonLoading = () => (
1111
<div>
1212
<br />
13+
{/* @ts-ignore */}
1314
<ArticleContentLoading />
1415
</div>
1516
)
@@ -22,6 +23,7 @@ const commonConfig = {
2223

2324
// editor style loading config
2425
const editorConfig = {
26+
// @ts-ignore
2527
loading: () => <EditorLoading />,
2628
ssr: false,
2729
}

src/containers/tool/Drawer/index.js renamed to src/containers/tool/Drawer/index.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import T from 'prop-types'
1010
import { pluggedIn, buildLog } from '@/utils'
1111
import { useShortcut, useResize } from '@/hooks'
1212

13+
import type { TStore } from './store'
14+
1315
import Viewer from './Viewer/index'
1416
import Content from './Content'
1517

@@ -18,7 +20,11 @@ import { useInit, closeDrawer } from './logic'
1820
/* eslint-disable-next-line */
1921
const log = buildLog('C:Preview')
2022

21-
const DrawerContainer = ({ drawer: store }) => {
23+
type TProps = {
24+
drawer: TStore
25+
}
26+
27+
const DrawerContainer: React.FC<TProps> = ({ drawer: store }) => {
2228
const { width: windowWidth } = useResize()
2329
useInit(store, windowWidth)
2430
useShortcut('Escape', closeDrawer)

0 commit comments

Comments
 (0)