diff --git a/src/App.tsx b/src/App.tsx index 1ac87ce..59b1338 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -27,10 +27,12 @@ function App() { initialBaselayersState ); + const [isAuthenticated, setIsAuthenticated] = useState(null); + /** query the bands to use as the baselayers of the map */ useQuery({ initialData: undefined, - queryKey: [], + queryKey: [isAuthenticated], queryFn: async () => { // Fetch the maps and the map metadata in order to get the list of bands used as // map baselayers @@ -69,7 +71,7 @@ function App() { /** sourceLists are used as FeatureGroups in the map, which can be toggled on/off in the map legend */ const { data: sourceLists } = useQuery({ initialData: undefined, - queryKey: [], + queryKey: [isAuthenticated], queryFn: async () => { // Fetch the source catalogs and sources const { catalogs, sources } = await fetchProducts('sources'); @@ -93,7 +95,7 @@ function App() { // The optimistic version of highlightBoxes for when we add boxes in the UI optimisticHighlightBoxes, addOptimisticHighlightBox, - } = useHighlightBoxes(); + } = useHighlightBoxes(isAuthenticated); /** tracks highlight boxes that are "checked" and visible on the map */ const [activeBoxIds, setActiveBoxIds] = useState([]); @@ -168,24 +170,30 @@ function App() { const { activeBaselayer, internalBaselayersState } = baselayersState; return ( <> - - {activeBaselayer && internalBaselayersState && ( - - )} - {assertBand(activeBaselayer) && + + {isAuthenticated !== null && + activeBaselayer && + internalBaselayersState && ( + + )} + {isAuthenticated !== null && + assertBand(activeBaselayer) && activeBaselayer.cmap && activeBaselayer.cmapValues && ( (null); - +export function Login({ + isAuthenticated, + setIsAuthenticated, +}: { + isAuthenticated: boolean | null; + setIsAuthenticated: (isAuthenticated: boolean) => void; +}) { useEffect(() => { const hasAccessToken = getCookie('validate_access_token'); const hasRefreshToken = getCookie('valid_refresh_token'); diff --git a/src/hooks/useHighlightBoxes.ts b/src/hooks/useHighlightBoxes.ts index 9b24a87..5deaf60 100644 --- a/src/hooks/useHighlightBoxes.ts +++ b/src/hooks/useHighlightBoxes.ts @@ -9,7 +9,9 @@ type UseHighlightBoxesReturn = { addOptimisticHighlightBox: (action: Box) => void; }; -export function useHighlightBoxes(): UseHighlightBoxesReturn { +export function useHighlightBoxes( + isAuthenticated: boolean | null +): UseHighlightBoxesReturn { // Represents the box regions users can add to maps const [highlightBoxes, updateHighlightBoxes] = useState( undefined @@ -34,7 +36,7 @@ export function useHighlightBoxes(): UseHighlightBoxesReturn { updateHighlightBoxes(boxes); } getBoxes(); - }, []); + }, [isAuthenticated]); return { highlightBoxes, diff --git a/src/hooks/useQuery.ts b/src/hooks/useQuery.ts index 205c889..f324c08 100644 --- a/src/hooks/useQuery.ts +++ b/src/hooks/useQuery.ts @@ -2,7 +2,7 @@ import { useState, useEffect } from 'react'; type UseQueryParams = { queryFn: () => Promise; - queryKey: string[]; + queryKey: any[]; initialData: T; };