-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Used ModalProvider for unsaved changes dialog
- Loading branch information
1 parent
ed2b253
commit ab4422b
Showing
7 changed files
with
155 additions
and
179 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,22 +1,47 @@ | ||
import React from 'react'; | ||
import React, { useEffect, useState } from 'react'; | ||
import { Provider } from 'react-redux'; | ||
import { ConnectedRouter } from 'connected-react-router'; | ||
import { hot } from 'react-hot-loader/root'; | ||
import { History } from 'history'; | ||
import { Store } from '../store'; | ||
import { CssBaseline, ThemeProvider, useTheme } from '@material-ui/core'; | ||
import { remote } from 'electron'; | ||
import { AnyAction, EnhancedStore } from '@reduxjs/toolkit'; | ||
import Routes from '../Routes'; | ||
import ModalProvider from '../dialogs/ModalProvider'; | ||
import createTheme from '../theme'; | ||
|
||
type Props = { | ||
store: Store; | ||
store: EnhancedStore<any, AnyAction, any[]>; | ||
history: History; | ||
}; | ||
|
||
const Root = ({ store, history }: Props) => ( | ||
<Provider store={store}> | ||
<ConnectedRouter history={history}> | ||
<Routes /> | ||
</ConnectedRouter> | ||
</Provider> | ||
); | ||
const Root = ({ store, history }: Props) => { | ||
const theme = useTheme(); | ||
const [, setCurrentTheme] = useState(createTheme(theme)); | ||
|
||
useEffect(() => { | ||
const setTheme = () => { | ||
// Does nothing but required for force reload | ||
setCurrentTheme(createTheme(theme)); | ||
}; | ||
remote.nativeTheme.on('updated', setTheme); | ||
return () => { | ||
remote.nativeTheme.removeListener('updated', setTheme); | ||
}; | ||
}, [theme]); | ||
|
||
return ( | ||
<Provider store={store}> | ||
<ThemeProvider theme={createTheme(theme)}> | ||
<CssBaseline /> | ||
<ModalProvider> | ||
<ConnectedRouter history={history}> | ||
<Routes /> | ||
</ConnectedRouter> | ||
</ModalProvider> | ||
</ThemeProvider> | ||
</Provider> | ||
); | ||
}; | ||
|
||
export default hot(Root); |
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,20 @@ | ||
import { workspaceSetPath } from '../features/workspace/workspaceSlice'; | ||
import { reloadState, save } from '../utils/FileAccess'; | ||
|
||
const UnsavedChangesDialog = (newFilePath) => { | ||
return { | ||
title: 'Unsaved changes', | ||
text: 'Do you want to save your changes, before loading a new file?', | ||
onConfirm: (dispatch) => { | ||
dispatch(save()); | ||
dispatch(workspaceSetPath(newFilePath)); | ||
dispatch(reloadState()); | ||
}, | ||
onReject: (dispatch) => { | ||
dispatch(workspaceSetPath(newFilePath)); | ||
dispatch(reloadState()); | ||
}, | ||
}; | ||
}; | ||
|
||
export default UnsavedChangesDialog; |
Oops, something went wrong.