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

fix(drawer): fix drawer close error #1066

Merged
merged 3 commits into from
Apr 24, 2021
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
4 changes: 2 additions & 2 deletions src/containers/thread/PostsThread/logic.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const { SR71, $solver, asyncRes, asyncErr } = asyncSuit
const sr71$ = new SR71({
receive: [
EVENT.REFRESH_POSTS,
EVENT.DRAWER.CLOSE,
EVENT.DRAWER.AFTER_CLOSE,
EVENT.COMMUNITY_CHANGE,
EVENT.THREAD_CHANGE,
EVENT.C11N_DENSITY_CHANGE,
Expand Down Expand Up @@ -215,7 +215,7 @@ const DataSolver = [
},
},
{
match: asyncRes(EVENT.DRAWER.CLOSE),
match: asyncRes(EVENT.DRAWER.AFTER_CLOSE),
action: () => {
store.setViewing({ post: {} })
store.markRoute({ ...store.filtersData, ...store.tagQuery })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,15 @@ import {

import { closeDrawer } from './logic'

const AddOn = ({ type, imageUploading }) => {
type TProps = {
type: string
imageUploading?: boolean
}

const AddOn: React.FC<TProps> = ({ type, imageUploading = false }) => {
return (
<Wrapper>
<CloseTab type={type} onClick={closeDrawer}>
<CloseTab type={type} onClick={() => closeDrawer()}>
<CloserInner />
</CloseTab>
<UploadingTab show={imageUploading}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,14 @@ import CustomScroller from '@/components/CustomScroller'
import renderContent from './renderContent'
import { Wrapper } from '../styles/content'

const Content = ({ visible, type, attachment, attUser }) => {
type TProps = {
visible: boolean
type: string // TODO:
attachment: any // TODO:
attUser: any // TODO:
}

const Content: React.FC<TProps> = ({ visible, type, attachment, attUser }) => {
const ref = useRef(null)

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,29 @@ import React, { useEffect, useRef, useState } from 'react'

import CustomScroller from '@/components/CustomScroller'

import type { TSwipeOption } from '../spec'
import renderContent from './renderContent'

import { Wrapper } from '../styles/content'
import { getMobileContentHeight } from '../styles/metrics'
import { Wrapper } from '../styles/content'
import { toggleSwipeAviliable, toggleHeaderTextVisiable } from '../logic'

const Content = ({ visible, options, type, attachment, attUser, mmType }) => {
type TProps = {
visible: boolean
options: TSwipeOption
type: string // TODO
attachment: any // TODO
attUser: any // TODO
mmType: string // TODO
}

const Content: React.FC<TProps> = ({
visible,
options,
type,
attachment,
attUser,
mmType,
}) => {
const ref = useRef(null)

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

/*
Expand Down Expand Up @@ -76,10 +92,10 @@ const Content = ({ visible, options, type, attachment, attUser, mmType }) => {
setTopEnterTimer(null)
}

toggleSwipeAviliable('Down', false)
toggleSwipeAviliable('down', false)
}}
onBottomEnter={() => toggleSwipeAviliable('Up', true)}
onBottomLeave={() => toggleSwipeAviliable('Up', false)}
onBottomEnter={() => toggleSwipeAviliable('up', true)}
onBottomLeave={() => toggleSwipeAviliable('up', false)}
autoHide
>
<Wrapper ref={ref}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ICON_CMD } from '@/config'
// import { ICON_CMD } from '../../config'
import { Wrapper, SiteLogo, Desc } from '../styles/content/place_holder'

const PlaceHolder = () => {
const PlaceHolder: React.FC = () => {
return (
<Wrapper>
<SiteLogo src={`${ICON_CMD}/barcelona.png`} />
Expand Down
10 changes: 4 additions & 6 deletions src/containers/tool/Drawer/Content/renderContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import ModeLineMenu from '@/containers/unit/ModeLineMenu'

import PlaceHolder from './PlaceHolder'

import { closeDrawer } from '../logic'

import {
PostViewer,
JobViewer,
Expand All @@ -33,20 +31,20 @@ const renderContent = (type, attachment, attUser, mmType) => {
return <PostViewer attachment={attachment} />

case TYPE.DRAWER.POST_CREATE:
return <PostEditor onClose={closeDrawer} />
return <PostEditor />

case TYPE.DRAWER.POST_EDIT:
return <PostEditor onClose={closeDrawer} attachment={attachment} />
return <PostEditor attachment={attachment} />

// job
case TYPE.DRAWER.JOB_CREATE:
return <JobEditor onClose={closeDrawer} />
return <JobEditor />

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

case TYPE.DRAWER.JOB_EDIT:
return <JobEditor onClose={closeDrawer} attachment={attachment} />
return <JobEditor attachment={attachment} />

// repo
case TYPE.DRAWER.REPO_VIEW:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@ import { Wrapper, LeftLine, RightLine } from '../styles/header/close_line'

import { closeDrawer } from '../logic'

const CloseLine = ({ curve }) => {
type TProps = {
curve: boolean
}

const CloseLine: React.FC<TProps> = ({ curve }) => {
return (
<Wrapper onClick={closeDrawer}>
<Wrapper onClick={() => closeDrawer()}>
<LeftLine curve={curve} />
<RightLine curve={curve} />
</Wrapper>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,23 @@ import React from 'react'
import { useSwipe } from '@/hooks'
import { nilOrEmpty } from '@/utils'

import type { TSwipeOption } from '../spec'
import CloseLine from './CloseLine'
import { TopWrapper, BottomWrapper, TextWrapper } from '../styles/header'
import { onSwipedYHandler, onSwipingYHandler } from '../logic'

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

const Header = ({
type TProps = {
headerText?: string
options: TSwipeOption
setSwipeUpY: (i: number) => void
setSwipeDownY: (i: number) => void
canBeClose: boolean
showHeaderText: boolean
}

const Header: React.FC<TProps> = ({
headerText,
options,
setSwipeUpY,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
import React from 'react'

import type { TSwipeOption } from '../spec'
import AddOn from '../AddOn'

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

const DesktopView = ({
type TProps = {
testid?: string
options: TSwipeOption
visible: boolean
rightOffset: string
type: string
imageUploading: boolean
children: React.ReactNode
}

const DesktopView: React.FC<TProps> = ({
testid = 'drawer-sidebar-panel',
options,
visible,
rightOffset,
Expand All @@ -15,9 +27,9 @@ const DesktopView = ({
}) => {
return (
<React.Fragment>
<DrawerOverlay visible={visible} onClick={closeDrawer} />
<DrawerOverlay visible={visible} onClick={() => closeDrawer()} />
<DrawerWrapper
testid="drawer-sidebar-panel"
testid={testid}
visible={visible}
rightOffset={rightOffset}
type={type}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import React, { useEffect, useState } from 'react'
import { useTheme } from 'styled-components'

import type { TThemeMap } from '@/spec'
import { useSwipe } from '@/hooks'

import type { TSwipeOption } from '../spec'
import AddOn from '../AddOn'
import Header from '../Header'

Expand All @@ -20,7 +22,21 @@ import {
resetSwipeAviliable,
} from '../logic'

const Viewer = ({
type TProps = {
testid?: string
headerText: string
options: TSwipeOption
visible: boolean
type: string
imageUploading: boolean
canBeClose: boolean
showHeaderText: boolean
disableContentDrag: boolean
children: React.ReactNode
}

const Viewer: React.FC<TProps> = ({
testid = 'drawer-sidebar-panel',
headerText,
options,
visible,
Expand All @@ -31,7 +47,7 @@ const Viewer = ({
disableContentDrag,
children,
}) => {
const theme = useTheme()
const theme: TThemeMap = useTheme()
// swipe action state for top && bottom
// null means restore and close
const [swipeDownY, setSwipeDownY] = useState(null)
Expand Down Expand Up @@ -65,9 +81,9 @@ const Viewer = ({

return (
<div>
<DrawerOverlay visible={visible} onClick={closeDrawer} />
<DrawerOverlay visible={visible} onClick={() => closeDrawer()} />
<DrawerWrapper
testid="drawer-sidebar-panel"
testid={testid}
visible={visible}
type={type}
swipeUpY={swipeUpY}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
const CommonLoading = () => (
<div>
<br />
{/* @ts-ignore */}
<ArticleContentLoading />
</div>
)
Expand All @@ -22,6 +23,7 @@ const commonConfig = {

// editor style loading config
const editorConfig = {
// @ts-ignore
loading: () => <EditorLoading />,
ssr: false,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import T from 'prop-types'
import { pluggedIn, buildLog } from '@/utils'
import { useShortcut, useResize } from '@/hooks'

import type { TStore } from './store'

import Viewer from './Viewer/index'
import Content from './Content'

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

const DrawerContainer = ({ drawer: store }) => {
type TProps = {
drawer: TStore
}

const DrawerContainer: React.FC<TProps> = ({ drawer: store }) => {
const { width: windowWidth } = useResize()
useInit(store, windowWidth)
useShortcut('Escape', closeDrawer)
Expand Down
Loading