File tree 7 files changed +59
-10
lines changed
app/(dashboard)/dashboard
components/modules/dashboard/crossbell
7 files changed +59
-10
lines changed Original file line number Diff line number Diff line change @@ -31,6 +31,7 @@ import {
31
31
} from '~/components/modules/dashboard/writing/Writing'
32
32
import { LoadingButtonWrapper , StyledButton } from '~/components/ui/button'
33
33
import { PublishEvent , WriteEditEvent } from '~/events'
34
+ import { useRefetchData } from '~/hooks/biz/use-refetch-data'
34
35
import { useEventCallback } from '~/hooks/common/use-event-callback'
35
36
import { cloneDeep } from '~/lib/_'
36
37
import { dayOfYear } from '~/lib/datetime'
@@ -42,15 +43,17 @@ export default function Page() {
42
43
const search = useSearchParams ( )
43
44
const id = search . get ( 'id' )
44
45
45
- const { data, isLoading } = useQuery ( {
46
+ const { data, isLoading, refetch } = useQuery ( {
46
47
...adminQueries . note . getNote ( id ! ) ,
47
48
enabled : ! ! id ,
48
49
} )
49
50
51
+ const [ key ] = useRefetchData ( refetch )
52
+
50
53
if ( id ) {
51
54
if ( isLoading ) return < PageLoading />
52
55
53
- return < EditPage initialData = { data } />
56
+ return < EditPage initialData = { data } key = { key } />
54
57
}
55
58
return < EditPage />
56
59
}
Original file line number Diff line number Diff line change @@ -31,6 +31,7 @@ import {
31
31
} from '~/components/modules/dashboard/writing/Writing'
32
32
import { LoadingButtonWrapper , StyledButton } from '~/components/ui/button'
33
33
import { PublishEvent , WriteEditEvent } from '~/events'
34
+ import { useRefetchData } from '~/hooks/biz/use-refetch-data'
34
35
import { useEventCallback } from '~/hooks/common/use-event-callback'
35
36
import { cloneDeep } from '~/lib/_'
36
37
import { toast } from '~/lib/toast'
@@ -41,15 +42,17 @@ export default function Page() {
41
42
const search = useSearchParams ( )
42
43
const id = search . get ( 'id' )
43
44
44
- const { data, isLoading } = useQuery ( {
45
+ const { data, isLoading, refetch } = useQuery ( {
45
46
...adminQueries . post . getPost ( id ! ) ,
46
47
enabled : ! ! id ,
47
48
} )
48
49
50
+ const [ key ] = useRefetchData ( refetch )
51
+
49
52
if ( id ) {
50
53
if ( isLoading ) return < PageLoading />
51
54
52
- return < EditPage initialData = { data } />
55
+ return < EditPage initialData = { data } key = { key } />
53
56
}
54
57
return < EditPage />
55
58
}
Original file line number Diff line number Diff line change 1
- import { lazy } from 'react'
1
+ import { lazy , Suspense , useMemo } from 'react'
2
2
3
- const XLogEnableImpl = lazy ( ( ) =>
4
- import ( './XlogSwitch' ) . then ( ( mo ) => ( { default : mo . XlogSwitch } ) ) ,
5
- )
6
3
export const XLogEnable = ( ) => {
7
- return 'ethereum' in window ? < XLogEnableImpl /> : null
4
+ return 'ethereum' in window ? < XlogSwitchLazy /> : null
5
+ }
6
+
7
+ const XlogSwitchLazy = ( ) => {
8
+ const Component = useMemo (
9
+ ( ) =>
10
+ lazy ( ( ) =>
11
+ import ( './XlogSwitch' ) . then ( ( mo ) => ( { default : mo . XlogSwitch } ) ) ,
12
+ ) ,
13
+ [ ] ,
14
+ )
15
+ return (
16
+ < Suspense >
17
+ < Component />
18
+ </ Suspense >
19
+ )
8
20
}
Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ import { useAtom, useStore } from 'jotai'
5
5
import { XLogIcon } from '~/components/icons/platform/XLogIcon'
6
6
import { LabelSwitch } from '~/components/ui/switch'
7
7
import { PublishEvent } from '~/events'
8
+ import { RefetchEvent } from '~/events/refetch'
8
9
import { apiClient } from '~/lib/request'
9
10
10
11
import { syncToXlogAtom } from '../writing/atoms'
@@ -57,7 +58,9 @@ const PublishEventSubscriber = () => {
57
58
const enabled = store . get ( syncToXlogAtom )
58
59
if ( ! enabled ) return
59
60
60
- CrossBellConnector . createOrUpdate ( ev . data )
61
+ CrossBellConnector . createOrUpdate ( ev . data ) . then ( ( ) => {
62
+ window . dispatchEvent ( new RefetchEvent ( ) )
63
+ } )
61
64
} )
62
65
} , [ store ] )
63
66
Original file line number Diff line number Diff line change @@ -2,4 +2,5 @@ export const enum EmitKeyMap {
2
2
EditDataUpdate = 'editDataUpdate' ,
3
3
4
4
Publish = 'Publish' ,
5
+ Refetch = 'Refetch' ,
5
6
}
Original file line number Diff line number Diff line change
1
+ import { EmitKeyMap } from '~/constants/keys'
2
+
3
+ export class RefetchEvent extends Event {
4
+ static readonly type = EmitKeyMap . Refetch
5
+ constructor ( ) {
6
+ super ( EmitKeyMap . Refetch )
7
+ }
8
+ }
Original file line number Diff line number Diff line change
1
+ import { useEffect } from 'react'
2
+ import { useForceUpdate } from 'framer-motion'
3
+
4
+ import { EmitKeyMap } from '~/constants/keys'
5
+
6
+ export const useRefetchData = ( refetchFn : ( ) => Promise < any > ) => {
7
+ const [ forceUpdate , key ] = useForceUpdate ( )
8
+ useEffect ( ( ) => {
9
+ const handler = ( ) => {
10
+ refetchFn ( ) . then ( forceUpdate )
11
+ }
12
+ window . addEventListener ( EmitKeyMap . Refetch , handler )
13
+ return ( ) => {
14
+ window . removeEventListener ( EmitKeyMap . Refetch , handler )
15
+ }
16
+ } , [ forceUpdate , refetchFn ] )
17
+
18
+ return [ key ] as const
19
+ }
You can’t perform that action at this time.
0 commit comments