-
-
Notifications
You must be signed in to change notification settings - Fork 779
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: update data when save csb successful
Signed-off-by: Innei <i@innei.in>
- Loading branch information
Showing
7 changed files
with
59 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 17 additions & 5 deletions
22
src/components/modules/dashboard/crossbell/XLogEnabled.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,20 @@ | ||
import { lazy } from 'react' | ||
import { lazy, Suspense, useMemo } from 'react' | ||
|
||
const XLogEnableImpl = lazy(() => | ||
import('./XlogSwitch').then((mo) => ({ default: mo.XlogSwitch })), | ||
) | ||
export const XLogEnable = () => { | ||
return 'ethereum' in window ? <XLogEnableImpl /> : null | ||
return 'ethereum' in window ? <XlogSwitchLazy /> : null | ||
} | ||
|
||
const XlogSwitchLazy = () => { | ||
const Component = useMemo( | ||
() => | ||
lazy(() => | ||
import('./XlogSwitch').then((mo) => ({ default: mo.XlogSwitch })), | ||
), | ||
[], | ||
) | ||
return ( | ||
<Suspense> | ||
<Component /> | ||
</Suspense> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,5 @@ export const enum EmitKeyMap { | |
EditDataUpdate = 'editDataUpdate', | ||
|
||
Publish = 'Publish', | ||
Refetch = 'Refetch', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { EmitKeyMap } from '~/constants/keys' | ||
|
||
export class RefetchEvent extends Event { | ||
static readonly type = EmitKeyMap.Refetch | ||
constructor() { | ||
super(EmitKeyMap.Refetch) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { useEffect } from 'react' | ||
import { useForceUpdate } from 'framer-motion' | ||
|
||
import { EmitKeyMap } from '~/constants/keys' | ||
|
||
export const useRefetchData = (refetchFn: () => Promise<any>) => { | ||
const [forceUpdate, key] = useForceUpdate() | ||
useEffect(() => { | ||
const handler = () => { | ||
refetchFn().then(forceUpdate) | ||
} | ||
window.addEventListener(EmitKeyMap.Refetch, handler) | ||
return () => { | ||
window.removeEventListener(EmitKeyMap.Refetch, handler) | ||
} | ||
}, [forceUpdate, refetchFn]) | ||
|
||
return [key] as const | ||
} |