forked from Expensify/App
-
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.
Add context for storing active workspacegp
- Loading branch information
1 parent
adbb9a1
commit 7c7f8fa
Showing
4 changed files
with
39 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import {createContext} from 'react'; | ||
|
||
type ActiveWorkspaceContextType = { | ||
activeWorkspaceID?: string; | ||
setActiveWorkspaceID: (activeWorkspaceID?: string) => void; | ||
} | ||
|
||
const ActiveWorkspaceContext = createContext<ActiveWorkspaceContextType>({activeWorkspaceID: undefined, setActiveWorkspaceID: () => undefined}); | ||
|
||
export default ActiveWorkspaceContext; | ||
export {type ActiveWorkspaceContextType}; |
17 changes: 17 additions & 0 deletions
17
src/components/ActiveWorkspace/ActiveWorkspaceProvider.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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import React, {useMemo, useState} from 'react'; | ||
import ActiveWorkspaceContext from './ActiveWorkspaceContext'; | ||
|
||
function ActiveWorkspaceContextProvider({children}: React.PropsWithChildren) { | ||
const [activeWorkspaceID, setActiveWorkspaceID] = useState<string | undefined>(undefined); | ||
|
||
const value = useMemo( | ||
() => ({ | ||
activeWorkspaceID, | ||
setActiveWorkspaceID, | ||
}), [activeWorkspaceID] | ||
) | ||
This comment has been minimized.
Sorry, something went wrong. |
||
|
||
return <ActiveWorkspaceContext.Provider value={value}>{children}</ActiveWorkspaceContext.Provider>; | ||
} | ||
|
||
export default ActiveWorkspaceContextProvider; |
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,9 @@ | ||
import {useContext} from 'react'; | ||
import ActiveWorkspaceContext from '@components/ActiveWorkspace/ActiveWorkspaceContext'; | ||
import type { ActiveWorkspaceContextType } from '@components/ActiveWorkspace/ActiveWorkspaceContext'; | ||
|
||
function useActiveWorkspace(): ActiveWorkspaceContextType { | ||
return useContext(ActiveWorkspaceContext); | ||
} | ||
|
||
export default useActiveWorkspace; |
On refreshing and navigating to LHN, workspace switcher resets to all. This was fixed in Expensify#42684.