From 8c81bed01365092fbbfad99283bba51a4e34f2fa Mon Sep 17 00:00:00 2001 From: Reckless_Satoshi Date: Mon, 24 Apr 2023 07:47:34 -0700 Subject: [PATCH] Fix Garage and Settings load on Android --- frontend/src/contexts/AppContext.ts | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/frontend/src/contexts/AppContext.ts b/frontend/src/contexts/AppContext.ts index f8ba3dcc..8c061b74 100644 --- a/frontend/src/contexts/AppContext.ts +++ b/frontend/src/contexts/AppContext.ts @@ -102,18 +102,16 @@ const makeTheme = function (settings: Settings) { return theme; }; -const initialSettings = new Settings(); -const initialTheme = makeTheme(initialSettings); -const initialGarage = new Garage(); -const initialSlot = initialGarage.slots.length - 1; -const initialRobot = new Robot(initialGarage.slots[initialSlot].robot); - export const useAppStore = () => { // State provided right at the top level of the app. A chaotic bucket of everything. // Contains app-wide state and functions. Triggers re-renders on the full tree often. - const [theme, setTheme] = useState(initialTheme); - const [settings, setSettings] = useState(initialSettings); + const [settings, setSettings] = useState(() => { + return new Settings(); + }); + const [theme, setTheme] = useState(() => { + return makeTheme(settings); + }); useEffect(() => { setTheme(makeTheme(settings)); @@ -130,9 +128,15 @@ export const useAppStore = () => { list: [], loading: true, }); - const [garage, setGarage] = useState(initialGarage); - const [currentSlot, setCurrentSlot] = useState(initialSlot); - const [robot, setRobot] = useState(initialRobot); + const [garage, setGarage] = useState(() => { + return new Garage(); + }); + const [currentSlot, setCurrentSlot] = useState(() => { + return garage.slots.length - 1; + }); + const [robot, setRobot] = useState(() => { + return new Robot(garage.slots[currentSlot].robot); + }); const [maker, setMaker] = useState(defaultMaker); const [info, setInfo] = useState(defaultInfo); const [coordinators, setCoordinators] = useState(defaultCoordinators);