From 1cc304d412bce4ae5935e55d8adea694b4355180 Mon Sep 17 00:00:00 2001 From: Roman Popat Date: Mon, 7 Apr 2025 21:31:40 +0000 Subject: [PATCH 1/2] feat: Initialize geolocation state structure in geolocationSlice --- bs3/src/app/geolocatorSlice.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/bs3/src/app/geolocatorSlice.js b/bs3/src/app/geolocatorSlice.js index 09dd630..4a259b2 100644 --- a/bs3/src/app/geolocatorSlice.js +++ b/bs3/src/app/geolocatorSlice.js @@ -3,7 +3,11 @@ import { createSlice } from '@reduxjs/toolkit'; export const geolocationSlice = createSlice({ name: 'geolocation', initialState: { - location: null, + location: { + loaded: false, + coordinates: { lat: null, lng: null }, + local: false, + } }, reducers: { setLocation: (state, action) => { From 74ccaeea58c91abe4753950eecb968b28ca82185 Mon Sep 17 00:00:00 2001 From: Roman Popat Date: Mon, 7 Apr 2025 21:31:53 +0000 Subject: [PATCH 2/2] feat: Implement geoLocation dispatch within useEffect for improved validation --- bs3/src/App.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/bs3/src/App.js b/bs3/src/App.js index b4ba0ba..60cb16f 100644 --- a/bs3/src/App.js +++ b/bs3/src/App.js @@ -4,12 +4,18 @@ import { Outlet } from 'react-router-dom'; import { useDispatch } from 'react-redux'; import { setLocation } from './app/geolocatorSlice'; import useGeoLocationCheck from './api/geolocation'; +import { useEffect } from 'react'; function App() { - const dispatch = useDispatch(); - const geoLocation = useGeoLocationCheck(); - dispatch(setLocation(geoLocation)); + const geoLocation = useGeoLocationCheck(); // Custom hook + + // Use useEffect to dispatch the action only when geoLocation is valid + useEffect(() => { + if (geoLocation) { + dispatch(setLocation(geoLocation)); + } + }, [dispatch, geoLocation]); return (