Update according to etebase-js changes.

master
Tom Hacohen 4 years ago
parent 7ad14407ca
commit 82a3233a43

@ -26,13 +26,13 @@ import { CachedCollection } from "../Pim/helpers";
import LoadingIndicator from "../widgets/LoadingIndicator"; import LoadingIndicator from "../widgets/LoadingIndicator";
export interface CachedItem { export interface CachedItem {
item: Etebase.CollectionItem; item: Etebase.Item;
metadata: Etebase.CollectionItemMetadata; metadata: Etebase.ItemMetadata;
content: string; 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
async function decryptItems(items: Map<string, Map<string, Etebase.CollectionItem>>) { async function decryptItems(items: Map<string, Map<string, Etebase.Item>>) {
const entries: Map<string, Map<string, CachedItem>> = new Map(); const entries: Map<string, Map<string, CachedItem>> = new Map();
for (const [colUid, col] of items.entries()) { for (const [colUid, col] of items.entries()) {
const cur = new Map(); const cur = new Map();

@ -51,7 +51,7 @@ export function getDecryptCollectionsFunction(_colType?: string) {
export function getDecryptItemsFunction<T extends PimType>(_colType: string, parseFunc: (str: string) => T) { export function getDecryptItemsFunction<T extends PimType>(_colType: string, parseFunc: (str: string) => T) {
return memoize( return memoize(
async function (items: Map<string, Map<string, Etebase.CollectionItem>>) { async function (items: Map<string, Map<string, Etebase.Item>>) {
const entries: Map<string, Map<string, T>> = new Map(); const entries: Map<string, Map<string, T>> = new Map();
if (items) { if (items) {
for (const [colUid, col] of items.entries()) { for (const [colUid, col] of items.entries()) {
@ -76,7 +76,7 @@ export function getDecryptItemsFunction<T extends PimType>(_colType: string, par
); );
} }
export async function itemSave(etebase: Etebase.Account, collection: Etebase.Collection, items: Map<string, Map<string, Etebase.CollectionItem>>, item: PimType, collectionUid: string, originalItem?: PimType): Promise<void> { export async function itemSave(etebase: Etebase.Account, collection: Etebase.Collection, items: Map<string, Map<string, Etebase.Item>>, item: PimType, collectionUid: string, originalItem?: PimType): Promise<void> {
const itemUid = originalItem?.itemUid; const itemUid = originalItem?.itemUid;
const colMgr = getCollectionManager(etebase); const colMgr = getCollectionManager(etebase);
const itemMgr = colMgr.getItemManager(collection); const itemMgr = colMgr.getItemManager(collection);
@ -94,7 +94,7 @@ export async function itemSave(etebase: Etebase.Account, collection: Etebase.Col
await eteItem.setMeta(meta); await eteItem.setMeta(meta);
} else { } else {
// New // New
const meta: Etebase.CollectionItemMetadata = { const meta: Etebase.ItemMetadata = {
mtime, mtime,
name: item.uid, name: item.uid,
}; };
@ -104,7 +104,7 @@ export async function itemSave(etebase: Etebase.Account, collection: Etebase.Col
await asyncDispatch(itemBatch(collection, itemMgr, [eteItem])); await asyncDispatch(itemBatch(collection, itemMgr, [eteItem]));
} }
export async function itemDelete(etebase: Etebase.Account, collection: Etebase.Collection, items: Map<string, Map<string, Etebase.CollectionItem>>, item: PimType, collectionUid: string) { export async function itemDelete(etebase: Etebase.Account, collection: Etebase.Collection, items: Map<string, Map<string, Etebase.Item>>, item: PimType, collectionUid: string) {
const itemUid = item.itemUid!; const itemUid = item.itemUid!;
const colMgr = getCollectionManager(etebase); const colMgr = getCollectionManager(etebase);
const itemMgr = colMgr.getItemManager(collection); const itemMgr = colMgr.getItemManager(collection);

@ -28,8 +28,8 @@ export const getCollectionsByType = memoize(async function (cachedCollections: C
return ret; return ret;
}, { length: 2 }); }, { length: 2 });
export const getItems = memoize(async function (cachedItems: CacheItems, itemMgr: Etebase.CollectionItemManager) { export const getItems = memoize(async function (cachedItems: CacheItems, itemMgr: Etebase.ItemManager) {
const ret = new Map<string, Etebase.CollectionItem>(); const ret = new Map<string, Etebase.Item>();
for (const cached of cachedItems.values()) { for (const cached of cachedItems.values()) {
const item = await itemMgr.cacheLoad(cached); const item = await itemMgr.cacheLoad(cached);
ret.set(item.uid, item); ret.set(item.uid, item);
@ -40,7 +40,7 @@ export const getItems = memoize(async function (cachedItems: CacheItems, itemMgr
export const getItemsByType = memoize(async function (cachedCollections: CacheCollectionsData, cachedItems: CacheItemsData, colType: string, etebase: Etebase.Account) { export const getItemsByType = memoize(async function (cachedCollections: CacheCollectionsData, cachedItems: CacheItemsData, colType: string, etebase: Etebase.Account) {
const colMgr = getCollectionManager(etebase); const colMgr = getCollectionManager(etebase);
const collections = await getCollectionsByType(cachedCollections, colType, etebase); const collections = await getCollectionsByType(cachedCollections, colType, etebase);
const ret = new Map<string, Map<string, Etebase.CollectionItem>>(); const ret = new Map<string, Map<string, Etebase.Item>>();
for (const col of collections) { for (const col of collections) {
const itemMgr = colMgr.getItemManager(col); const itemMgr = colMgr.getItemManager(col);
const cachedColItems = cachedItems.get(col.uid); const cachedColItems = cachedItems.get(col.uid);

@ -81,10 +81,10 @@ export const collectionUpload = createAction(
export const setCacheItem = createAction( export const setCacheItem = createAction(
"SET_CACHE_ITEM", "SET_CACHE_ITEM",
async (_col: Etebase.Collection, itemMgr: Etebase.CollectionItemManager, item: Etebase.CollectionItem) => { async (_col: Etebase.Collection, itemMgr: Etebase.ItemManager, item: Etebase.Item) => {
return await itemMgr.cacheSave(item); return await itemMgr.cacheSave(item);
}, },
(col: Etebase.Collection, _itemMgr: Etebase.CollectionItemManager, item: Etebase.CollectionItem) => { (col: Etebase.Collection, _itemMgr: Etebase.ItemManager, item: Etebase.Item) => {
return { return {
colUid: col.uid, colUid: col.uid,
itemUid: item.uid, itemUid: item.uid,
@ -95,10 +95,10 @@ export const setCacheItem = createAction(
export const unsetCacheItem = createAction( export const unsetCacheItem = createAction(
"UNSET_CACHE_ITEM", "UNSET_CACHE_ITEM",
(_colUid: string, _itemMgr: Etebase.CollectionItemManager, itemUid: string) => { (_colUid: string, _itemMgr: Etebase.ItemManager, itemUid: string) => {
return itemUid; return itemUid;
}, },
(colUid: string, _itemMgr: Etebase.CollectionItemManager, itemUid: string) => { (colUid: string, _itemMgr: Etebase.ItemManager, itemUid: string) => {
return { return {
colUid, colUid,
itemUid, itemUid,
@ -109,14 +109,14 @@ export const unsetCacheItem = createAction(
export const setCacheItemMulti = createAction( export const setCacheItemMulti = createAction(
"SET_CACHE_ITEM_MULTI", "SET_CACHE_ITEM_MULTI",
async (_colUid: string, itemMgr: Etebase.CollectionItemManager, items: Etebase.CollectionItem[]) => { async (_colUid: string, itemMgr: Etebase.ItemManager, items: Etebase.Item[]) => {
const ret = []; const ret = [];
for (const item of items) { for (const item of items) {
ret.push(await itemMgr.cacheSave(item)); ret.push(await itemMgr.cacheSave(item));
} }
return ret; return ret;
}, },
(colUid: string, _itemMgr: Etebase.CollectionItemManager, items: Etebase.CollectionItem[], _deps?: Etebase.CollectionItem[]) => { (colUid: string, _itemMgr: Etebase.ItemManager, items: Etebase.Item[], _deps?: Etebase.Item[]) => {
return { return {
colUid, colUid,
items: items, items: items,
@ -126,7 +126,7 @@ export const setCacheItemMulti = createAction(
export const itemBatch = createAction( export const itemBatch = createAction(
"ITEM_BATCH", "ITEM_BATCH",
async (_col: Etebase.Collection, itemMgr: Etebase.CollectionItemManager, items: Etebase.CollectionItem[], deps?: Etebase.CollectionItem[]) => { async (_col: Etebase.Collection, itemMgr: Etebase.ItemManager, items: Etebase.Item[], deps?: Etebase.Item[]) => {
await itemMgr.batch(items, deps); await itemMgr.batch(items, deps);
const ret = []; const ret = [];
for (const item of items) { for (const item of items) {
@ -134,7 +134,7 @@ export const itemBatch = createAction(
} }
return ret; return ret;
}, },
(col: Etebase.Collection, _itemMgr: Etebase.CollectionItemManager, items: Etebase.CollectionItem[], _deps?: Etebase.CollectionItem[]) => { (col: Etebase.Collection, _itemMgr: Etebase.ItemManager, items: Etebase.Item[], _deps?: Etebase.Item[]) => {
return { return {
colUid: col.uid, colUid: col.uid,
items: items, items: items,

@ -137,7 +137,7 @@ export const items = handleActions(
actions.setCacheItemMulti actions.setCacheItemMulti
).toString()]: (state: CacheItemsData, action_: any) => { ).toString()]: (state: CacheItemsData, action_: any) => {
// Fails without it for some reason // Fails without it for some reason
const action = action_ as ActionMeta<CacheItem[], { colUid: string, items: Etebase.CollectionItem[] }>; const action = action_ as ActionMeta<CacheItem[], { colUid: string, items: Etebase.Item[] }>;
if (action.payload !== undefined) { if (action.payload !== undefined) {
return state.withMutations((state) => { return state.withMutations((state) => {
let i = 0; let i = 0;

Loading…
Cancel
Save