Fixed: Calendar Filter Selection and Persist State

pull/250/head
Qstick 7 years ago
parent 4940e5014d
commit ef0590728f

@ -40,10 +40,6 @@ class CalendarPage extends Component {
this.props.onDaysCountChange(days); this.props.onDaysCountChange(days);
} }
onFilterSelect = (selectedFilterKey) => {
this.props.onUnmonitoredChange(selectedFilterKey === 'unmonitored');
}
onGetCalendarLinkPress = () => { onGetCalendarLinkPress = () => {
this.setState({ isCalendarLinkModalOpen: true }); this.setState({ isCalendarLinkModalOpen: true });
} }
@ -60,7 +56,8 @@ class CalendarPage extends Component {
selectedFilterKey, selectedFilterKey,
filters, filters,
hasArtist, hasArtist,
colorImpairedMode colorImpairedMode,
onFilterSelect
} = this.props; } = this.props;
const isMeasured = this.state.width > 0; const isMeasured = this.state.width > 0;
@ -89,7 +86,7 @@ class CalendarPage extends Component {
selectedFilterKey={selectedFilterKey} selectedFilterKey={selectedFilterKey}
filters={filters} filters={filters}
customFilters={[]} customFilters={[]}
onFilterSelect={this.onFilterSelect} onFilterSelect={onFilterSelect}
/> />
</PageToolbarSection> </PageToolbarSection>
</PageToolbar> </PageToolbar>
@ -126,7 +123,7 @@ CalendarPage.propTypes = {
hasArtist: PropTypes.bool.isRequired, hasArtist: PropTypes.bool.isRequired,
colorImpairedMode: PropTypes.bool.isRequired, colorImpairedMode: PropTypes.bool.isRequired,
onDaysCountChange: PropTypes.func.isRequired, onDaysCountChange: PropTypes.func.isRequired,
onUnmonitoredChange: PropTypes.func.isRequired onFilterSelect: PropTypes.func.isRequired
}; };
export default CalendarPage; export default CalendarPage;

@ -1,6 +1,6 @@
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { createSelector } from 'reselect'; import { createSelector } from 'reselect';
import { setCalendarDaysCount, setCalendarIncludeUnmonitored } from 'Store/Actions/calendarActions'; import { setCalendarDaysCount, setCalendarFilter } from 'Store/Actions/calendarActions';
import createArtistCountSelector from 'Store/Selectors/createArtistCountSelector'; import createArtistCountSelector from 'Store/Selectors/createArtistCountSelector';
import createUISettingsSelector from 'Store/Selectors/createUISettingsSelector'; import createUISettingsSelector from 'Store/Selectors/createUISettingsSelector';
import CalendarPage from './CalendarPage'; import CalendarPage from './CalendarPage';
@ -28,8 +28,8 @@ function createMapDispatchToProps(dispatch, props) {
dispatch(setCalendarDaysCount({ dayCount })); dispatch(setCalendarDaysCount({ dayCount }));
}, },
onUnmonitoredChange(unmonitored) { onFilterSelect(selectedFilterKey) {
dispatch(setCalendarIncludeUnmonitored({ unmonitored })); dispatch(setCalendarFilter({ selectedFilterKey }));
} }
}; };
} }

@ -40,23 +40,23 @@ export const defaultState = {
filters: [ filters: [
{ {
key: 'monitored', key: 'all',
label: 'Monitored Only', label: 'All',
filters: [ filters: [
{ {
key: 'monitored', key: 'monitored',
value: true, value: false,
type: filterTypes.EQUAL type: filterTypes.EQUAL
} }
] ]
}, },
{ {
key: 'unmonitored', key: 'monitored',
label: 'Include Unmonitored', label: 'Monitored Only',
filters: [ filters: [
{ {
key: 'monitored', key: 'monitored',
value: false, value: true,
type: filterTypes.EQUAL type: filterTypes.EQUAL
} }
] ]
@ -66,7 +66,6 @@ export const defaultState = {
export const persistState = [ export const persistState = [
'calendar.view', 'calendar.view',
'calendar.unmonitored',
'calendar.selectedFilterKey' 'calendar.selectedFilterKey'
]; ];
@ -75,7 +74,7 @@ export const persistState = [
export const FETCH_CALENDAR = 'calendar/fetchCalendar'; export const FETCH_CALENDAR = 'calendar/fetchCalendar';
export const SET_CALENDAR_DAYS_COUNT = 'calendar/setCalendarDaysCount'; export const SET_CALENDAR_DAYS_COUNT = 'calendar/setCalendarDaysCount';
export const SET_CALENDAR_INCLUDE_UNMONITORED = 'calendar/setCalendarIncludeUnmonitored'; export const SET_CALENDAR_FILTER = 'calendar/setCalendarFilter';
export const SET_CALENDAR_VIEW = 'calendar/setCalendarView'; export const SET_CALENDAR_VIEW = 'calendar/setCalendarView';
export const GOTO_CALENDAR_TODAY = 'calendar/gotoCalendarToday'; export const GOTO_CALENDAR_TODAY = 'calendar/gotoCalendarToday';
export const GOTO_CALENDAR_PREVIOUS_RANGE = 'calendar/gotoCalendarPreviousRange'; export const GOTO_CALENDAR_PREVIOUS_RANGE = 'calendar/gotoCalendarPreviousRange';
@ -182,7 +181,7 @@ function isRangePopulated(start, end, state) {
export const fetchCalendar = createThunk(FETCH_CALENDAR); export const fetchCalendar = createThunk(FETCH_CALENDAR);
export const setCalendarDaysCount = createThunk(SET_CALENDAR_DAYS_COUNT); export const setCalendarDaysCount = createThunk(SET_CALENDAR_DAYS_COUNT);
export const setCalendarIncludeUnmonitored = createThunk(SET_CALENDAR_INCLUDE_UNMONITORED); export const setCalendarFilter = createThunk(SET_CALENDAR_FILTER);
export const setCalendarView = createThunk(SET_CALENDAR_VIEW); export const setCalendarView = createThunk(SET_CALENDAR_VIEW);
export const gotoCalendarToday = createThunk(GOTO_CALENDAR_TODAY); export const gotoCalendarToday = createThunk(GOTO_CALENDAR_TODAY);
export const gotoCalendarPreviousRange = createThunk(GOTO_CALENDAR_PREVIOUS_RANGE); export const gotoCalendarPreviousRange = createThunk(GOTO_CALENDAR_PREVIOUS_RANGE);
@ -196,7 +195,7 @@ export const actionHandlers = handleThunks({
[FETCH_CALENDAR]: function(getState, payload, dispatch) { [FETCH_CALENDAR]: function(getState, payload, dispatch) {
const state = getState(); const state = getState();
const unmonitored = state.calendar.unmonitored; const unmonitored = state.calendar.selectedFilterKey === 'all';
const { const {
time, time,
@ -273,10 +272,10 @@ export const actionHandlers = handleThunks({
dispatch(fetchCalendar({ time, view })); dispatch(fetchCalendar({ time, view }));
}, },
[SET_CALENDAR_INCLUDE_UNMONITORED]: function(getState, payload, dispatch) { [SET_CALENDAR_FILTER]: function(getState, payload, dispatch) {
dispatch(set({ dispatch(set({
section, section,
unmonitored: payload.unmonitored selectedFilterKey: payload.selectedFilterKey
})); }));
const state = getState(); const state = getState();
@ -340,8 +339,8 @@ export const reducers = createHandleActions({
[CLEAR_CALENDAR]: (state) => { [CLEAR_CALENDAR]: (state) => {
const { const {
view, view,
unmonitored,
showUpcoming, showUpcoming,
selectedFilterKey,
...otherDefaultState ...otherDefaultState
} = defaultState; } = defaultState;

Loading…
Cancel
Save