diff --git a/src/components/AutoLoader.tsx b/src/components/AutoLoader.tsx deleted file mode 100644 index e6c4b2f..0000000 --- a/src/components/AutoLoader.tsx +++ /dev/null @@ -1,27 +0,0 @@ -import { WebSource } from 'filelist-utils'; -import { memo, ReactNode, useEffect } from 'react'; - -import useFileLoader from '../hooks/useFileLoader'; -import useLog from '../hooks/useLog'; - -interface AutoLoaderProps { - webSource?: WebSource; - children: ReactNode; -} - -function AutoLoader({ children, webSource }: AutoLoaderProps) { - const { handleWebSource } = useFileLoader(); - const { logger } = useLog(); - - useEffect(() => { - if (webSource === undefined) return; - - handleWebSource(webSource).catch((error) => { - logger.error(`Error while loading websource: ${error.message}`); - }); - }, [handleWebSource, logger, webSource]); - - return children; -} - -export default memo(AutoLoader); diff --git a/src/components/PixeliumApp.tsx b/src/components/PixeliumApp.tsx new file mode 100644 index 0000000..7ddfcf2 --- /dev/null +++ b/src/components/PixeliumApp.tsx @@ -0,0 +1,59 @@ +import styled from '@emotion/styled'; +import { memo, useRef } from 'react'; +import { SplitPane, Toolbar } from 'react-science/ui'; + +import CenterPanel from './layout/CenterPanel'; +import Header from './layout/Header'; +import Sidebar from './layout/Sidebar'; +import ModalContainer from './modal/ModalContainer'; +import ExportTool from './tool/ExportTool'; +import GreyTool from './tool/FilterTool'; +import GeometryTool from './tool/GeometryTool'; +import ImportTool from './tool/ImportTool'; +import MaskTool from './tool/MaskTool'; +import MorphologyTool from './tool/MorphologyTool'; +import ROITool from './tool/ROITool'; + +const PixeliumStyle = styled.div` + width: 100%; + height: 100%; + background-color: white; + display: flex; + flex-direction: column; +`; + +const PixeliumMainStyle = styled.div` + display: flex; + flex-direction: row; + height: 100%; + overflow: hidden; +`; + +function PixeliumApp() { + // Refs + const rootRef = useRef(null); + + return ( + +
+ + + + + + + + + + + + + + + + + + ); +} + +export default memo(PixeliumApp); diff --git a/src/components/Pixelium.tsx b/src/components/PixeliumProvider.tsx similarity index 61% rename from src/components/Pixelium.tsx rename to src/components/PixeliumProvider.tsx index f02a024..c49b4b4 100644 --- a/src/components/Pixelium.tsx +++ b/src/components/PixeliumProvider.tsx @@ -1,9 +1,14 @@ -import styled from '@emotion/styled'; -import { WebSource } from 'filelist-utils'; -import { memo, useCallback, useMemo, useReducer, useRef } from 'react'; +import { + memo, + ReactNode, + useCallback, + useMemo, + useReducer, + useRef, +} from 'react'; import { KbsProvider } from 'react-kbs'; import { RoiProvider } from 'react-roi'; -import { RootLayout, SplitPane, Toolbar } from 'react-science/ui'; +import { RootLayout } from 'react-science/ui'; import useViewDispatch from '../hooks/useViewDispatch'; import { @@ -23,7 +28,6 @@ import { ViewState, } from '../state/view/ViewReducer'; -import AutoLoader from './AutoLoader'; import { AnnotationsProvider } from './context/AnnotationsContext'; import { DataProvider } from './context/DataContext'; import { DispatchProvider } from './context/DispatchContext'; @@ -33,42 +37,22 @@ import { PreferencesProvider } from './context/PreferencesContext'; import { initialROIState, ROIProvider, ROIReducer } from './context/ROIContext'; import { RootProvider } from './context/RootContext'; import { ViewProvider } from './context/ViewContext'; -import CenterPanel from './layout/CenterPanel'; -import Header from './layout/Header'; -import Sidebar from './layout/Sidebar'; -import ModalContainer from './modal/ModalContainer'; -import ExportTool from './tool/ExportTool'; -import GreyTool from './tool/FilterTool'; -import GeometryTool from './tool/GeometryTool'; -import ImportTool from './tool/ImportTool'; -import MaskTool from './tool/MaskTool'; -import MorphologyTool from './tool/MorphologyTool'; -import ROITool from './tool/ROITool'; - -const PixeliumStyle = styled.div` - width: 100%; - height: 100%; - background-color: white; - display: flex; - flex-direction: column; -`; interface PixeliumProps { data?: DataState; preferences?: PreferencesState; view?: ViewState; - webSource?: WebSource; + children: ReactNode; } -const PixeliumMainStyle = styled.div` - display: flex; - flex-direction: row; - height: 100%; - overflow: hidden; -`; - -function Pixelium({ data, preferences, view, webSource }: PixeliumProps) { +function PixeliumProvider({ + data, + preferences, + view, + children, +}: PixeliumProps) { const viewDispatch = useViewDispatch(); + // Refs const rootRef = useRef(null); @@ -149,33 +133,7 @@ function Pixelium({ data, preferences, view, webSource }: PixeliumProps) { }} onAfterZoomChange={setPanZoom} > - - - -
- - - - - - - - - - - - - - - - - - - + {children} @@ -190,4 +148,4 @@ function Pixelium({ data, preferences, view, webSource }: PixeliumProps) { ); } -export default memo(Pixelium); +export default memo(PixeliumProvider); diff --git a/src/demo/Sidebar.tsx b/src/demo/Sidebar.tsx index 201120b..02215c1 100644 --- a/src/demo/Sidebar.tsx +++ b/src/demo/Sidebar.tsx @@ -4,6 +4,9 @@ import ky from 'ky'; import { Fragment, memo, useEffect, useState } from 'react'; import { Button } from 'react-science/ui'; +import useFileLoader from '../hooks/useFileLoader'; +import useLog from '../hooks/useLog'; + const StyledSidebar = styled.div` display: flex; flex-direction: column; @@ -50,18 +53,15 @@ interface TocResponse { }[]; } -interface SidebarProps { - setWebSource: (webSource: WebSource) => void; -} +function Sidebar() { + const { handleWebSource } = useFileLoader(); + const { logger } = useLog(); -function Sidebar({ setWebSource }: SidebarProps) { const [toc, setToC] = useState({ title: '', sections: [], }); - const [selectedSource, setSelectedSource] = useState(); - useEffect(() => { ky.get('https://image-js.github.io/image-dataset-demo/toc.json') .json() @@ -72,12 +72,6 @@ function Sidebar({ setWebSource }: SidebarProps) { }); }, []); - useEffect(() => { - if (selectedSource) { - setWebSource(selectedSource); - } - }, [selectedSource, setWebSource]); - return (

Pixelium

@@ -91,7 +85,11 @@ function Sidebar({ setWebSource }: SidebarProps) {