import { observer } from "mobx-react"; import { FC, useEffect, useRef, useState } from "react"; import { Trans } from "react-i18next"; import { useTheme } from "styled-components"; import Box from "../Styled/Box"; import { RawButton } from "../Styled/Button"; import Icon, { StyledIcon } from "../Styled/Icon"; import Text, { TextSpan } from "../Styled/Text"; import { useViewState } from "./Context"; interface DragDropNotificationProps { uploadedFiles: readonly string[]; } const DragDropNotification: FC = observer( ({ uploadedFiles }) => { const theme = useTheme(); const viewState = useViewState(); const [showNotification, setShowNotification] = useState(false); const notificationTimeoutRef = useRef | null>( null ); useEffect(() => { if (notificationTimeoutRef.current) { clearTimeout(notificationTimeoutRef.current); } // show notification, restart timer setShowNotification(true); // initialise new time out notificationTimeoutRef.current = setTimeout(() => { setShowNotification(false); }, 5000); return () => { if (notificationTimeoutRef.current) { clearTimeout(notificationTimeoutRef.current); } }; }, [uploadedFiles]); const handleHover = () => { // reset timer on hover if (notificationTimeoutRef.current) { clearTimeout(notificationTimeoutRef.current); } }; const handleMouseLeave = () => { notificationTimeoutRef.current = setTimeout(() => { setShowNotification(false); }, 4000); }; const handleClick = () => { viewState.openUserData(); }; const fileNames = uploadedFiles.join(","); return ( 0 && `right: 100px;`}; `} onMouseEnter={handleHover} onMouseLeave={handleMouseLeave} onClick={handleClick} > {/* @ts-expect-error i18next won't properly interpolate text if not in double brackets({{ }}) */} "{{ fileNames }}" {{ count: uploadedFiles.length }} been added to{" "} My data ); } ); DragDropNotification.displayName = "DragDropNotification"; export default DragDropNotification;