-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: YoanRos <[email protected]>
- Loading branch information
1 parent
d486128
commit 7ed8eb0
Showing
9 changed files
with
119 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ import "react-native-get-random-values"; | |
import React, { useEffect, useState } from "react"; | ||
import * as Sentry from "@sentry/react-native"; | ||
import { SafeAreaProvider } from "react-native-safe-area-context"; | ||
import { RecoilRoot } from "recoil"; | ||
import { RecoilRoot, useSetRecoilState } from "recoil"; | ||
import dayjs from "dayjs"; | ||
import * as SplashScreen from "expo-splash-screen"; | ||
import * as Application from "expo-application"; | ||
|
@@ -26,16 +26,18 @@ import { | |
migrateMissingDrinkKey, | ||
sendPreviousDrinksToDB, | ||
} from "./src/migrations"; | ||
import { reconciliateDrinksToDB, reconciliateGoalToDB } from "./src/reconciliations"; | ||
import { fixMissingDrinkKey, reconciliateDrinksToDB, reconciliateGoalToDB } from "./src/reconciliations"; | ||
import { drinksState, ownDrinksCatalogState } from "./src/recoil/consos"; | ||
import { drinksByWeekState, goalsState } from "./src/recoil/gains"; | ||
import { getInitValueFromStorage } from "./src/recoil/utils"; | ||
|
||
dayjs.locale("fr"); | ||
dayjs.extend(isSameOrAfter); | ||
dayjs.extend(weekday); | ||
|
||
SplashScreen.preventAutoHideAsync(); | ||
|
||
const release = | ||
getBundleId() + "@" + Application.nativeApplicationVersion + "+" + Application.nativeBuildVersion; // ex : [email protected]+198 | ||
const release = getBundleId() + "@" + Application.nativeApplicationVersion + "+" + Application.nativeBuildVersion; // ex : [email protected]+198 | ||
|
||
Sentry.init({ | ||
dsn: __DEV__ ? "" : "https://[email protected]/80", | ||
|
@@ -46,15 +48,14 @@ Sentry.init({ | |
const App = () => { | ||
// sync everytime we open the app | ||
const [reconciliatedDrinksToDB, setReconciliatedDrinksToDB] = useState(false); | ||
const [fixedMissingDrinkKey, setFixedMissingDrinkKey] = useState(false); | ||
const [reconciliatedGoalsToDB, setReconciliatedGoalsToDB] = useState(false); | ||
|
||
// migrate only once if not yet done | ||
// TODO: clean migrations when it's time | ||
const [_hasSentPreviousDrinksToDB, setHasSentPreviousDrinksToDB] = | ||
useState(hasSentPreviousDrinksToDB); | ||
const [_hasSentPreviousDrinksToDB, setHasSentPreviousDrinksToDB] = useState(hasSentPreviousDrinksToDB); | ||
const [_hasCleanConsoAndCatalog, setHasCleanConsoAndCatalog] = useState(hasCleanConsoAndCatalog); | ||
const [_hasMigrateMissingDrinkKey, sethasMigrateMissingDrinkKey] = | ||
useState(hasMigrateMissingDrinkKey); | ||
const [_hasMigrateMissingDrinkKey, sethasMigrateMissingDrinkKey] = useState(hasMigrateMissingDrinkKey); | ||
const [_hasMigrateFromDailyGoalToWeekly, sethasMigrateFromDailyGoalToWeekly] = useState( | ||
hasMigrateFromDailyGoalToWeekly | ||
); | ||
|
@@ -65,6 +66,10 @@ const App = () => { | |
await reconciliateDrinksToDB(); | ||
setReconciliatedDrinksToDB(true); | ||
} | ||
if (!fixedMissingDrinkKey) { | ||
await fixMissingDrinkKey(); | ||
setFixedMissingDrinkKey(true); | ||
} | ||
if (!reconciliatedGoalsToDB) { | ||
await reconciliateGoalToDB(); | ||
setReconciliatedGoalsToDB(true); | ||
|
@@ -92,6 +97,7 @@ const App = () => { | |
|
||
if ( | ||
!reconciliatedDrinksToDB || | ||
!fixedMissingDrinkKey || | ||
!reconciliatedGoalsToDB || | ||
!_hasSentPreviousDrinksToDB || | ||
!_hasCleanConsoAndCatalog || | ||
|
@@ -101,15 +107,38 @@ const App = () => { | |
return null; | ||
} | ||
|
||
return <RecoiledApp />; | ||
}; | ||
|
||
function RecoiledApp() { | ||
return ( | ||
<RecoilRoot> | ||
<ResetRecoilStatesAfterMigrationsAndReconciliations /> | ||
<ToastProvider> | ||
<SafeAreaProvider> | ||
<Router /> | ||
</SafeAreaProvider> | ||
</ToastProvider> | ||
</RecoilRoot> | ||
); | ||
}; | ||
} | ||
|
||
// Why this function ? | ||
// because we have a FUCKING HARD TIME to manage how and when recoil is initiated | ||
// the default value of recoil's atoms is called AT FIRST, before any migration or reconciliation | ||
// so we need to re-init the atoms we want to be initiated once the migrations/reconciliations are done | ||
function ResetRecoilStatesAfterMigrationsAndReconciliations() { | ||
const resetOwnDrinks = useSetRecoilState(ownDrinksCatalogState); | ||
const resetDrinks = useSetRecoilState(drinksState); | ||
const resetDrinksByWeek = useSetRecoilState(drinksByWeekState); | ||
const resetGoals = useSetRecoilState(goalsState); | ||
useEffect(() => { | ||
resetOwnDrinks(getInitValueFromStorage("@OwnDrinks", [])); | ||
resetDrinks(getInitValueFromStorage("@Drinks", [])); | ||
resetDrinksByWeek(getInitValueFromStorage("@StoredDetaileddrinksByWeekState", [])); | ||
resetGoals(getInitValueFromStorage("goalsState", [])); | ||
}, []); | ||
return null; | ||
} | ||
|
||
export default Sentry.wrap(App); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters