From c78fcda9123e852321e19fc0392e4e39e7956d86 Mon Sep 17 00:00:00 2001 From: natjms Date: Sat, 3 Apr 2021 04:29:54 -0300 Subject: [PATCH] Improve async workflow in authenticate.js --- src/components/pages/authenticate.js | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/components/pages/authenticate.js b/src/components/pages/authenticate.js index 2f58806..d10d2ed 100644 --- a/src/components/pages/authenticate.js +++ b/src/components/pages/authenticate.js @@ -53,19 +53,21 @@ const AuthenticateJsx = ({navigation}) => { }); }, []); - const loginCallback = async () => { - const profileJSON = JSON.stringify(TEST_PROFILE); + const loginCallback = () => { + const initialization = [ + [ "@user_profile", JSON.stringify(TEST_PROFILE) ], + [ + "@user_notifications", + JSON.stringify({ + unread: false, + memory: [{ id: 1 }, { id: 2 }], + }) + ] + ]; - // TODO: Should fetch initial notifications to prevent bugging a newly - // logged in user about the notifications already on their account - const notificationsJSON = JSON.stringify({ - unread: false, - memory: [{ id: 1 }, { id: 2 }], + AsyncStorage.multiSet(initialization).then(() => { + navigation.navigate("Feed"); }); - await AsyncStorage.setItem("@user_profile", profileJSON); - await AsyncStorage.setItem("@user_notifications", notificationsJSON); - - navigation.navigate("Feed"); }; return (