import useFileDrop from "components/system/Files/FileManager/useFileDrop"; import { useProcesses } from "contexts/process"; import dynamic from "next/dynamic"; import { useMemo, useRef, useState } from "react"; import type { DefaultTheme, StyledComponent as StyledComponentType, } from "styled-components"; const StyledLoading = dynamic( () => import("components/system/Files/FileManager/StyledLoading") ); type ContainerHook = ( id: string, url: string, container: React.MutableRefObject, setLoading: React.Dispatch>, loading: boolean ) => void; type AppContainerProps = { StyledComponent: StyledComponentType<"div", DefaultTheme>; id: string; useHook: ContainerHook; }; const AppContainer: FC = ({ id, useHook, StyledComponent, children, }): JSX.Element => { const { processes: { [id]: { url: currentUrl = "" } = {} }, } = useProcesses(); const containerRef = useRef(null); const [loading, setLoading] = useState(true); const style = useMemo( () => ({ contain: "strict", visibility: loading ? "hidden" : "visible", }), [loading] ); useHook(id, currentUrl, containerRef, setLoading, loading); return ( <> {loading && } {children} ); }; export default AppContainer;