-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
master1lan
committed
Jan 26, 2023
1 parent
34b8d9f
commit 08be3e6
Showing
26 changed files
with
543 additions
and
146 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| import { memo, useState, ReactElement } from "react"; | ||
| import styles from "./modal.module.less"; | ||
| import { createPortal } from "react-dom"; | ||
| import { useEffect } from "react"; | ||
| import { enableScroll, disableScroll } from "./scrollFn"; | ||
|
|
||
| type __Click_modal__Type = { | ||
| children: ReactElement; | ||
| visible: boolean; | ||
| closeModal: (event: any) => void; | ||
| resProps: Object; | ||
| }; | ||
|
|
||
| export const __Click_Modal__ = (props: __Click_modal__Type) => { | ||
| const { children, visible, closeModal, ...resProps } = props; | ||
| function handleClick(event: { | ||
| stopPropagation: () => void; | ||
| target: any; | ||
| currentTarget: any; | ||
| }) { | ||
| //点击蒙层本身时关闭模态框,点击模态框内容时不关闭 | ||
| event.stopPropagation(); | ||
| // event.nativeEvent.stopImmediatePropagation(); | ||
| if (event.target === event.currentTarget) { | ||
| closeModal(event); | ||
| } | ||
| } | ||
| let modal; | ||
| typeof document !== "undefined" && | ||
| (modal = createPortal( | ||
| <div {...resProps} className={styles.modal} onClick={handleClick}> | ||
| {children} | ||
| </div>, | ||
| document.body | ||
| )); | ||
| return <>{visible && modal}</>; | ||
| }; | ||
|
|
||
| type ModalType = { | ||
| isNoScroll: boolean; | ||
| children: ReactElement; | ||
| visible: boolean; | ||
| closeModal: (event: any) => void; | ||
| }; | ||
| export default memo(function Modal(props: ModalType) { | ||
| const { isNoScroll = false, children, ...resProps } = props; | ||
| useEffect(() => { | ||
| if (isNoScroll) { | ||
| disableScroll(); | ||
| return enableScroll; | ||
| } | ||
| }, [isNoScroll]); | ||
| //@ts-ignore | ||
| return <__Click_Modal__ {...resProps}>{children}</__Click_Modal__>; | ||
| }); | ||
|
|
||
| type useModalConfigOutputType = { | ||
| visible: boolean; | ||
| isNoScroll: boolean; | ||
| closeModal: () => void; | ||
| }; | ||
|
|
||
| export const useModalConfig = ( | ||
| _isvisible: boolean, | ||
| _isNoScroll: boolean | ||
| ): useModalConfigOutputType => { | ||
| const [isvisible, setVisible] = useState(_isvisible || false); | ||
| const [isNoScroll, setScroll] = useState(_isNoScroll || false); | ||
| const clickFunc = () => { | ||
| setScroll(!isNoScroll); | ||
| setVisible(!isvisible); | ||
| }; | ||
| return { visible: isvisible, isNoScroll, closeModal: clickFunc }; | ||
| }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| /* modal.less */ | ||
| .modal { | ||
| position: fixed; | ||
| top: 0; | ||
| left: 0; | ||
| bottom: 0; | ||
| right: 0; | ||
| z-index: 1; | ||
| min-height: 100vh; | ||
| background-color: rgba(0, 0, 0, 0.7); | ||
| } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| //@ts-nocheck | ||
| //阻止默认行为 | ||
| export function preventDefault(e) { | ||
| // console.log({ e }); | ||
| e.preventDefault(); | ||
| } | ||
|
|
||
| export function enableScroll() { | ||
| const wheelEvent = | ||
| "onwheel" in document.createElement("div") ? "wheel" : "mousewheel"; | ||
| window.removeEventListener("DOMMouseScroll", preventDefault, false); | ||
| window.removeEventListener(wheelEvent, preventDefault, { passive: false }); | ||
| window.removeEventListener("touchmove", preventDefault, { passive: false }); | ||
| } | ||
|
|
||
| export function disableScroll() { | ||
| const wheelEvent = | ||
| "onwheel" in document.createElement("div") ? "wheel" : "mousewheel"; | ||
| window.addEventListener("DOMMouseScroll", preventDefault, false); // older FF | ||
| window.addEventListener(wheelEvent, preventDefault, { passive: false }); // modern desktop | ||
| window.addEventListener("touchmove", preventDefault, { passive: false }); // mobile | ||
| } |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,19 +1,29 @@ | ||
| import { useSearchFocus } from "@components/proview/searchFocus"; | ||
| import { Flipped } from "react-flip-toolkit"; | ||
| import styles from "./layout.module.less"; | ||
| import LOGO from "./logo"; | ||
| import RightSide from "./rightSide"; | ||
| import Search from "./search"; | ||
| import { useAppDispatch } from "@store/hooks"; | ||
| import { Link, useLocation } from "react-router-dom"; | ||
| import { useEffect, useMemo } from "react"; | ||
| import { changeLoadingCauseByUrl } from "@store/loading"; | ||
| export default function Header() { | ||
| // const { focused } = useSearchFocus(); | ||
| return ( | ||
| // <Flipped flipId={"list"} spring={"veryGentle"}> | ||
| <header className={styles["header"]}> | ||
| {/* {!focused && <LOGO />} | ||
| <Search /> | ||
| {!focused && <RightSide />} */} | ||
| <LOGO /> | ||
| </header> | ||
| // </Flipped> | ||
| const dispatch = useAppDispatch(), | ||
| location = useLocation(); | ||
| useEffect(() => { | ||
| dispatch( | ||
| changeLoadingCauseByUrl({ | ||
| stateName: | ||
| location.pathname == "/photo" ? "photoIsloading" : "videoIsLoading", | ||
| }) | ||
| ); | ||
| }, [location.pathname]); | ||
| const JSXRes = useMemo( | ||
| () => ( | ||
| <header className={styles["header"]}> | ||
| <LOGO /> | ||
| <Link to='/video'>video</Link> | ||
| <Link to='/photo'>photo</Link> | ||
| </header> | ||
| ), | ||
| [] | ||
| ); | ||
| return <>{JSXRes}</>; | ||
| } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import Masonry from "./masonry"; | ||
|
|
||
| export default function PhotoPage() { | ||
| return ( | ||
| <> | ||
| <Masonry /> | ||
| </> | ||
| ); | ||
| } |
Oops, something went wrong.