Skip to content
This repository has been archived by the owner on Jul 12, 2021. It is now read-only.

Commit

Permalink
Select first day of month on month change
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelmeuli committed Dec 12, 2018
1 parent 5207b91 commit 165acf8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 21 deletions.
19 changes: 5 additions & 14 deletions src/renderer/redux/actions/diaryActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -73,17 +64,17 @@ 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()));
}
};
}

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()));
};
}
8 changes: 1 addition & 7 deletions src/renderer/redux/reducers/diaryReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 165acf8

Please sign in to comment.