Skip to content

Commit

Permalink
Subindo redux para armazenamento do estado de datas
Browse files Browse the repository at this point in the history
  • Loading branch information
itsmorais committed Nov 3, 2024
1 parent 71f49b3 commit ef03804
Show file tree
Hide file tree
Showing 16 changed files with 206 additions and 178 deletions.
7 changes: 4 additions & 3 deletions frontend/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import React, { useEffect } from "react";
import * as SplashScreen from "expo-splash-screen";
import { useFonts, Signika_400Regular } from "@expo-google-fonts/signika";
import { UserProvider } from "./src/context/userContext";
import { DateProvider } from "./src/context/dateContext";
import { PaperProvider } from "react-native-paper";
import {Provider} from 'react-redux'
import { store } from "./src/store/store";
SplashScreen.preventAutoHideAsync(); // Manter a splash screen até as fontes serem carregadas

export default function App() {
Expand All @@ -25,11 +26,11 @@ export default function App() {
}
return (
<PaperProvider>
<Provider store={store}>
<UserProvider>
<DateProvider>
<Routes />
</DateProvider>
</UserProvider>
</Provider>
</PaperProvider>

)
Expand Down
89 changes: 88 additions & 1 deletion frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"@react-navigation/native": "^6.1.18",
"@react-navigation/native-stack": "^6.11.0",
"@react-navigation/stack": "^6.4.1",
"@reduxjs/toolkit": "^2.3.0",
"@types/react-native": "^0.73.0",
"axios": "^1.7.7",
"cors": "^2.8.5",
Expand All @@ -45,7 +46,8 @@
"react-native-svg": "^15.7.1",
"react-native-svg-circular-progress": "^1.0.4",
"react-native-vector-icons": "^10.2.0",
"react-native-web": "~0.19.10"
"react-native-web": "~0.19.10",
"react-redux": "^9.1.2"
},
"devDependencies": {
"@babel/core": "^7.20.0",
Expand Down
24 changes: 0 additions & 24 deletions frontend/src/context/dateContext.tsx

This file was deleted.

17 changes: 17 additions & 0 deletions frontend/src/dateSlice.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { createSlice } from '@reduxjs/toolkit';
import moment from 'moment';

export const dateSlice = createSlice({
name: 'date',
initialState: {
value: moment.utc().format("YYYY-MM-DD"),
},
reducers: {
setNewDate: (state, action) => { state.value = action.payload }
},
});

export const { setNewDate } = dateSlice.actions;
export const selectDate = (state: any) => state.date.value;

export default dateSlice.reducer;
1 change: 0 additions & 1 deletion frontend/src/routes/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import StackRoutes from "./stack.routes";
import { NavigationContainer } from "@react-navigation/native";
import TabRoutes from "./tab.routes";
import { UserContext } from "../context/userContext";
import { useContext } from "react";
import AuthRoutes from "./auth.routes";
Expand Down
64 changes: 20 additions & 44 deletions frontend/src/routes/stack.routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import React from "react";
import ProductDetailsScreenPG from "../screens/ProductPG";
import AlimentosConsumidosScreen from "../screens/AlimentosConsumidosScreen";
import SelectRefeicao from "../screens/SelectRefeicao";
import Main from "../screens/HomeScreen";
import { IuserLogin } from "../types/user";

const Stack = createStackNavigator();
Expand All @@ -27,14 +26,14 @@ export default function StackRoutes() {
const [isOnboardingCompleted, setIsOnboardingCompleted] = useState<
null | boolean
>(null);
const [user,setUser] = useState<IuserLogin>();
const [user, setUser] = useState<IuserLogin>();

useEffect(() => {
const checkOnboardingStatus = async () => {
const completed = await AsyncStorage.getItem("onboardingCompleted");
setIsOnboardingCompleted(completed === "true");

const userData = await AsyncStorage.getItem("user");
const userData = await AsyncStorage.getItem("user");
setUser(userData ? JSON.parse(userData) : null);
};

Expand All @@ -46,40 +45,17 @@ export default function StackRoutes() {
}

return (
<Stack.Navigator
initialRouteName={isOnboardingCompleted ? "Main" : "Onboarding"}
screenOptions={({ navigation, route }) => ({
headerShown: !(route.name === "Onboarding"),
headerLeft:
route.name === "Main"
? () => (
<TouchableOpacity
onPress={() => navigation.goBack()}
style={{
flexDirection: "row",
alignItems: "center",
marginLeft: 10,
}}
>
<Ionicons name="arrow-back" size={24} color="black" />
<Text style={{ marginLeft: 5, fontSize: 18 }}>Voltar</Text>
</TouchableOpacity>
)
: undefined,
})}
>
{!isOnboardingCompleted && (
<Stack.Screen
name="Onboarding"
component={TabRoutes}
options={{ headerShown: false }}
/>
)}




<Stack.Screen
<Stack.Navigator>

<Stack.Screen
name="Main"
component={TabRoutes}
options={{ headerShown: false }}
/>



<Stack.Screen
name="SelectRefeicao"
component={SelectRefeicao}
options={{
Expand Down Expand Up @@ -160,7 +136,7 @@ export default function StackRoutes() {
},
}}
/>
<Stack.Screen
<Stack.Screen
name="AlimentosConsumidosScreen"
component={AlimentosConsumidosScreen}
options={{
Expand All @@ -173,7 +149,7 @@ export default function StackRoutes() {
color: "#000000", // Cor do título, ajustada para melhor contraste com o fundo
},
}}
/>
/>
<Stack.Screen
name="termsOfUse"
component={TermsOfUse}
Expand All @@ -194,10 +170,10 @@ export default function StackRoutes() {
}}
/>

<Stack.Screen
name="ProfileScreen"
component={ProfileScreen}
options={{
<Stack.Screen
name="ProfileScreen"
component={ProfileScreen}
options={{
headerShown: false,
title: "Profile",
headerStyle: {
Expand All @@ -206,7 +182,7 @@ export default function StackRoutes() {
headerTitleStyle: {
color: "#000000", // Cor do título, ajustada para melhor contraste com o fundo
},
}}/>
}} />



Expand Down
Loading

0 comments on commit ef03804

Please sign in to comment.