diff --git a/src/App.css b/src/App.css index f8b30cab..8028e7c3 100644 --- a/src/App.css +++ b/src/App.css @@ -188,16 +188,8 @@ body.webamp-loaded #webamp { line-height: 1.4em; } -.readme { - background: white; -} - .readme pre { - padding: 10px; - width: 100%; - height: 100%; white-space: pre-wrap; margin: 0; font-size: 12px; - box-sizing: border-box; } diff --git a/src/Overlay.js b/src/Overlay.js index fce23034..ac54e200 100644 --- a/src/Overlay.js +++ b/src/Overlay.js @@ -1,10 +1,118 @@ -import { connect } from "react-redux"; -import * as ActionCreators from "./redux/actionCreators"; -import BaseOverlay from "./components/BaseOverlay"; +import * as Actions from "./redux/actionCreators"; +import React, { + useEffect, + useCallback, + useLayoutEffect, + useState, +} from "react"; +import ReactDOM from "react-dom"; +import { useActionCreator } from "./hooks"; -const mapDispatchToProps = dispatch => ({ - closeModal() { - dispatch(ActionCreators.closeModal()); - } -}); -export default connect(null, mapDispatchToProps)(BaseOverlay); +function handleTouchMove(e) { + e.preventDefault(); +} + +function Overlay({ shouldAnimate, children }) { + const closeModal = useActionCreator(Actions.closeModal); + const [mounted, setMounted] = useState(); + + useLayoutEffect(() => { + const timeout = setTimeout(() => { + setMounted(true); + }); + const bodyOverflow = document.body.style.overflow; + document.body.style.overflow = "hidden"; + return () => { + document.body.style.overflow = bodyOverflow; + if (timeout != null) { + clearTimeout(timeout); + } + }; + }, []); + + const handleClick = useCallback( + (e) => { + if (e.target === e.currentTarget) { + closeModal(); + } + }, + [closeModal] + ); + + const handleKeyDown = useCallback( + (e) => { + // Esc + if (e.keyCode === 27) { + closeModal(); + } + }, + [closeModal] + ); + + useEffect(() => { + window.document.addEventListener("keydown", handleKeyDown); + window.document.addEventListener("touchmove", handleTouchMove); + return () => { + window.document.removeEventListener("keydown", handleKeyDown); + window.document.removeEventListener("touchmove", handleTouchMove); + }; + }, [handleKeyDown]); + + return ReactDOM.createPortal( +
, + window.document.body + ); +} + +export default Overlay; diff --git a/src/SkinReadme.js b/src/SkinReadme.js index f42d967f..cdf7c050 100644 --- a/src/SkinReadme.js +++ b/src/SkinReadme.js @@ -1,55 +1,47 @@ import React from "react"; -import { connect } from "react-redux"; -import * as Actions from "./redux/actionCreators"; +import { createPortal } from "react-dom"; +import { useSelector } from "react-redux"; -class SkinReadme extends React.Component { - render() { - if (this.props.focusedFile == null) { - return null; - } +function SkinReadme() { + const focusedFile = useSelector((state) => state.focusedSkinFile); + if (focusedFile == null) { + return null; + } - const { fileName, content } = this.props.focusedFile; - if (content == null) { - return null; - } - return ( + const { content } = focusedFile; + if (content == null) { + return null; + } + return createPortal( +{content}
- {content}