Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"axios": "0.21.4",
"core-js": "3.2.1",
"history": "4.10.1",
"immer": "^9.0.15",
"prop-types": "15.7.2",
"ramda": "0.26.1",
"react": "17.0.1",
Expand Down
2 changes: 1 addition & 1 deletion src/Components/Pages/HomePage/homePageActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const HOMEPAGE_ACTIONS = {

const userPositionWeatherRequested = () => ({
type: HOMEPAGE_ACTIONS.USER_POSITION_WEATHER_REQUESTED
})
});

const userPositionWeatherReceived = ({ currentWeather }) => ({
type: HOMEPAGE_ACTIONS.USER_POSITION_WEATHER_RECEIVED,
Expand Down
32 changes: 15 additions & 17 deletions src/Components/Pages/HomePage/homePageReducer.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,27 @@
import initialState from './homePageInitialState';
import { HOMEPAGE_ACTIONS } from './homePageActions';
import produce from 'immer';

export const homePageReducer = (state = initialState, { type, payload }) => {
const homePageReducer = (state = initialState, { type, payload }) => {
switch (type) {
case HOMEPAGE_ACTIONS.USER_POSITION_WEATHER_REQUESTED:
return {
...state,
loading: true,
error: null
};
return produce(state, draft => {
draft.loading = true;
draft.error = null;
});
case HOMEPAGE_ACTIONS.USER_POSITION_WEATHER_RECEIVED:
return {
...state,
loading: false,
currentWeather: payload.currentWeather
};
return produce(state, draft => {
draft.loading = false;
draft.currentWeather = payload.currentWeather;
});
case HOMEPAGE_ACTIONS.USER_POSITION_WEATHER_FAILED:
return {
...state,
loading: false,
error: payload
};
return produce(state, draft => {
draft.loading = false;
draft.error = payload;
});
default:
return state;
}
};

export default homePageReducer;
export default homePageReducer;
2 changes: 1 addition & 1 deletion src/Components/Pages/HomePage/homePageSelectors.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export const getCurrentWeather = state => state.homePage.currentWeather;
export const getLoading = state => state.homePage.loading;
export const getLoading = state => state.homePage.loading;
8 changes: 4 additions & 4 deletions src/Store/actions/geoActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ const userGeoDataReceived = ({ position, location }) => ({
});

export const fetchUserGeoData = () => async dispatch => {
const position = await getUserCurrentPosition();
const { longitude, latitude } = position.coords;
const location = await getLocationByCoords(longitude, latitude);
return dispatch(userGeoDataReceived({ position: position.coords, location }));
const position = await getUserCurrentPosition();
const { longitude, latitude } = position.coords;
const location = await getLocationByCoords(longitude, latitude);
return dispatch(userGeoDataReceived({ position: position.coords, location }));
};
15 changes: 8 additions & 7 deletions src/Store/reducers/geoReducer.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
import produce from 'immer';

export const GEO_ACTIONS = {
USER_GEO_DATA_RECEIVED: 'USER_GEO_DATA_RECEIVED'
};

const initialState = {
position: null,
location: null,
location: null
};

export const geoReducer = (state = initialState, { type, payload }) => {
const geoReducer = (state = initialState, { type, payload }) => {
switch (type) {
case GEO_ACTIONS.USER_GEO_DATA_RECEIVED:
return {
...state,
position: payload.position,
location: payload.location,
};
return produce(state, draft => {
draft.position = payload.position;
draft.location = payload.location;
});
default:
return state;
}
Expand Down