File tree 4 files changed +257
-23
lines changed
4 files changed +257
-23
lines changed Original file line number Diff line number Diff line change 10
10
"dependencies" : {
11
11
"@logseq/libs" : " ^0.0.1-alpha.10" ,
12
12
"react" : " ^17.0.0" ,
13
- "react-dom" : " ^17.0.0"
13
+ "react-dom" : " ^17.0.0" ,
14
+ "react-use" : " ^17.2.4"
14
15
},
15
16
"devDependencies" : {
16
17
"@types/react" : " ^17.0.0" ,
Original file line number Diff line number Diff line change 1
- import React , { useRef , useState } from "react" ;
2
-
3
- const useAppVisible = ( ) => {
4
- const [ visible , setVisible ] = useState ( logseq . isMainUIVisible ) ;
5
- React . useEffect ( ( ) => {
6
- const eventName = "ui:visible:changed" ;
7
- const handler = async ( { visible } : any ) => {
8
- setVisible ( visible ) ;
9
- } ;
10
- logseq . on ( eventName , handler ) ;
11
- return ( ) => {
12
- logseq . off ( eventName , handler ) ;
13
- } ;
14
- } , [ ] ) ;
15
- return visible ;
16
- } ;
1
+ import React , { useRef } from "react" ;
2
+ import { useAppVisible } from "./utils" ;
17
3
18
4
function App ( ) {
19
5
const innerRef = useRef < HTMLDivElement > ( null ) ;
20
6
const visible = useAppVisible ( ) ;
21
7
if ( visible ) {
22
8
return (
23
- < main
24
- className = "backdrop-filter backdrop-blur-md top-0 bottom-0 left-0 right-0 fixed flex items-center justify-center"
9
+ < main
10
+ className = "backdrop-filter backdrop-blur-md fixed inset-0 flex items-center justify-center"
25
11
onClick = { ( e ) => {
26
12
if ( ! innerRef . current ?. contains ( e . target as any ) ) {
27
13
window . logseq . hideMainUI ( ) ;
28
14
}
29
15
} }
30
16
>
31
17
< div ref = { innerRef } className = "text-size-2em" >
32
- Welcome to Logseq Plugins!
18
+ Welcome to [[ Logseq]] Plugins!
33
19
</ div >
34
20
</ main >
35
21
) ;
Original file line number Diff line number Diff line change
1
+ import React , { useState } from "react" ;
2
+ import { useMountedState } from "react-use" ;
3
+
4
+ export const useAppVisible = ( ) => {
5
+ const [ visible , setVisible ] = useState ( logseq . isMainUIVisible ) ;
6
+ const isMounted = useMountedState ( ) ;
7
+ React . useEffect ( ( ) => {
8
+ const eventName = "ui:visible:changed" ;
9
+ const handler = async ( { visible } : any ) => {
10
+ if ( isMounted ( ) ) {
11
+ setVisible ( visible ) ;
12
+ }
13
+ } ;
14
+ logseq . on ( eventName , handler ) ;
15
+ return ( ) => {
16
+ logseq . off ( eventName , handler ) ;
17
+ } ;
18
+ } , [ ] ) ;
19
+ return visible ;
20
+ } ;
21
+
22
+ export const useSidebarVisible = ( ) => {
23
+ const [ visible , setVisible ] = useState ( false ) ;
24
+ const isMounted = useMountedState ( ) ;
25
+ React . useEffect ( ( ) => {
26
+ logseq . App . onSidebarVisibleChanged ( ( { visible } ) => {
27
+ if ( isMounted ( ) ) {
28
+ setVisible ( visible ) ;
29
+ }
30
+ } ) ;
31
+ } , [ ] ) ;
32
+ return visible ;
33
+ } ;
You can’t perform that action at this time.
0 commit comments