diff --git a/app/src/UI/Map2/Map.tsx b/app/src/UI/Map2/Map.tsx index 134944307..153edbfc5 100644 --- a/app/src/UI/Map2/Map.tsx +++ b/app/src/UI/Map2/Map.tsx @@ -52,7 +52,6 @@ export const Map = ({ children }) => { const [draw, setDraw] = useState(null); const [mapReady, setMapReady] = useState(false); - const [loggedIn, setLoggedIn] = useState(false); const mapContainer: React.MutableRefObject = useRef(null); const map: React.MutableRefObject = useRef(null); @@ -62,7 +61,7 @@ export const Map = ({ children }) => { // Avoid remounting map to avoid unnecesssary tile fetches or bad umounts: const authInitiated = useSelector((state) => state.Auth.initialized); - const { authenticated, workingOffline } = useSelector((state) => state.Auth); + const { authenticated, loggedInOrWorkingOffline } = useSelector((state) => state.Auth); const connectedToNetwork = useSelector((state) => state.Network.connected); // RecordSet Layers @@ -127,9 +126,6 @@ export const Map = ({ children }) => { const PUBLIC_MAP_URL = useSelector((state) => state.Configuration.current.PUBLIC_MAP_URL); - useEffect(() => { - setLoggedIn(authenticated || workingOffline); - }, [workingOffline, authenticated]); useEffect(() => { if (!map.current || mapReady) return; @@ -206,7 +202,7 @@ export const Map = ({ children }) => { refreshColoursOnColourUpdate(storeLayers, map.current); refreshVisibilityOnToggleUpdate(storeLayers, map.current); removeDeletedRecordSetLayersOnRecordSetDelete(storeLayers, map.current); - }, [storeLayers, map.current, mapReady, connectedToNetwork, workingOffline]); + }, [storeLayers, map.current, mapReady, connectedToNetwork, loggedInOrWorkingOffline]); // Layer picker: useEffect(() => { @@ -432,13 +428,13 @@ export const Map = ({ children }) => { // toggle public map pmtile layer useEffect(() => { if (!mapReady) return; - if (loggedIn) { + if (loggedInOrWorkingOffline) { toggleLayerOnBool(map.current, 'invasivesbc-pmtile-vector', false); toggleLayerOnBool(map.current, 'iapp-pmtile-vector', false); toggleLayerOnBool(map.current, 'invasivesbc-pmtile-vector-label', false); toggleLayerOnBool(map.current, 'iapp-pmtile-vector-label', false); } - }, [loggedIn, map.current, mapReady]); + }, [loggedInOrWorkingOffline, map.current, mapReady]); useEffect(() => { refreshWhatsHereFeature(map.current, { whatsHereFeature }); diff --git a/app/src/state/reducers/auth.ts b/app/src/state/reducers/auth.ts index 05c0863dc..242d7577c 100644 --- a/app/src/state/reducers/auth.ts +++ b/app/src/state/reducers/auth.ts @@ -69,6 +69,7 @@ export interface AuthState { offlineUserDialogOpen: boolean; offlineUsers: OfflineUserState[]; workingOffline: boolean; + loggedInOrWorkingOffline: boolean; roles: { role_id: number; role_name: string }[]; accessRoles: { role_id: number; role_name: string }[]; @@ -130,6 +131,7 @@ const initialState: AuthState = { offlineUserDialogOpen: false, offlineUsers: [], workingOffline: false, + loggedInOrWorkingOffline: false, extendedInfo: { account_status: 0, activation_status: 0, @@ -152,16 +154,17 @@ const initialState: AuthState = { function loadCurrentStateFromIdToken(idToken): object { let displayName = 'User'; - let username = null; + let username: string | null = null; let email = ''; let bceid_userid = ''; let idir_userid = ''; let bceid_user_guid = ''; let idir_user_guid = ''; - + let loggedInOrWorkingOffline = false; const authenticated = !!idToken; if (authenticated) { + loggedInOrWorkingOffline = true; try { const parsedToken = JSON.parse( decodeURIComponent( @@ -203,7 +206,8 @@ function loadCurrentStateFromIdToken(idToken): object { idir_userid, bceid_userid, idir_user_guid, - bceid_user_guid + bceid_user_guid, + loggedInOrWorkingOffline }; } @@ -222,6 +226,7 @@ function createAuthReducer(configuration: AppConfig): (AuthState, AnyAction) => draftState.displayName = null; draftState.email = null; draftState.username = 'loggedOut'; + draftState.loggedInOrWorkingOffline = false; break; } case AUTH_SAVE_CURRENT_TO_OFFLINE: { @@ -281,6 +286,7 @@ function createAuthReducer(configuration: AppConfig): (AuthState, AnyAction) => draftState.username = found.username; draftState.displayName = found.displayName; draftState.workingOffline = true; + draftState.loggedInOrWorkingOffline = true; break; } case AUTH_INITIALIZE_COMPLETE: { @@ -290,6 +296,8 @@ function createAuthReducer(configuration: AppConfig): (AuthState, AnyAction) => Object.keys(loadCurrentStateFromIdToken(currentIdToken)).forEach((key) => { draftState[key] = loadCurrentStateFromIdToken(currentIdToken)[key]; }); + draftState.workingOffline = draftState.authenticated ? false : draftState.workingOffline; + break; } case AUTH_REQUEST_COMPLETE: {