-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
46 lines (42 loc) · 1.09 KB
/
App.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import React from "react";
import { NavigationContainer } from "@react-navigation/native";
import Routes from "./src";
import { Provider } from "react-redux";
import { createStore } from "redux";
// para um problema no firebase
import { decode, encode } from "base-64";
if (!global.btoa) {
global.btoa = encode;
}
if (!global.atob) {
global.atob = decode;
}
const initialState = { cart: [] };
const reducer = (state = initialState, action) => {
switch (action.type) {
case "ADD_CART": {
if (!state.cart.includes(action.data)) {
return { cart: state.cart.concat([action.data]) };
} else return state;
}
case "REMOVE_CART": {
if (state.cart.includes(action.data)) {
state.cart.splice(state.cart.indexOf(action.data), 1);
return { cart: state.cart };
} else return state;
}
case "CLEAR_CART": {
return initialState;
}
}
return state;
};
const store = createStore(reducer);
const App = () => (
<Provider store={store}>
<NavigationContainer>
<Routes />
</NavigationContainer>
</Provider>
);
export default App;