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";
export interface CachedItem {
item: Etebase.CollectionItem;
metadata: Etebase.CollectionItemMetadata;
item: Etebase.Item;
metadata: Etebase.ItemMetadata;
content: string;
}
// 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();
for (const [colUid, col] of items.entries()) {
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) {
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();
if (items) {
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 colMgr = getCollectionManager(etebase);
const itemMgr = colMgr.getItemManager(collection);
@ -94,7 +94,7 @@ export async function itemSave(etebase: Etebase.Account, collection: Etebase.Col
await eteItem.setMeta(meta);
} else {
// New
const meta: Etebase.CollectionItemMetadata = {
const meta: Etebase.ItemMetadata = {
mtime,
name: item.uid,
};
@ -104,7 +104,7 @@ export async function itemSave(etebase: Etebase.Account, collection: Etebase.Col
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 colMgr = getCollectionManager(etebase);
const itemMgr = colMgr.getItemManager(collection);

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

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

@ -137,7 +137,7 @@ export const items = handleActions(
actions.setCacheItemMulti
).toString()]: (state: CacheItemsData, action_: any) => {
// 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) {
return state.withMutations((state) => {
let i = 0;

Loading…
Cancel
Save