From da95830d9ff10366b6d7efa91040c9ca44595909 Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Fri, 4 Sep 2020 12:10:12 +0300 Subject: [PATCH] CacheItems: don't delete when deleted, just mark as such. This is needed for the change history to work properly. --- src/Collections/CollectionChangeEntries.tsx | 3 ++- src/Pim/helpers.tsx | 3 +++ src/store/actions.ts | 14 -------------- src/store/reducers.ts | 15 +++------------ 4 files changed, 8 insertions(+), 27 deletions(-) diff --git a/src/Collections/CollectionChangeEntries.tsx b/src/Collections/CollectionChangeEntries.tsx index 7427f7d..d25c77e 100644 --- a/src/Collections/CollectionChangeEntries.tsx +++ b/src/Collections/CollectionChangeEntries.tsx @@ -31,7 +31,8 @@ export interface CachedItem { content: string; } -// FIXME: use the ones used by e.g. Contacts/Main so ew share the cache +// FIXME: use the ones used by e.g. Contacts/Main so ew share the cache. +// Only problem though is that we want the deleted items here and not there. async function decryptItems(items: Map>) { const entries: Map> = new Map(); for (const [colUid, col] of items.entries()) { diff --git a/src/Pim/helpers.tsx b/src/Pim/helpers.tsx index 2c128f3..47f432f 100644 --- a/src/Pim/helpers.tsx +++ b/src/Pim/helpers.tsx @@ -58,6 +58,9 @@ export function getDecryptItemsFunction(_colType: string, par const cur = new Map(); entries.set(colUid, cur); for (const item of col.values()) { + if (item.isDeleted) { + continue; + } try { const contact = parseFunc(await item.getContent(Etebase.OutputFormat.String)); contact.collectionUid = colUid; diff --git a/src/store/actions.ts b/src/store/actions.ts index aebd506..addc61b 100644 --- a/src/store/actions.ts +++ b/src/store/actions.ts @@ -93,20 +93,6 @@ export const setCacheItem = createAction( } ); -export const unsetCacheItem = createAction( - "UNSET_CACHE_ITEM", - (_colUid: string, _itemMgr: Etebase.ItemManager, itemUid: string) => { - return itemUid; - }, - (colUid: string, _itemMgr: Etebase.ItemManager, itemUid: string) => { - return { - colUid, - itemUid, - deleted: true, - }; - } -); - export const setCacheItemMulti = createAction( "SET_CACHE_ITEM_MULTI", async (_colUid: string, itemMgr: Etebase.ItemManager, items: Etebase.Item[]) => { diff --git a/src/store/reducers.ts b/src/store/reducers.ts index 2287e0c..a062e3a 100644 --- a/src/store/reducers.ts +++ b/src/store/reducers.ts @@ -120,15 +120,10 @@ export const collections = handleActions( export const items = handleActions( { [combineActions( - actions.setCacheItem, - actions.unsetCacheItem + actions.setCacheItem ).toString()]: (state: CacheItemsData, action: ActionMeta) => { if (action.payload !== undefined) { - if (action.meta.deleted) { - return state.removeIn([action.meta.colUid, action.meta.itemUid]); - } else { - return state.setIn([action.meta.colUid, action.meta.itemUid], action.payload); - } + return state.setIn([action.meta.colUid, action.meta.itemUid], action.payload); } return state; }, @@ -142,11 +137,7 @@ export const items = handleActions( return state.withMutations((state) => { let i = 0; for (const item of action.meta.items) { - if (item.isDeleted) { - state.removeIn([action.meta.colUid, item.uid]); - } else { - state.setIn([action.meta.colUid, item.uid], action.payload[i]); - } + state.setIn([action.meta.colUid, item.uid], action.payload[i]); i++; } });