From 6d602462fb25ab52519ad971d4f6433b0d897522 Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Thu, 1 Dec 2022 04:00:39 -0800 Subject: [PATCH] Fix restoring party state Instead of pulling it down from props on mount we're just pulling from state --- components/JobDropdown/index.tsx | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/components/JobDropdown/index.tsx b/components/JobDropdown/index.tsx index 6cfa6f03..179034f4 100644 --- a/components/JobDropdown/index.tsx +++ b/components/JobDropdown/index.tsx @@ -1,5 +1,6 @@ import React, { useEffect, useState } from "react" import { useRouter } from "next/router" +import { useSnapshot } from "valtio" import { appState } from "~utils/appState" import { jobGroups } from "~utils/jobGroups" @@ -21,11 +22,19 @@ const JobDropdown = React.forwardRef( const router = useRouter() const locale = router.locale || "en" + // Create snapshot of app state + const { party } = useSnapshot(appState) + // Set up local states for storing jobs const [currentJob, setCurrentJob] = useState() const [jobs, setJobs] = useState() const [sortedJobs, setSortedJobs] = useState() + // Set current job from state on mount + useEffect(() => { + setCurrentJob(party.job) + }, []) + // Organize jobs into groups on mount useEffect(() => { const jobGroups = appState.jobs @@ -67,11 +76,7 @@ const JobDropdown = React.forwardRef( .sort((a, b) => a.order - b.order) .map((item, i) => { return ( - ) @@ -88,8 +93,8 @@ const JobDropdown = React.forwardRef( return (