2018-02-08 18:50:19 +00:00
|
|
|
// @flow
|
|
|
|
|
2018-05-14 19:05:41 +00:00
|
|
|
import { APP_WILL_MOUNT } from '../app';
|
|
|
|
import { ReducerRegistry, set } from '../base/redux';
|
|
|
|
import { PersistenceRegistry } from '../base/storage';
|
2018-02-08 18:50:19 +00:00
|
|
|
|
2018-03-20 13:51:51 +00:00
|
|
|
import {
|
2018-04-16 02:04:57 +00:00
|
|
|
SET_CALENDAR_AUTHORIZATION,
|
|
|
|
SET_CALENDAR_EVENTS
|
2018-03-20 13:51:51 +00:00
|
|
|
} from './actionTypes';
|
2018-04-16 16:39:26 +00:00
|
|
|
import { CALENDAR_ENABLED } from './constants';
|
2018-02-08 18:50:19 +00:00
|
|
|
|
|
|
|
const DEFAULT_STATE = {
|
2018-03-20 13:51:51 +00:00
|
|
|
/**
|
|
|
|
* Note: If features/calendar-sync ever gets persisted, do not persist the
|
2018-04-16 02:04:57 +00:00
|
|
|
* authorization value as it's needed to remain a runtime value to see if we
|
|
|
|
* need to re-request the calendar permission from the user.
|
2018-03-20 13:51:51 +00:00
|
|
|
*/
|
2018-04-16 02:04:57 +00:00
|
|
|
authorization: undefined,
|
2018-05-11 15:29:09 +00:00
|
|
|
events: []
|
2018-02-08 18:50:19 +00:00
|
|
|
};
|
2018-02-14 16:21:52 +00:00
|
|
|
|
2018-02-08 18:50:19 +00:00
|
|
|
const STORE_NAME = 'features/calendar-sync';
|
|
|
|
|
2018-05-14 19:05:41 +00:00
|
|
|
// XXX For legacy purposes, read any {@code knownDomains} persisted by the
|
|
|
|
// feature calendar-sync.
|
|
|
|
CALENDAR_ENABLED
|
|
|
|
&& PersistenceRegistry.register(STORE_NAME, {
|
|
|
|
knownDomains: true
|
|
|
|
});
|
|
|
|
|
2018-04-16 16:39:26 +00:00
|
|
|
CALENDAR_ENABLED
|
|
|
|
&& ReducerRegistry.register(STORE_NAME, (state = DEFAULT_STATE, action) => {
|
|
|
|
switch (action.type) {
|
2018-05-14 19:05:41 +00:00
|
|
|
case APP_WILL_MOUNT:
|
|
|
|
// For legacy purposes, we've allowed the deserialization of
|
|
|
|
// knownDomains. At this point, it should have already been
|
|
|
|
// translated into the new state format (namely, base/known-domains)
|
|
|
|
// and the app no longer needs it.
|
|
|
|
if (typeof state.knownDomains !== 'undefined') {
|
|
|
|
return set(state, 'knownDomains', undefined);
|
|
|
|
}
|
|
|
|
break;
|
2018-04-16 16:39:26 +00:00
|
|
|
|
|
|
|
case SET_CALENDAR_AUTHORIZATION:
|
2018-06-11 17:28:45 +00:00
|
|
|
return set(state, 'authorization', action.authorization);
|
2018-04-16 16:39:26 +00:00
|
|
|
|
|
|
|
case SET_CALENDAR_EVENTS:
|
2018-06-11 17:28:45 +00:00
|
|
|
return set(state, 'events', action.events);
|
2018-04-16 16:39:26 +00:00
|
|
|
}
|
2018-05-14 19:05:41 +00:00
|
|
|
|
|
|
|
return state;
|
2018-04-16 16:39:26 +00:00
|
|
|
});
|