diff --git a/remix/app/components/Thingtime/SettingsMenu.tsx b/remix/app/components/Thingtime/SettingsMenu.tsx index 4371203..6823e24 100644 --- a/remix/app/components/Thingtime/SettingsMenu.tsx +++ b/remix/app/components/Thingtime/SettingsMenu.tsx @@ -1,10 +1,42 @@ import React, { useState } from "react" +import ClickAwayListener from "react-click-away-listener" import { Center, Flex, Text } from "@chakra-ui/react" import { Icon } from "../Icon/Icon" export const SettingsMenu = (props) => { const [show, setShow] = useState(false) + const hideRef = React.useRef(null) + const [opacity, setOpacity] = React.useState(props?.opacity === 0 ? 0 : 1) + + const opacityRef = React.useRef(null) + + const waitTime = 1555 + + React.useEffect(() => { + clearInterval(opacityRef?.current) + if (props?.opacity) { + setOpacity(props?.opacity) + } else { + opacityRef.current = setInterval(() => { + setOpacity(props?.opacity) + setShow(false) + }, waitTime) + } + }, [props?.opacity]) + + React.useEffect(() => { + if (show || props?.opacity) { + clearInterval(hideRef?.current) + } + }, [show, props?.opacity]) + + const maybeHide = React.useCallback(() => { + clearInterval(hideRef?.current) + hideRef.current = setTimeout(() => { + setShow(false) + }, waitTime) + }, []) const showMenu = React.useCallback(() => { setShow(true) @@ -46,117 +78,124 @@ export const SettingsMenu = (props) => { const iconSize = 10 return ( -