Skip to content

Commit

Permalink
saving changes. Opening PR here shortly.
Browse files Browse the repository at this point in the history
  • Loading branch information
siddheshraze committed Mar 27, 2024
1 parent 5df0ee1 commit 0f8b3aa
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion frontend/app/(hub)/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {Box} from "@mui/joy";
import Divider from "@mui/joy/Divider";
import {useLoading} from "@/app/contexts/loadingprovider";
import {loadServerDataIntoIDB} from "@/config/updatecontextsfromidb";
import {useSiteContext} from "@/app/contexts/userselectionprovider";
import {useCensusDispatch, usePlotDispatch, useSiteContext} from "@/app/contexts/userselectionprovider";

function renderSwitch(endpoint: string) {
switch (endpoint) {
Expand Down Expand Up @@ -71,9 +71,15 @@ export default function HubLayout({children,}: Readonly<{ children: React.ReactN
const quadratListDispatch = useQuadratListDispatch();
const censusListDispatch = useCensusListDispatch();
const siteListDispatch = useSiteListDispatch();
// plot & census selection dispatches to reset plot/census when census changes
const censusDispatch = useCensusDispatch();
const plotDispatch = usePlotDispatch();
// site/session definition
const currentSite = useSiteContext();
const {data: session} = useSession();
const previousSiteRef = useRef<string | undefined>(undefined);
const previousCensusRef = useRef<string | undefined>(undefined);
const previousPlotRef = useRef<string | undefined>(undefined);

const [siteListLoaded, setSiteListLoaded] = useState(false);
const [coreDataLoaded, setCoreDataLoaded] = useState(false);
Expand Down Expand Up @@ -170,6 +176,9 @@ export default function HubLayout({children,}: Readonly<{ children: React.ReactN
if (siteListLoaded && currentSite && !coreDataLoaded) {
// Site list loaded and current site selected, fetch core data
fetchAndUpdateCoreData().then(() => setCoreDataLoaded(true)).catch(console.error);
// clear currently selected plot & census
if (censusDispatch) censusDispatch({census: null});
if (plotDispatch) plotDispatch({plot: null});
}
}, [siteListLoaded, currentSite, coreDataLoaded, fetchAndUpdateCoreData]);

Expand Down

0 comments on commit 0f8b3aa

Please sign in to comment.