Skip to content

Commit

Permalink
prepare for global DialogContext
Browse files Browse the repository at this point in the history
  • Loading branch information
andreas committed Dec 5, 2024
1 parent b03d8e6 commit 662914e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 10 deletions.
37 changes: 28 additions & 9 deletions viewer/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import WarningPage from './gui/WarningPage.jsx';
import ViewPage from './gui/ViewPage.jsx';
import AddonConfigPage from './gui/AddOnConfigPage.jsx';
import ImporterPage from "./gui/ImporterPage";
import OverlayDialog, {GlobalDialogDisplay} from './components/OverlayDialog.jsx';
import OverlayDialog, {DialogContext, GlobalDialogDisplay, useDialog} from './components/OverlayDialog.jsx';
import globalStore from './util/globalstore.jsx';
import Requests from './util/requests.js';
import SoundHandler from './components/SoundHandler.jsx';
Expand Down Expand Up @@ -162,6 +162,30 @@ const ButtonSizer=(props)=>{
let lastError={
};

const MainBody = ({location, options, history, nightMode}) => {
const [DialogDisplay, setDialog] = useDialog();
return (
<DialogContext
showDialog={setDialog}
>
<DialogDisplay/>
<DynamicRouter
storeKeys={{
sequence: keys.gui.global.propertySequence,
dimensions: keys.gui.global.windowDimensions,
dim: keys.gui.global.dimActive,
isEditing: keys.gui.global.layoutEditing,
...keys.gui.capabilities
}}
location={location}
options={options}
history={history}
nightMode={nightMode}
/>
</DialogContext>
)
};

class App extends React.Component {
appRef=createRef();
constructor(props) {
Expand Down Expand Up @@ -476,6 +500,7 @@ class App extends React.Component {
let layoutClass=(this.props.layoutName||"").replace(/[^0-9a-zA-Z]/g,'_');
appClass+=" "+layoutClass;
if (this.props.smallDisplay) appClass+=" smallDisplay";
if (this.props.nightMode) appClass+=" nightMode";
let location=this.leftHistoryState.getValue('location');
if (location !== "warningpage") {
if (! this.titleSet) {
Expand All @@ -492,20 +517,14 @@ class App extends React.Component {
style={{fontSize: this.props.fontSize+"px"}}
tabIndex="0"
>
<DynamicRouter
storeKeys={{
sequence: keys.gui.global.propertySequence,
dimensions: keys.gui.global.windowDimensions,
dim: keys.gui.global.dimActive,
isEditing:keys.gui.global.layoutEditing,
...keys.gui.capabilities}}
<MainBody
location={location}
options={this.leftHistoryState.getValue('options')}
history={this.history}
nightMode={this.props.nightMode}
/>
<GlobalDialogDisplay
className={this.props.nightMode?"nightMode":""}/>
/>
{ ! (avnav.android || globalStore.getData(keys.gui.global.preventAlarms)) && globalStore.getData(keys.properties.localAlarmSound) ?<DynamicSound
storeKeys={alarmStoreKeys}
updateFunction={computeAlarmSound}
Expand Down
2 changes: 1 addition & 1 deletion viewer/components/OverlayDialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ const DialogContextImpl=createContext({
zIndex: DIALOG_Z
});
export const useDialogContext=()=>useContext(DialogContextImpl);
const DialogContext=({closeDialog,showDialog,zIndex,children})=>{
export const DialogContext=({closeDialog,showDialog,zIndex,children})=>{
return <DialogContextImpl.Provider value={{
closeDialog:closeDialog?closeDialog:()=>{},
showDialog: showDialog?showDialog:()=>{},
Expand Down

0 comments on commit 662914e

Please sign in to comment.