import React , { useState } from "react" ; import { useMountedState } from "react-use" ; export const useAppVisible = ( ) => { const [ visible , setVisible ] = useState ( logseq . isMainUIVisible ) ; const isMounted = useMountedState ( ) ; React . useEffect ( ( ) => { const eventName = "ui:visible:changed" ; const handler = async ( { visible } ) => { if ( isMounted ( ) ) { setVisible ( visible ) ; } } ; logseq . on ( eventName , handler ) ; return ( ) => { logseq . off ( eventName , handler ) ; } ; } , [ ] ) ; return visible ; } ; export const useSidebarVisible = ( ) => { const [ visible , setVisible ] = useState ( false ) ; const isMounted = useMountedState ( ) ; React . useEffect ( ( ) => { logseq . App . onSidebarVisibleChanged ( ( { visible } ) => { if ( isMounted ( ) ) { setVisible ( visible ) ; } } ) ; } , [ ] ) ; return visible ; } ;