Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3382088
D5646.id18582.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
4 KB
Referenced Files
None
Subscribers
None
D5646.id18582.diff
View Options
diff --git a/lib/reducers/draft-reducer.js b/lib/reducers/draft-reducer.js
new file mode 100644
--- /dev/null
+++ b/lib/reducers/draft-reducer.js
@@ -0,0 +1,89 @@
+// @flow
+
+import {
+ moveDraftActionType,
+ setDraftStoreDrafts,
+ updateDraftActionType,
+} from '../actions/draft-actions';
+import {
+ deleteAccountActionTypes,
+ logOutActionTypes,
+} from '../actions/user-actions';
+import type { DraftStore, DraftStoreOperation } from '../types/draft-types';
+import type { BaseAction } from '../types/redux-types';
+import { setNewSessionActionType } from '../utils/action-utils';
+type ReduceDraftStoreResult = {
+ +draftStoreOperations: $ReadOnlyArray<DraftStoreOperation>,
+ +draftStore: DraftStore,
+};
+function reduceDraftStore(
+ draftStore: DraftStore,
+ action: BaseAction,
+): ReduceDraftStoreResult {
+ if (
+ action.type === logOutActionTypes.success ||
+ action.type === deleteAccountActionTypes.success ||
+ (action.type === setNewSessionActionType &&
+ action.payload.sessionChange.cookieInvalidated)
+ ) {
+ return {
+ draftStoreOperations: [],
+ draftStore: { drafts: {} },
+ };
+ } else if (action.type === updateDraftActionType) {
+ const { key, text } = action.payload;
+
+ const draftStoreOperations = [
+ {
+ type: 'update',
+ payload: { key, text },
+ },
+ ];
+ return {
+ draftStoreOperations,
+ draftStore: {
+ ...draftStore,
+ drafts: {
+ ...draftStore.drafts,
+ [key]: text,
+ },
+ },
+ };
+ } else if (action.type === moveDraftActionType) {
+ const { oldKey, newKey } = action.payload;
+
+ const draftStoreOperations = [
+ {
+ type: 'move',
+ payload: { oldKey, newKey },
+ },
+ ];
+
+ const { [oldKey]: text, ...draftsWithoutOldKey } = draftStore.drafts;
+ return {
+ draftStoreOperations,
+ draftStore: {
+ ...draftStore,
+ drafts: {
+ ...draftsWithoutOldKey,
+ [newKey]: text,
+ },
+ },
+ };
+ } else if (action.type === setDraftStoreDrafts) {
+ const drafts = {};
+ for (const dbDraftInfo of action.payload) {
+ drafts[dbDraftInfo.key] = dbDraftInfo.text;
+ }
+ return {
+ draftStoreOperations: [],
+ draftStore: {
+ ...draftStore,
+ drafts: drafts,
+ },
+ };
+ }
+ return { draftStore, draftStoreOperations: [] };
+}
+
+export { reduceDraftStore };
diff --git a/lib/reducers/master-reducer.js b/lib/reducers/master-reducer.js
--- a/lib/reducers/master-reducer.js
+++ b/lib/reducers/master-reducer.js
@@ -11,6 +11,7 @@
import reduceCalendarFilters from './calendar-filters-reducer';
import reduceConnectionInfo from './connection-reducer';
import reduceDataLoaded from './data-loaded-reducer';
+import { reduceDraftStore } from './draft-reducer';
import reduceEnabledApps from './enabled-apps-reducer';
import { reduceEntryInfos } from './entry-reducer';
import reduceLifecycleState from './lifecycle-state-reducer';
@@ -75,10 +76,16 @@
}
}
+ const { draftStore, draftStoreOperations } = reduceDraftStore(
+ state.draftStore,
+ action,
+ );
+
return {
state: {
...state,
navInfo: reduceBaseNavInfo(state.navInfo, action),
+ draftStore,
entryStore,
loadingStatuses: reduceLoadingStatuses(state.loadingStatuses, action),
currentUserInfo: reduceCurrentUserInfo(state.currentUserInfo, action),
@@ -100,6 +107,7 @@
dataLoaded: reduceDataLoaded(state.dataLoaded, action),
},
storeOperations: {
+ draftStoreOperations,
threadStoreOperations,
messageStoreOperations,
},
diff --git a/lib/types/store-ops-types.js b/lib/types/store-ops-types.js
--- a/lib/types/store-ops-types.js
+++ b/lib/types/store-ops-types.js
@@ -1,8 +1,11 @@
// @flow
+
+import type { DraftStoreOperation } from './draft-types';
import type { MessageStoreOperation } from './message-types';
import type { ThreadStoreOperation } from './thread-types';
export type StoreOperations = {
+ +draftStoreOperations: $ReadOnlyArray<DraftStoreOperation>,
+threadStoreOperations: $ReadOnlyArray<ThreadStoreOperation>,
+messageStoreOperations: $ReadOnlyArray<MessageStoreOperation>,
};
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Nov 29, 8:26 AM (20 h, 28 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2596419
Default Alt Text
D5646.id18582.diff (4 KB)
Attached To
Mode
D5646: Implement draft reducer and use it in master reducer
Attached
Detach File
Event Timeline
Log In to Comment