-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fe0e37f
commit 54b9e23
Showing
23 changed files
with
421 additions
and
43 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { ipcRenderer } from 'electron'; | ||
|
||
import { LayoutParams } from '../store'; | ||
import { LAYOUT } from '../ipc-channels'; | ||
|
||
/** | ||
* Expose functions to store layout parameters in between session | ||
*/ | ||
export const layoutService = { | ||
getLayoutParams(): LayoutParams { | ||
return ipcRenderer.sendSync(LAYOUT.GET_LAYOUT); | ||
}, | ||
|
||
setLayoutParams(lp: LayoutParams): void { | ||
return ipcRenderer.sendSync(LAYOUT.SET_LAYOUT, lp); | ||
}, | ||
|
||
getItem(s: string): string | null { | ||
return ipcRenderer.sendSync(LAYOUT.GET_LAYOUT_ITEM, s); | ||
}, | ||
|
||
setItem(s: string, v: string): void { | ||
return ipcRenderer.sendSync(LAYOUT.SET_LAYOUT_ITEM, s, v); | ||
}, | ||
}; | ||
|
||
export type LayoutService = typeof layoutService; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import ElectronStore from 'electron-store'; | ||
|
||
const store = new ElectronStore(); | ||
|
||
type PanelParams = { | ||
open: boolean; | ||
}; | ||
|
||
export type LayoutParams = { | ||
leftPanel: PanelParams; | ||
rightPanel: PanelParams; | ||
}; | ||
|
||
export const Store = { | ||
getLayoutItem(s: string) { | ||
return store.get(s); | ||
}, | ||
|
||
setLayoutItem(s: string, v: string) { | ||
store.set(s, v); | ||
}, | ||
|
||
getLayoutParams(): LayoutParams { | ||
const defaultLayoutParams = { | ||
leftPanel: { | ||
show: true, | ||
}, | ||
rightPanel: { | ||
show: true, | ||
}, | ||
}; | ||
|
||
return (store.get('layout') as LayoutParams) || defaultLayoutParams; | ||
}, | ||
|
||
setLayoutParams(lp: LayoutParams) { | ||
store.set('layout', lp); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import { useEffect, useRef } from 'react'; | ||
import { Panel, PanelGroup, PanelResizeHandle } from 'react-resizable-panels'; | ||
|
||
import { PanelState, usePanels } from '@context/panel-context'; | ||
|
||
import DeviceList from './DeviceList'; | ||
import ConfigPanel from './ConfigPanel'; | ||
import DevicePanel from './DevicePanel'; | ||
|
||
type ImperativePanelActions = { | ||
collapse: () => void; | ||
expand: () => void; | ||
}; | ||
|
||
function usePanelEffect( | ||
panelRef: React.MutableRefObject<null>, | ||
panelState: PanelState | ||
) { | ||
useEffect(() => { | ||
const { collapsed, requiresUpdate } = panelState; | ||
const ref = panelRef.current; | ||
if (ref && collapsed && requiresUpdate) { | ||
(ref as ImperativePanelActions).collapse(); | ||
} else if (ref && !collapsed && requiresUpdate) { | ||
(ref as ImperativePanelActions).expand(); | ||
} | ||
}, [panelRef, panelState]); | ||
} | ||
|
||
const { LayoutService } = window; | ||
|
||
export default function MainContent() { | ||
const { panel1State, setPanel1, panel2State, setPanel2 } = usePanels(); | ||
|
||
const deviceListPanelRef = useRef(null); | ||
const configPanelRef = useRef(null); | ||
|
||
usePanelEffect(deviceListPanelRef, panel1State); | ||
usePanelEffect(configPanelRef, panel2State); | ||
|
||
return ( | ||
<div id="main-content"> | ||
<PanelGroup | ||
direction="horizontal" | ||
className="main-content" | ||
storage={LayoutService} | ||
autoSaveId="main-content" | ||
disablePointerEventsDuringResize | ||
> | ||
<Panel | ||
minSize={25} | ||
defaultSize={25} | ||
maxSize={50} | ||
ref={deviceListPanelRef} | ||
id="device-list" | ||
onCollapse={(collapsed) => setPanel1(collapsed, false)} | ||
collapsible | ||
> | ||
<DeviceList /> | ||
</Panel> | ||
<PanelResizeHandle | ||
className="drag-handle" | ||
style={{ | ||
borderRight: '1px solid #dbd4d1', | ||
backgroundColor: '#f4f0f1', | ||
}} | ||
/> | ||
<Panel minSize={25} id="main" order={1}> | ||
<DevicePanel /> | ||
</Panel> | ||
<PanelResizeHandle | ||
className="drag-handle" | ||
style={{ | ||
borderLeft: '1px solid #dbd4d1', | ||
backgroundColor: '#f4f0f1', | ||
}} | ||
/> | ||
<Panel | ||
minSize={30} | ||
ref={configPanelRef} | ||
maxSize={50} | ||
defaultSize={25} | ||
id="history" | ||
order={2} | ||
onCollapse={(collapsed) => setPanel2(collapsed, false)} | ||
collapsible | ||
> | ||
<ConfigPanel /> | ||
</Panel> | ||
</PanelGroup> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import DrawerRightClosed from '@assets/drawer_right_closed.svg'; | ||
import DrawerRightOpen from '@assets/drawer_right_open.svg'; | ||
import DrawerLeftClosed from '@assets/drawer_left_closed.svg'; | ||
import DrawerLeftOpen from '@assets/drawer_left_open.svg'; | ||
import { usePanels } from '../../context/panel-context'; | ||
|
||
export default function DrawerToggles() { | ||
const { panel1State, setPanel1, panel2State, setPanel2 } = usePanels(); | ||
|
||
return ( | ||
<div className="drawer-toggles"> | ||
<img | ||
src={panel1State.collapsed ? DrawerLeftClosed : DrawerLeftOpen} | ||
alt={panel1State.collapsed ? 'close left drawer' : 'show left drawer'} | ||
onClick={() => setPanel1(!panel1State.collapsed, true)} | ||
height="18" | ||
role="presentation" | ||
/> | ||
<img | ||
src={panel2State.collapsed ? DrawerRightClosed : DrawerRightOpen} | ||
alt={panel2State.collapsed ? 'close right drawer' : 'show right drawer'} | ||
height={18} | ||
onClick={() => setPanel2(!panel2State.collapsed, true)} | ||
role="presentation" | ||
/> | ||
</div> | ||
); | ||
} |
Oops, something went wrong.