import { useEffect , useState } from 'react' ; import { useAppDispatch } from 'store/hooks' ; import { saveForm } from 'store/slices/story' ; import useSaveAs from './useSaveAs' ; import useFormContext from 'hooks/useFormContext' ; export default function useIPCListeners ( ) { const [ loading , setLoading ] = useState ( false ) ; const saveAs = useSaveAs ( ) ; const dispatch = useAppDispatch ( ) ; const { save , formState : { isDirty } , } = useFormContext ( ) ; useEffect ( ( ) => { window . electron . onSaveAsMenuClick ( ( ) => { saveAs ( ) ; } , function onSaved ( event , args ) { console . log ( 'completed' , args ) ; } ) ; } , [ saveAs ] ) ; useEffect ( ( ) => { window . electron . onOpenFile ( ( event , state ) => { dispatch ( saveForm ( state . story ) ) ; } ) ; } , [ dispatch ] ) ; useEffect ( ( ) => { window . electron . onSave ( save ) ; } , [ save ] ) ; useEffect ( ( ) => { window . electron . toggleSave ( isDirty ) ; } , [ isDirty ] ) ; useEffect ( ( ) => { window . electron . onExport ( ( ) => window . electron . exportAsZip ( ) ) ; } , [ ] ) ; useEffect ( ( ) => { window . electron . onPreview ( ( ) => window . electron . openPreview ( ) ) ; } , [ ] ) ; useEffect ( ( ) => { window . electron . onLoading ( ( loading ) => setLoading ( loading ) ) ; } , [ ] ) ; return { loading } ; }