diff --git a/Eplant/EplantLayout.tsx b/Eplant/EplantLayout.tsx deleted file mode 100644 index 8c03fe4b..00000000 --- a/Eplant/EplantLayout.tsx +++ /dev/null @@ -1,84 +0,0 @@ -import { useEffect } from 'react' - -import { Box, CircularProgress, IconButton } from '@mui/material' -import { useTheme } from '@mui/material/styles' - -import { ViewContainer } from './UI/Layout/ViewContainer' -import { collapsedSidebarWidth, sidebarWidth } from './UI/Sidebar' -import FallbackView from './views/FallbackView' -import { useConfig } from './config' -import { - useActiveGeneId, - useActiveViewId, - useGeneticElements, - usePageLoad, - useSidebarState, -} from './state' -import { updateColors } from './updateColors' - -const EplantLayout = () => { - const [activeGeneId, setActiveGeneId] = useActiveGeneId() - const [activeViewId, setActiveViewId] = useActiveViewId() - const [isCollapse, setIsCollapse] = useSidebarState() - const [genes] = useGeneticElements() - const theme = useTheme() - const [globalProgress, loaded] = usePageLoad() - const config = useConfig() - useEffect(() => { - if (loaded) { - updateColors(theme) - } - }, [theme, loaded]) - - return ( - ({ - height: `calc(100% - ${theme.spacing(1)})`, - left: `${isCollapse ? collapsedSidebarWidth : sidebarWidth}px`, - right: '0px', - position: 'absolute', - marginTop: '0.5rem', - boxSizing: 'border-box', - transition: 'left 1s ease-out', - backgroundColor: theme.palette.background.paper, - })} - > - -
- {loaded ? ( - gene.id === activeGeneId) ?? null} - view={ - config.views.find( - (view) => view.id === (activeViewId ?? config.defaultView) - ) ?? FallbackView - } - setView={(view) => { - setActiveViewId(view) - }} - sx={{ - width: '100%', - height: '100%', - }} - /> - ) : ( -
- -
- )} - - - ) -} -export default EplantLayout diff --git a/Eplant/UI/Layout/ViewContainer/Topbar.tsx b/Eplant/UI/Layout/ViewContainer/Topbar.tsx index c49c0523..b7aebb20 100644 --- a/Eplant/UI/Layout/ViewContainer/Topbar.tsx +++ b/Eplant/UI/Layout/ViewContainer/Topbar.tsx @@ -5,7 +5,7 @@ import { queryClient } from '@eplant/main' import { useActiveGeneId, useActiveViewId } from '@eplant/state' import { useURLState } from '@eplant/state/URLStateProvider' import downloadFile from '@eplant/util/downloadFile' -import { ActionsPanel } from '@eplant/util/stateUtils/ActionsPanel' +import { ActionsPanel } from '@eplant/util/Actions/ActionsPanel' import { View } from '@eplant/View' import { AppBar, diff --git a/Eplant/UI/Layout/ViewContainer/ViewOptions.tsx b/Eplant/UI/Layout/ViewContainer/ViewOptions.tsx deleted file mode 100644 index ffeaa207..00000000 --- a/Eplant/UI/Layout/ViewContainer/ViewOptions.tsx +++ /dev/null @@ -1,53 +0,0 @@ -import { useTransition } from 'react' - -import GeneticElement from '@eplant/GeneticElement' -import Dropdown from '@eplant/UI/Dropdown' -import { View, ViewDispatch } from '@eplant/View' -import { MenuItem } from '@mui/material' - -export default function ViewOptions({ - view, - gene, - loading, - state, - dispatch, -}: { - view: View - gene: GeneticElement | null - loading: boolean - state?: S - dispatch: ViewDispatch -}) { - const [transitioning, startTransition] = useTransition() - if (!view.actions) return <> - return ( - <> - ( - startTransition(() => dispatch(a.action))} - > - {state ? ( - - ) : ( - '...' - )} - - ))} - > - View options - - - ) -} diff --git a/Eplant/UI/Layout/ViewContainer/types.ts b/Eplant/UI/Layout/ViewContainer/types.ts index 41a879bb..4e39b369 100644 --- a/Eplant/UI/Layout/ViewContainer/types.ts +++ b/Eplant/UI/Layout/ViewContainer/types.ts @@ -1,5 +1,5 @@ import GeneticElement from '@eplant/GeneticElement' -import { StateAction } from '@eplant/util/stateUtils' +import { StateAction } from '@eplant/View' export type ViewContext = { geneticElement: GeneticElement | null diff --git a/Eplant/UI/LeftNav/Collections.tsx b/Eplant/UI/LeftNav/Collections.tsx index 0ef3b720..e8fe75c7 100644 --- a/Eplant/UI/LeftNav/Collections.tsx +++ b/Eplant/UI/LeftNav/Collections.tsx @@ -436,7 +436,6 @@ export function Collections(props: { }} deleteGene={(g) => { deleteGene(g) - setActiveGeneId('') }} setOpen={() => { setCollections((collections) => { diff --git a/Eplant/state/index.tsx b/Eplant/state/index.tsx index 5ee815e9..93306645 100644 --- a/Eplant/state/index.tsx +++ b/Eplant/state/index.tsx @@ -216,40 +216,3 @@ export const useActiveId = () => useAtom(activeIdAtom) export const sidebarAtom = atom(false) export const useSidebarState = () => useAtom(sidebarAtom) export const useSetSidebarState = () => useSetAtom(sidebarAtom) - -// export function getPaneName(pane: Panes[string]) { -// return `${pane.activeGene ? pane.activeGene + ' - ' : ''}${pane.view}` -// } - -// export const modelAtom = atomWithOptionalStorage( -// 'flexlayout-model', -// FlexLayout.Model.fromJson({ -// global: { -// tabSetTabStripHeight: 48, -// tabEnableRename: false, -// tabEnableClose: false, -// tabSetEnableMaximize: false, -// }, -// borders: [], -// layout: { -// type: 'row', -// weight: 100, -// children: [ -// { -// type: 'tabset', -// active: true, -// children: [ -// { -// type: 'tab', -// id: 'default', -// }, -// ], -// }, -// ], -// }, -// }), -// (model) => JSON.stringify(model.toJson()), -// (model) => FlexLayout.Model.fromJson(JSON.parse(model)) -// ) -// export const useModel = () => useAtom(modelAtom) -// export const useSetModel = () => useSetAtom(modelAtom) diff --git a/Eplant/util/stateUtils/ActionsPanel.tsx b/Eplant/util/Actions/ActionsPanel.tsx similarity index 100% rename from Eplant/util/stateUtils/ActionsPanel.tsx rename to Eplant/util/Actions/ActionsPanel.tsx diff --git a/Eplant/util/hook-menu/index.tsx b/Eplant/util/hook-menu/index.tsx deleted file mode 100644 index 8800fb57..00000000 --- a/Eplant/util/hook-menu/index.tsx +++ /dev/null @@ -1,100 +0,0 @@ -import { - Context, - createContext, - Dispatch, - PropsWithChildren, - useContext, - useEffect, - useId, - useReducer, -} from 'react' - -type Entries = { - idOrdering: string[] - entries: { - [id: string]: Entry - } -} -type HookMenuAction = - | { type: 'add'; entry: Entry; id: string } - | { type: 'remove'; id: string } - -type HookMenuContextValue = [ - Entries, - Dispatch>, -] -/** - * Generates a list of entries by calling a hook in order. - * Used to generate action menus for views that render somewhere else, - * while allowing the user to put callbacks in the view's render method. - */ -export default class HookMenu { - private context: Context> - constructor() { - this.context = createContext>([ - { idOrdering: [], entries: {} }, - (a) => a, - ]) - } - /** - * Generates a context provider for the HookMenu. All components that use entries must be within this root. - * @param props - Props containing the children of this hook menu - * @returns - */ - Root(props: PropsWithChildren) { - const [value, dispatch] = useReducer(this.reducer, { - idOrdering: [], - entries: {}, - }) - return ( - - {props.children} - - ) - } - - /** - * @returns The entries in the HookMenu - */ - useEntries() { - const val = useContext(this.context)[0] - return val.idOrdering - .map((id) => val.entries[id]) - .filter((x) => x) as EntryType[] - } - - /** - * @param entry - The entry to add to the HookMenu - */ - useEntry(entry: EntryType) { - const [, dispatch] = useContext(this.context) - const id = useId() - useEffect(() => { - dispatch({ type: 'add', entry, id }) - return () => dispatch({ type: 'remove', id }) - }, [entry, id]) - } - - private reducer( - state: Entries, - action: HookMenuAction - ) { - const { [action.id]: old, ...rest } = state.entries - switch (action.type) { - case 'add': - return { - idOrdering: state.idOrdering.includes(action.id) - ? state.idOrdering - : [...state.idOrdering, action.id], - entries: { ...state.entries, [action.id]: action.entry }, - } - case 'remove': - return { - idOrdering: state.idOrdering, - entries: rest, - } - default: - return state - } - } -} diff --git a/Eplant/util/router/index.ts b/Eplant/util/router/index.ts deleted file mode 100644 index 2b60fae2..00000000 --- a/Eplant/util/router/index.ts +++ /dev/null @@ -1,13 +0,0 @@ -export const flattenState = ( - obj: { [key: string]: any }, - res: { [key: string]: any } = {} -) => { - for (const key in obj) { - if (typeof obj[key] === 'object' && obj[key] !== null) { - flattenState(obj[key], res) - } else { - res[key] = obj[key] - } - } - return res -} diff --git a/Eplant/views/CellEFP/CellEFP.tsx b/Eplant/views/CellEFP/CellEFP.tsx index 6b6ddff2..31cef6f2 100644 --- a/Eplant/views/CellEFP/CellEFP.tsx +++ b/Eplant/views/CellEFP/CellEFP.tsx @@ -18,7 +18,6 @@ import { CellEFPViewerData, CellEFPViewerState, } from './types' -import CellEFP from '.' export const CellEFPView = () => { const { geneticElement, setIsLoading, setLoadAmount, setActiveActions } = @@ -43,7 +42,7 @@ export const CellEFPView = () => { useEffect(() => { setIsLoading(isLoading) - }, [isLoading, setIsLoading]) + }, [isLoading]) const efp = useMemo(() => { const Component = CellEFPDataObject.component diff --git a/Eplant/views/DebugView/index.tsx b/Eplant/views/DebugView/index.tsx deleted file mode 100644 index de995eb6..00000000 --- a/Eplant/views/DebugView/index.tsx +++ /dev/null @@ -1,91 +0,0 @@ -import { useActiveGeneId, useActiveViewId } from '@eplant/state' -import { viewDataStorage, viewStateStorage } from '@eplant/View/viewData' -import { BugReportOutlined } from '@mui/icons-material' -import { - Button, - Table, - TableBody, - TableCell, - TableHead, - TableRow, - Typography, -} from '@mui/material' - -import { View } from '../../View' - -type DebugViewState = { - testToggle: boolean -} - -type DebugViewAction = { type: 'test-toggle' } - -const DebugView: View = { - name: 'Debug view', - getInitialState: () => ({ - testToggle: false, - }), - component: (props) => { - const [activeViewId, setActiveViewId] = useActiveViewId() - const [activeGeneId, setActiveGeneId] = useActiveGeneId() - return ( -
- - Debug view for {props.geneticElement?.id} - - - - - Key - Value - - - - - Toggle value - {props.state.testToggle ? 'true' : 'false'} - - - {activeViewId} - - - Gene ID - {activeGeneId} - - -
- -
- ) - }, - getInitialData: async () => null, - reducer: (state, action) => { - switch (action.type) { - case 'test-toggle': - return { - ...state, - testToggle: !state.testToggle, - } - default: - return state - } - }, - actions: [ - { - action: { type: 'test-toggle' }, - render(props) { - return <>{props.state.testToggle ? 'Turn off' : 'Turn on'} - }, - }, - ], - id: 'debug-view', - icon: () => , -} - -export default DebugView diff --git a/Eplant/views/GeneInfoView/ViewButton.tsx b/Eplant/views/GeneInfoView/ViewButton.tsx index f2e87673..80074a40 100644 --- a/Eplant/views/GeneInfoView/ViewButton.tsx +++ b/Eplant/views/GeneInfoView/ViewButton.tsx @@ -1,7 +1,6 @@ import styled from '@emotion/styled' import GeneticElement from '@eplant/GeneticElement' import { View } from '@eplant/View' -import { useViewData } from '@eplant/View/viewData' import { Box, Button, ButtonProps, LinearProgress } from '@mui/material' export const ViewButton = styled(function ViewButton({ diff --git a/Eplant/views/eFP/EFPPreview.tsx b/Eplant/views/eFP/EFPPreview.tsx index fd335d7a..48514175 100644 --- a/Eplant/views/eFP/EFPPreview.tsx +++ b/Eplant/views/eFP/EFPPreview.tsx @@ -76,7 +76,6 @@ export default function EFPPreview({ maskingEnabled: maskingEnabled, }} geneticElement={gene} - dispatch={() => {}} />