All files / app/actions setDates.ts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35              5x                                                      
import { fetchDiff } from 'app/actions/diff';
import { debug } from 'app/utilities/logger';
 
import { setStartDate, setEndDate } from 'app/actions';
import { dateFilteredCommits } from 'app/selectors/dates';
import { commits } from 'app/reducers/commits';
 
export const setDates = (_startDate: number, _endDate: number | Date) => (
  dispatch,
  getState
) => {
  const [startDate, endDate] =
    _startDate === _endDate
      ? [_startDate, _endDate + 1]
      : !_endDate || _startDate < _endDate
        ? [_startDate, _endDate]
        : [_endDate, _startDate];
 
  const epochStartDate = startDate && Math.floor((startDate as number) / 1000);
  const epochEndDate = endDate && Math.floor((endDate as number) / 1000);
 
  debug('actions: setDates', startDate, endDate, epochStartDate, epochEndDate);
 
  dispatch(setStartDate(epochStartDate));
  dispatch(setEndDate(epochEndDate));
 
  const { commits, selectedPath } = getState();
  const leftCommit =
    (startDate && commits.find(c => c.authorDate < epochStartDate)) || null;
  const rightCommit =
    (endDate && commits.find(c => c.authorDate < epochEndDate)) || null;
 
  dispatch(fetchDiff(selectedPath, leftCommit, rightCommit));
};