[ide-react] Notify about unsaved changes (#16163)

* Notify about unsaved changes
* Move system message components and types to shared folder
* Add system messages component

GitOrigin-RevId: ab81a24888847bd9a8a390fd1af6b58f471f7a4b
This commit is contained in:
Alf Eaton
2023-12-15 09:03:27 +00:00
committed by Copybot
parent a074054cc9
commit 8dbf2b64f8
21 changed files with 251 additions and 77 deletions
@@ -12,7 +12,6 @@ import GenericMessageModal, {
import OutOfSyncModal, {
OutOfSyncModalProps,
} from '@/features/ide-react/components/modals/out-of-sync-modal'
import LockEditorMessageModal from '@/features/ide-react/components/modals/lock-editor-message-modal'
type ModalsContextValue = {
genericModalVisible: boolean
@@ -23,7 +22,6 @@ type ModalsContextValue = {
showOutOfSyncModal: (
editorContent: OutOfSyncModalProps['editorContent']
) => void
showLockEditorMessageModal: (delay: number) => void
}
const ModalsContext = createContext<ModalsContextValue | undefined>(undefined)
@@ -39,12 +37,6 @@ export const ModalsContextProvider: FC = ({ children }) => {
editorContent: '',
})
const [shouldShowLockEditorModal, setShouldShowLockEditorModal] =
useState(false)
const [lockEditorModalData, setLockEditorModalData] = useState({
delay: 0,
})
const handleHideGenericModal = useCallback(() => {
setShowGenericModal(false)
}, [])
@@ -69,24 +61,13 @@ export const ModalsContextProvider: FC = ({ children }) => {
setShouldShowOutOfSyncModal(true)
}, [])
const showLockEditorMessageModal = useCallback((delay: number) => {
setLockEditorModalData({ delay })
setShouldShowLockEditorModal(true)
}, [])
const value = useMemo<ModalsContextValue>(
() => ({
showGenericMessageModal,
genericModalVisible: showGenericModal,
showOutOfSyncModal,
showLockEditorMessageModal,
}),
[
showGenericMessageModal,
showGenericModal,
showOutOfSyncModal,
showLockEditorMessageModal,
]
[showGenericMessageModal, showGenericModal, showOutOfSyncModal]
)
return (
@@ -102,10 +83,6 @@ export const ModalsContextProvider: FC = ({ children }) => {
show={shouldShowOutOfSyncModal}
onHide={handleHideOutOfSyncModal}
/>
<LockEditorMessageModal
{...lockEditorModalData}
show={shouldShowLockEditorModal}
/>
</ModalsContext.Provider>
)
}