diff --git a/lib/reducers/entry-reducer.js b/lib/reducers/entry-reducer.js --- a/lib/reducers/entry-reducer.js +++ b/lib/reducers/entry-reducer.js @@ -11,7 +11,6 @@ import _omitBy from 'lodash/fp/omitBy.js'; import _pickBy from 'lodash/fp/pickBy.js'; import _sortBy from 'lodash/fp/sortBy.js'; -import _union from 'lodash/fp/union.js'; import { setClientDBStoreActionType } from '../actions/client-db-store-actions.js'; import { @@ -341,26 +340,21 @@ const entryInfo = action.payload; const localID = entryInfo.localID; invariant(localID, 'localID should be set in CREATE_LOCAL_ENTRY'); - const newEntryInfos = { - ...entryInfos, - [(localID: string)]: entryInfo, - }; - const dayString = dateString( - entryInfo.year, - entryInfo.month, - entryInfo.day, - ); - const newDaysToEntries = { - ...daysToEntries, - [dayString]: _union([localID])(daysToEntries[dayString]), - }; + const ops = [ + { + type: 'replace_entry', + payload: { + id: localID, + entry: entryInfo, + }, + }, + ]; return { entryStore: { - entryInfos: newEntryInfos, - daysToEntries: newDaysToEntries, + ...entryStoreOpsHandlers.processStoreOperations(entryStore, ops), lastUserInteractionCalendar: Date.now(), }, - entryStoreOperations: [], + entryStoreOperations: ops, reportCreationRequests: [], }; } else if (action.type === createEntryActionTypes.success) { @@ -390,12 +384,20 @@ }; } - const ops = mergeNewEntryInfosOps( - rekeyedEntryInfos, - null, - mergeUpdateEntryInfos([], action.payload.updatesResult.viewerUpdates), - newThreadInfos, - ); + const ops = [ + ...mergeNewEntryInfosOps( + rekeyedEntryInfos, + null, + mergeUpdateEntryInfos([], action.payload.updatesResult.viewerUpdates), + newThreadInfos, + ), + { + type: 'remove_entries', + payload: { + ids: [localID], + }, + }, + ]; return { entryStore: { ...entryStoreOpsHandlers.processStoreOperations(entryStore, ops), @@ -446,20 +448,21 @@ reportCreationRequests: [], }; } - const newEntryInfos = { - ...entryInfos, - [payload.id]: { - ...entryInfos[payload.id], - text: payload.dbText, + const ops = [ + { + type: 'replace_entry', + payload: { + id: payload.id, + entry: { + ...entryInfos[payload.id], + text: payload.dbText, + }, + }, }, - }; + ]; return { - entryStore: { - entryInfos: newEntryInfos, - daysToEntries, - lastUserInteractionCalendar, - }, - entryStoreOperations: [], + entryStore: entryStoreOpsHandlers.processStoreOperations(entryStore, ops), + entryStoreOperations: ops, reportCreationRequests: [], }; } else if (action.type === deleteEntryActionTypes.started) { @@ -469,20 +472,24 @@ ? payload.serverID : payload.localID; invariant(id, 'either serverID or localID should be set'); - const newEntryInfos = { - ...entryInfos, - [(id: string)]: { - ...entryInfos[id], - deleted: true, + const ops = [ + { + type: 'replace_entry', + payload: { + id, + entry: { + ...entryInfos[id], + deleted: true, + }, + }, }, - }; + ]; return { entryStore: { - entryInfos: newEntryInfos, - daysToEntries, + ...entryStoreOpsHandlers.processStoreOperations(entryStore, ops), lastUserInteractionCalendar: Date.now(), }, - entryStoreOperations: [], + entryStoreOperations: ops, reportCreationRequests: [], }; } else if (action.type === deleteEntryActionTypes.success) {