From 165acf87d4e1b7c0e8b2c40ec55b90de20cb354b Mon Sep 17 00:00:00 2001 From: Samuel Meuli Date: Wed, 12 Dec 2018 21:55:02 +0100 Subject: [PATCH] Select first day of month on month change --- src/renderer/redux/actions/diaryActions.js | 19 +++++-------------- src/renderer/redux/reducers/diaryReducer.js | 8 +------- 2 files changed, 6 insertions(+), 21 deletions(-) diff --git a/src/renderer/redux/actions/diaryActions.js b/src/renderer/redux/actions/diaryActions.js index bf15cf1c..8d79c73a 100644 --- a/src/renderer/redux/actions/diaryActions.js +++ b/src/renderer/redux/actions/diaryActions.js @@ -7,22 +7,13 @@ import { searchIndex } from '../../helpers/searchIndex'; export function setDateSelected(dateSelected) { return { - type: 'SET_SELECTED_DATE', + type: 'SET_DATE_SELECTED', payload: { dateSelected } }; } -export function setMonthSelected(monthSelected) { - return { - type: 'SET_SELECTED_MONTH', - payload: { - monthSelected - } - }; -} - function setSearchKey(searchKey) { return { type: 'SET_SEARCH_KEY', @@ -73,9 +64,9 @@ export function setDateSelectedPrevious() { export function setMonthSelectedNext() { return (dispatch, getState) => { const { monthSelected } = getState().diary; - const nextMonth = moment(monthSelected).add(1, 'months'); + const nextMonth = moment(monthSelected).add(1, 'months').startOf('month'); if (nextMonth.isSameOrBefore(moment(), 'month')) { - dispatch(setMonthSelected(nextMonth.toDate())); + dispatch(setDateSelected(nextMonth.toDate())); } }; } @@ -83,7 +74,7 @@ export function setMonthSelectedNext() { export function setMonthSelectedPrevious() { return (dispatch, getState) => { const { monthSelected } = getState().diary; - const previousMonth = moment(monthSelected).subtract(1, 'months'); - dispatch(setMonthSelected(previousMonth.toDate())); + const previousMonth = moment(monthSelected).subtract(1, 'months').startOf('month'); + dispatch(setDateSelected(previousMonth.toDate())); }; } diff --git a/src/renderer/redux/reducers/diaryReducer.js b/src/renderer/redux/reducers/diaryReducer.js index 55f8e51f..ebab9f19 100644 --- a/src/renderer/redux/reducers/diaryReducer.js +++ b/src/renderer/redux/reducers/diaryReducer.js @@ -7,19 +7,13 @@ function diary(state = { searchResults: [] }, action) { switch (action.type) { - case 'SET_SELECTED_DATE': { + case 'SET_DATE_SELECTED': { return { ...state, dateSelected: action.payload.dateSelected, monthSelected: action.payload.dateSelected }; } - case 'SET_SELECTED_MONTH': { - return { - ...state, - monthSelected: action.payload.monthSelected - }; - } case 'SET_SEARCH_KEY': { return { ...state,