Skip to content

Commit 91358ab

Browse files
author
Thiago Lopes
committed
Revert "Trying to keep context state on user device"
This reverts commit 170f648.
1 parent 170f648 commit 91358ab

File tree

4 files changed

+2
-55
lines changed

4 files changed

+2
-55
lines changed

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
"@expo-google-fonts/poppins": "^0.2.3",
1414
"@expo/metro-config": "^0.17.4",
1515
"@expo/vector-icons": "^14.0.0",
16-
"@react-native-async-storage/async-storage": "1.21.0",
1716
"@react-navigation/bottom-tabs": "^6.5.12",
1817
"@react-navigation/drawer": "^6.6.11",
1918
"@react-navigation/material-bottom-tabs": "^6.2.19",

src/context/AppReducer.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ export enum ActionTypes {
1414
INCREASE_QTY = 'INCREASE_QTY',
1515
DECREASE_QTY = 'DECREASE_QTY',
1616
DELETE_ALL_FROM_CART = 'DELETE_ALL_FROM_CART',
17-
DELETE_ALL_FROM_FAVORITES = 'DELETE_ALL_FROM_FAVORITES',
18-
RESTORE_STATE = 'RESTORE_STATE'
17+
DELETE_ALL_FROM_FAVORITES = 'DELETE_ALL_FROM_FAVORITES'
1918
}
2019

2120
type Action =
@@ -26,7 +25,6 @@ type Action =
2625
| { type: ActionTypes.DECREASE_QTY; payload: { id: string; color: string } }
2726
| { type: ActionTypes.DELETE_ALL_FROM_CART }
2827
| { type: ActionTypes.DELETE_ALL_FROM_FAVORITES }
29-
| { type: ActionTypes.RESTORE_STATE; payload: AppState }
3028

3129
export const AppReducer = (
3230
state: AppState = initialState,

src/context/GlobalState.tsx

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { createContext, useReducer, ReactNode, useEffect } from 'react'
2-
import AsyncStorage from '@react-native-async-storage/async-storage'
1+
import { createContext, useReducer, ReactNode, Dispatch } from 'react'
32
import { AppReducer, ActionTypes } from '@Context/AppReducer'
43
import { Product, Order, AppState, GlobalStateContextProps } from '@Data/types'
54
import allProducts from '@Data/data'
@@ -34,36 +33,6 @@ interface GlobalStateProps {
3433
export const GlobalProvider = ({ children }: GlobalStateProps) => {
3534
const [state, dispatch] = useReducer(AppReducer, initialState)
3635

37-
useEffect(() => {
38-
const loadState = async () => {
39-
try {
40-
const storedState = await AsyncStorage.getItem('appState')
41-
if (storedState !== null) {
42-
dispatch({
43-
type: ActionTypes.RESTORE_STATE,
44-
payload: JSON.parse(storedState)
45-
})
46-
}
47-
} catch (error) {
48-
console.error('Error loading state from AsyncStorage:', error)
49-
}
50-
}
51-
52-
loadState()
53-
}, [])
54-
55-
useEffect(() => {
56-
const saveState = async () => {
57-
try {
58-
await AsyncStorage.setItem('appState', JSON.stringify(state))
59-
} catch (error) {
60-
console.error('Error saving state to AsyncStorage:', error)
61-
}
62-
}
63-
64-
saveState()
65-
}, [state])
66-
6736
const isOnFavorite = (id: string) => {
6837
return state.favorites.some((product) => product.id === id)
6938
}

yarn.lock

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1747,13 +1747,6 @@
17471747
mkdirp "^1.0.4"
17481748
rimraf "^3.0.2"
17491749

1750-
"@react-native-async-storage/async-storage@1.21.0":
1751-
version "1.21.0"
1752-
resolved "https://registry.yarnpkg.com/@react-native-async-storage/async-storage/-/async-storage-1.21.0.tgz#d7e370028e228ab84637016ceeb495878b7a44c8"
1753-
integrity sha512-JL0w36KuFHFCvnbOXRekqVAUplmOyT/OuCQkogo6X98MtpSaJOKEAeZnYO8JB0U/RIEixZaGI5px73YbRm/oag==
1754-
dependencies:
1755-
merge-options "^3.0.4"
1756-
17571750
"@react-native-community/cli-clean@12.3.6":
17581751
version "12.3.6"
17591752
resolved "https://registry.yarnpkg.com/@react-native-community/cli-clean/-/cli-clean-12.3.6.tgz#e8a7910bebc97266fd5068649013a03958021fc4"
@@ -4228,11 +4221,6 @@ is-path-inside@^3.0.2:
42284221
resolved "https://registry.npmjs.org/is-path-inside/-/is-path-inside-3.0.3.tgz"
42294222
integrity sha512-Fd4gABb+ycGAmKou8eMftCupSir5lRxqf4aD/vd0cD2qc4HL07OjCeuHMr8Ro4CoMaeCKDB0/ECBOVWjTwUvPQ==
42304223

4231-
is-plain-obj@^2.1.0:
4232-
version "2.1.0"
4233-
resolved "https://registry.yarnpkg.com/is-plain-obj/-/is-plain-obj-2.1.0.tgz#45e42e37fccf1f40da8e5f76ee21515840c09287"
4234-
integrity sha512-YWnfyRwxL/+SsrWYfOpUtz5b3YD+nyfkHvjbcanzk8zgyO4ASD67uVMRt8k5bM4lLMDnXfriRhOpemw+NfT1eA==
4235-
42364224
is-plain-object@^2.0.4:
42374225
version "2.0.4"
42384226
resolved "https://registry.npmjs.org/is-plain-object/-/is-plain-object-2.0.4.tgz"
@@ -4743,13 +4731,6 @@ memory-cache@~0.2.0:
47434731
resolved "https://registry.npmjs.org/memory-cache/-/memory-cache-0.2.0.tgz"
47444732
integrity sha512-OcjA+jzjOYzKmKS6IQVALHLVz+rNTMPoJvCztFaZxwG14wtAW7VRZjwTQu06vKCYOxh4jVnik7ya0SXTB0W+xA==
47454733

4746-
merge-options@^3.0.4:
4747-
version "3.0.4"
4748-
resolved "https://registry.yarnpkg.com/merge-options/-/merge-options-3.0.4.tgz#84709c2aa2a4b24c1981f66c179fe5565cc6dbb7"
4749-
integrity sha512-2Sug1+knBjkaMsMgf1ctR1Ujx+Ayku4EdJN4Z+C2+JzoeF7A3OZ9KM2GY0CpQS51NR61LTurMJrRKPhSs3ZRTQ==
4750-
dependencies:
4751-
is-plain-obj "^2.1.0"
4752-
47534734
merge-stream@^2.0.0:
47544735
version "2.0.0"
47554736
resolved "https://registry.npmjs.org/merge-stream/-/merge-stream-2.0.0.tgz"

0 commit comments

Comments
 (0)