-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Fix] Fix broken studio ui instance (#231)
- Loading branch information
1 parent
141af31
commit 19297fd
Showing
13 changed files
with
250 additions
and
130 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
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
32 changes: 22 additions & 10 deletions
32
src/components/navbar/navbarItems/useNavbarModeToggle.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
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
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,55 @@ | ||
import { createContext, ReactNode, useCallback, useContext, useMemo, useState } from 'react'; | ||
|
||
type Mode = 'design' | 'run'; | ||
|
||
interface IAppContext { | ||
isDocumentLoaded: boolean; | ||
selectedMode: Mode; | ||
updateSelectedMode: (_: string) => void; | ||
cleanRunningTasks: () => Promise<void>; | ||
} | ||
|
||
const AppContext = createContext<IAppContext>({ | ||
isDocumentLoaded: false, | ||
selectedMode: 'run', | ||
updateSelectedMode: () => null, | ||
cleanRunningTasks: () => Promise.resolve(), | ||
}); | ||
|
||
export const useAppContext = () => { | ||
return useContext(AppContext); | ||
}; | ||
|
||
function AppProvider({ | ||
isDocumentLoaded, | ||
isAnimationPlaying, | ||
children, | ||
}: { | ||
isDocumentLoaded: boolean; | ||
isAnimationPlaying: boolean; | ||
children: ReactNode; | ||
}) { | ||
const [selectedMode, setSelectedMode] = useState<Mode>('run'); | ||
|
||
const cleanRunningTasks = useCallback(async () => { | ||
if (isAnimationPlaying) await window.StudioUISDK.animation.pause(); | ||
}, [isAnimationPlaying]); | ||
|
||
const updateSelectedMode = useCallback((val: string) => { | ||
setSelectedMode(val as Mode); | ||
}, []); | ||
|
||
const data = useMemo( | ||
() => ({ | ||
isDocumentLoaded, | ||
selectedMode, | ||
updateSelectedMode, | ||
cleanRunningTasks, | ||
}), | ||
[isDocumentLoaded, selectedMode, updateSelectedMode, cleanRunningTasks], | ||
); | ||
|
||
return <AppContext.Provider value={data}>{children}</AppContext.Provider>; | ||
} | ||
|
||
export default AppProvider; |
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
Oops, something went wrong.