Skip to content

Commit

Permalink
Add context to the layout component
Browse files Browse the repository at this point in the history
  • Loading branch information
Jake McCoy - New committed May 9, 2024
1 parent 46bca45 commit 527c1fc
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 97 deletions.
87 changes: 45 additions & 42 deletions app/_layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { useEffect } from "react";

import { useColorScheme } from "@/components/useColorScheme";
import { SB_COLOR_SCHEME } from "@/constants";
import { UserContextProvider } from "@/contextManager";

export {
// Catch any errors thrown by the Layout component.
Expand Down Expand Up @@ -54,48 +55,50 @@ function RootLayoutNav() {

return (
<ThemeProvider value={colorScheme === "dark" ? DarkTheme : DefaultTheme}>
<Stack>
<Stack.Screen name="(tabs)" options={{ headerShown: false }} />
<Stack.Screen
name="checkout"
options={{
title: "Checkout",
headerTintColor: SB_COLOR_SCHEME.SB_PRIMARY,
headerBackTitle: "Back",
contentStyle: {
backgroundColor: "white",
},
}}
/>
<Stack.Screen
name="PaymentMethod"
options={{
title: "Payment",
headerTintColor: SB_COLOR_SCHEME.SB_PRIMARY,
headerBackTitle: "Back",
contentStyle: {
backgroundColor: "white",
},
}}
/>
<Stack.Screen
name="delivery"
options={{
title: "Delivery",
headerTintColor: SB_COLOR_SCHEME.SB_PRIMARY,
headerBackVisible: false,
gestureEnabled: false,
contentStyle: {
backgroundColor: "white",
},
}}
/>
<Stack.Screen name="modal" options={{ presentation: 'modal' }} />
<Stack.Screen
name="success"
options={{ presentation: "modal", headerShown: false }}
/>
</Stack>
<UserContextProvider>
<Stack>
<Stack.Screen name="(tabs)" options={{ headerShown: false }} />
<Stack.Screen
name="checkout"
options={{
title: "Checkout",
headerTintColor: SB_COLOR_SCHEME.SB_PRIMARY,
headerBackTitle: "Back",
contentStyle: {
backgroundColor: "white",
},
}}
/>
<Stack.Screen
name="PaymentMethod"
options={{
title: "Payment",
headerTintColor: SB_COLOR_SCHEME.SB_PRIMARY,
headerBackTitle: "Back",
contentStyle: {
backgroundColor: "white",
},
}}
/>
<Stack.Screen
name="delivery"
options={{
title: "Delivery",
headerTintColor: SB_COLOR_SCHEME.SB_PRIMARY,
headerBackVisible: false,
gestureEnabled: false,
contentStyle: {
backgroundColor: "white",
},
}}
/>
<Stack.Screen name="modal" options={{ presentation: "modal" }} />
<Stack.Screen
name="success"
options={{ presentation: "modal", headerShown: false }}
/>
</Stack>
</UserContextProvider>
</ThemeProvider>
);
}
56 changes: 1 addition & 55 deletions contextManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,61 +25,7 @@ export interface User {
//const UserContext = createContext<User | null>(null);
const UserContext = createContext<useUserReturn>(null as any);

function UserProvider({ children }: any) {
// const [user, setUser] = useState<User>(null as any);

// const setName = (firstName: string, lastName: string) => {
// setUser((prevUser) => ({
// ...prevUser,
// firstName,
// lastName,
// }));
// };

// const setEmail = (email: string) => {
// setUser((prevUser) => ({
// ...prevUser,
// email
// }));
// };

// const setPhone = (phone: number) => {
// setUser((prevUser) => ({
// ...prevUser,
// phone
// }));
// };

// const setAddress = (address: string) => {
// setUser((prevUser) => ({
// ...prevUser,
// address
// }));
// };

// const setPassword = (password: string) => {
// setUser((prevUser) => ({
// ...prevUser,
// password
// }));
// };

// const setIsMember = (isMember: boolean) => {
// setUser((prevUser) => ({
// ...prevUser,
// isMember
// }));
// };

// const addCard = (newCard: Card) => {
// setUser((prevUser) => ({
// ...prevUser,
// cards: [...(prevUser?.cards || []), newCard],
// }));
// };

// const value = user ? { ...user, setName, setEmail, setAddress, setPassword, setIsMember, addCard} : null;

export function UserContextProvider({ children }: any) {
const value = useUser();

return <UserContext.Provider value={value}>{children}</UserContext.Provider>;
Expand Down

0 comments on commit 527c1fc

Please sign in to comment.