Skip to content

Commit

Permalink
Add context for storing active workspacegp
Browse files Browse the repository at this point in the history
  • Loading branch information
mateuuszzzzz committed Jan 11, 2024
1 parent adbb9a1 commit 7c7f8fa
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Onyx from 'react-native-onyx';
import {PickerStateProvider} from 'react-native-picker-select';
import {SafeAreaProvider} from 'react-native-safe-area-context';
import '../wdyr';
import ActiveWorkspaceContextProvider from './components/ActiveWorkspace/ActiveWorkspaceProvider';
import ColorSchemeWrapper from './components/ColorSchemeWrapper';
import ComposeProviders from './components/ComposeProviders';
import CustomStatusBarAndBackground from './components/CustomStatusBarAndBackground';
Expand Down Expand Up @@ -69,6 +70,7 @@ function App() {
PickerStateProvider,
EnvironmentProvider,
CustomStatusBarAndBackgroundContextProvider,
ActiveWorkspaceContextProvider,
]}
>
<CustomStatusBarAndBackground />
Expand Down
11 changes: 11 additions & 0 deletions src/components/ActiveWorkspace/ActiveWorkspaceContext.tsx
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 src/components/ActiveWorkspace/ActiveWorkspaceProvider.tsx
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.

Copy link
@c3024

c3024 Jun 21, 2024

On refreshing and navigating to LHN, workspace switcher resets to all. This was fixed in Expensify#42684.


return <ActiveWorkspaceContext.Provider value={value}>{children}</ActiveWorkspaceContext.Provider>;
}

export default ActiveWorkspaceContextProvider;
9 changes: 9 additions & 0 deletions src/hooks/useActiveWorkspace.ts
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;

0 comments on commit 7c7f8fa

Please sign in to comment.