Update etebase dep and adjust code accordingly.

master
Tom Hacohen 4 years ago
parent 55cae0962d
commit f142b6081a

@ -9,7 +9,7 @@
"@material-ui/lab": "^4.0.0-alpha.56", "@material-ui/lab": "^4.0.0-alpha.56",
"@material-ui/pickers": "^3.2.10", "@material-ui/pickers": "^3.2.10",
"@material-ui/styles": "^4.10.0", "@material-ui/styles": "^4.10.0",
"etebase": "^0.14.0", "etebase": "^0.20.0",
"fuse.js": "^5.0.9-beta", "fuse.js": "^5.0.9-beta",
"ical.js": "^1.4.0", "ical.js": "^1.4.0",
"immutable": "^4.0.0-rc.12", "immutable": "^4.0.0-rc.12",

@ -48,7 +48,7 @@ class Collection extends React.Component<PropsType> {
return ( return (
<React.Fragment> <React.Fragment>
<AppBarOverride title={metadata.name}> <AppBarOverride title={metadata.name!!}>
{isAdmin && {isAdmin &&
<> <>
<IconButton <IconButton

@ -47,9 +47,8 @@ export default function CollectionChangeEntries(props: PropsType) {
const history = useHistory(); const history = useHistory();
const etebase = useCredentials()!; const etebase = useCredentials()!;
const { collection, metadata } = props.collection; const { collection, collectionType } = props.collection;
const colType = metadata.type; const items = useItems(etebase, collectionType);
const items = useItems(etebase, colType);
React.useEffect(() => { React.useEffect(() => {
if (items) { if (items) {
@ -71,7 +70,7 @@ export default function CollectionChangeEntries(props: PropsType) {
}); });
let changelogRoute = ""; let changelogRoute = "";
switch (colType) { switch (collectionType) {
case "etebase.vevent": { case "etebase.vevent": {
changelogRoute = "pim.events._id.log"; changelogRoute = "pim.events._id.log";
break; break;

@ -40,19 +40,21 @@ interface FormErrors {
export default function CollectionEdit(props: PropsType) { export default function CollectionEdit(props: PropsType) {
const [errors, setErrors] = React.useState<FormErrors>({}); const [errors, setErrors] = React.useState<FormErrors>({});
const [showDeleteDialog, setShowDeleteDialog] = React.useState(false); const [showDeleteDialog, setShowDeleteDialog] = React.useState(false);
const [info, setInfo] = React.useState<Etebase.CollectionMetadata>(); const [colType, setColType] = React.useState("");
const [info, setInfo] = React.useState<Etebase.ItemMetadata>();
const [selectedColor, setSelectedColor] = React.useState(""); const [selectedColor, setSelectedColor] = React.useState("");
const etebase = useCredentials()!; const etebase = useCredentials()!;
React.useEffect(() => { React.useEffect(() => {
if (props.collection !== undefined) { if (props.collection !== undefined) {
setColType(props.collection.collectionType);
setInfo(props.collection.metadata); setInfo(props.collection.metadata);
if (props.collection.metadata.color) { if (props.collection.metadata.color) {
setSelectedColor(props.collection.metadata.color); setSelectedColor(props.collection.metadata.color);
} }
} else { } else {
setColType("etebase.vcard");
setInfo({ setInfo({
type: "etebase.vcard",
name: "", name: "",
description: "", description: "",
}); });
@ -98,7 +100,7 @@ export default function CollectionEdit(props: PropsType) {
collection = props.collection.collection; collection = props.collection.collection;
await collection.setMeta(meta); await collection.setMeta(meta);
} else { } else {
collection = await colMgr.create(meta, ""); collection = await colMgr.create(colType, meta, "");
} }
onSave(collection); onSave(collection);
@ -111,7 +113,7 @@ export default function CollectionEdit(props: PropsType) {
const { collection, onDelete, onCancel } = props; const { collection, onDelete, onCancel } = props;
const item = collection?.metadata; const item = collection?.metadata;
const pageTitle = (item !== undefined) ? item.name : "New Collection"; const pageTitle = (item !== undefined) ? item.name! : "New Collection";
const styles = { const styles = {
fullWidth: { fullWidth: {
@ -130,7 +132,7 @@ export default function CollectionEdit(props: PropsType) {
"etebase.vtodo": "Task List", "etebase.vtodo": "Task List",
}; };
let collectionColorBox: React.ReactNode; let collectionColorBox: React.ReactNode;
switch (info.type) { switch (colType) {
case "etebase.vevent": case "etebase.vevent":
case "etebase.vtodo": case "etebase.vtodo":
collectionColorBox = ( collectionColorBox = (
@ -156,8 +158,8 @@ export default function CollectionEdit(props: PropsType) {
<Select <Select
name="type" name="type"
required required
value={info.type} value={colType}
onChange={(event: React.ChangeEvent<{ value: string }>) => setInfo({ ...info, type: event.target.value })} onChange={(event: React.ChangeEvent<{ value: string }>) => setColType(event.target.value)}
> >
{Object.keys(colTypes).map((x) => ( {Object.keys(colTypes).map((x) => (
<MenuItem key={x} value={x}>{colTypes[x]}</MenuItem> <MenuItem key={x} value={x}>{colTypes[x]}</MenuItem>

@ -35,13 +35,14 @@ export default function CollectionImport(props: PropsType) {
} }
for (const col of props.collections) { for (const col of props.collections) {
if (collectionMap[col.metadata.type]) { const colType = col.collectionType;
const supportsColor = (["etebase.vevent", "etebase.vtodo"].includes(col.metadata.type)); if (collectionMap[colType]) {
const supportsColor = (["etebase.vevent", "etebase.vtodo"].includes(colType));
const colorBox = (supportsColor) ? ( const colorBox = (supportsColor) ? (
<ColorBox size={24} color={col.metadata.color || defaultColor} /> <ColorBox size={24} color={col.metadata.color || defaultColor} />
) : undefined; ) : undefined;
collectionMap[col.metadata.type].push(( collectionMap[colType].push((
<ListItem key={col.collection.uid} rightIcon={colorBox} insetChildren <ListItem key={col.collection.uid} rightIcon={colorBox} insetChildren
onClick={() => colClicked(col.collection.uid)}> onClick={() => colClicked(col.collection.uid)}>
{col.metadata.name} {col.metadata.name}

@ -38,13 +38,14 @@ export default function CollectionList(props: PropsType) {
} }
for (const col of props.collections) { for (const col of props.collections) {
if (collectionMap[col.metadata.type]) { const colType = col.collectionType;
const supportsColor = (["etebase.vevent", "etebase.vtodo"].includes(col.metadata.type)); if (collectionMap[colType]) {
const supportsColor = (["etebase.vevent", "etebase.vtodo"].includes(colType));
const colorBox = (supportsColor) ? ( const colorBox = (supportsColor) ? (
<ColorBox size={24} color={col.metadata.color || defaultColor} /> <ColorBox size={24} color={col.metadata.color || defaultColor} />
) : undefined; ) : undefined;
collectionMap[col.metadata.type].push(( collectionMap[colType].push((
<ListItem key={col.collection.uid} rightIcon={colorBox} insetChildren <ListItem key={col.collection.uid} rightIcon={colorBox} insetChildren
onClick={() => colClicked(col.collection.uid)}> onClick={() => colClicked(col.collection.uid)}>
{col.metadata.name} {col.metadata.name}

@ -158,17 +158,17 @@ export default function ImportDialog(props: PropsType) {
} }
} }
const { metadata } = props.collection; const { collectionType } = props.collection;
let acceptTypes; let acceptTypes;
let dropFunction; let dropFunction;
if (metadata.type === "etebase.vcard") { if (collectionType === "etebase.vcard") {
acceptTypes = ["text/vcard", "text/directory", "text/x-vcard", ".vcf"]; acceptTypes = ["text/vcard", "text/directory", "text/x-vcard", ".vcf"];
dropFunction = onFileDropContact; dropFunction = onFileDropContact;
} else if (metadata.type === "etebase.vevent") { } else if (collectionType === "etebase.vevent") {
acceptTypes = ["text/calendar", ".ics", ".ical"]; acceptTypes = ["text/calendar", ".ics", ".ical"];
dropFunction = onFileDropEvent; dropFunction = onFileDropEvent;
} else if (metadata.type === "etebase.vtodo") { } else if (collectionType === "etebase.vtodo") {
acceptTypes = ["text/calendar", ".ics", ".ical"]; acceptTypes = ["text/calendar", ".ics", ".ical"];
dropFunction = onFileDropTask; dropFunction = onFileDropTask;
} }

@ -56,8 +56,8 @@ export default function ItemChangeHistory(props: PropsType) {
const [entries, setEntries] = React.useState<CachedItem[]>(); const [entries, setEntries] = React.useState<CachedItem[]>();
const [dialog, setDialog] = React.useState<CachedItem>(); const [dialog, setDialog] = React.useState<CachedItem>();
const etebase = useCredentials()!; const etebase = useCredentials()!;
const { collection, metadata } = props.collection; const { collection, collectionType } = props.collection;
const items = useItems(etebase, metadata.type); const items = useItems(etebase, collectionType);
const item = items?.get(collection.uid)?.get(props.itemUid); const item = items?.get(collection.uid)?.get(props.itemUid);

@ -18,7 +18,8 @@ export const defaultColor = "#8BC34A";
export interface CachedCollection { export interface CachedCollection {
collection: Etebase.Collection; collection: Etebase.Collection;
metadata: Etebase.CollectionMetadata; metadata: Etebase.ItemMetadata;
collectionType: string;
} }
export function getRawItemNavigationUid(collectionUid: string, itemUid: string) { export function getRawItemNavigationUid(collectionUid: string, itemUid: string) {
@ -40,6 +41,7 @@ export function getDecryptCollectionsFunction(_colType?: string) {
entries.push({ entries.push({
collection, collection,
metadata: await collection.getMeta(), metadata: await collection.getMeta(),
collectionType: await collection.getCollectionType(),
}); });
} catch (e) { } catch (e) {
store.dispatch(appendError(e)); store.dispatch(appendError(e));

@ -59,12 +59,11 @@ function SetupCollectionsPage(props: PagePropsType) {
["etebase.vtodo", "My Tasks"], ["etebase.vtodo", "My Tasks"],
]; ];
for (const [type, name] of types) { for (const [type, name] of types) {
const meta: Etebase.CollectionMetadata = { const meta: Etebase.ItemMetadata = {
type,
name, name,
mtime: (new Date()).getTime(), mtime: (new Date()).getTime(),
}; };
const collection = await colMgr.create(meta, ""); const collection = await colMgr.create(type, meta, "");
await colMgr.upload(collection); await colMgr.upload(collection);
} }

@ -20,8 +20,8 @@ export const getCollectionsByType = memoize(async function (cachedCollections: C
const collections = await getCollections(cachedCollections, etebase); const collections = await getCollections(cachedCollections, etebase);
const ret: Etebase.Collection[] = []; const ret: Etebase.Collection[] = [];
for (const col of collections) { for (const col of collections) {
const meta = await col.getMeta(); const collectionType = await col.getCollectionType();
if (meta.type === colType) { if (collectionType === colType) {
ret.push(col); ret.push(col);
} }
} }

@ -64,10 +64,10 @@ export class SyncManager {
let stoken = syncGeneral?.stoken; let stoken = syncGeneral?.stoken;
let done = false; let done = false;
while (!done) { while (!done) {
const collections = await colMgr.list({ stoken, limit }); const collections = await colMgr.list(this.COLLECTION_TYPES, { stoken, limit });
for (const col of collections.data) { for (const col of collections.data) {
const meta = await col.getMeta(); const collectionType = await col.getCollectionType();
if (this.COLLECTION_TYPES.includes(meta.type)) { if (this.COLLECTION_TYPES.includes(collectionType)) {
store.dispatch(setCacheCollection(colMgr, col)); store.dispatch(setCacheCollection(colMgr, col));
await this.fetchCollection(col); await this.fetchCollection(col);
} }

@ -4644,10 +4644,10 @@ etag@~1.8.1:
resolved "https://registry.yarnpkg.com/etag/-/etag-1.8.1.tgz#41ae2eeb65efa62268aebfea83ac7d79299b0887" resolved "https://registry.yarnpkg.com/etag/-/etag-1.8.1.tgz#41ae2eeb65efa62268aebfea83ac7d79299b0887"
integrity sha1-Qa4u62XvpiJorr/qg6x9eSmbCIc= integrity sha1-Qa4u62XvpiJorr/qg6x9eSmbCIc=
etebase@^0.14.0: etebase@^0.20.0:
version "0.14.0" version "0.20.0"
resolved "https://registry.yarnpkg.com/etebase/-/etebase-0.14.0.tgz#87a7e0c678a6c842aa2c71af46aa0d4a11129441" resolved "https://registry.yarnpkg.com/etebase/-/etebase-0.20.0.tgz#53537d76d71d356d2538c85292ee40ed32fde625"
integrity sha512-PYTgQ1w/qHjazlXoC2XZ7pMccwvIa1Beqv+iY5atwJ4zbxcfqgDgy/ibsOYXftr9h7YHxSnIKuhF5eHLlsh19A== integrity sha512-jmrrflrSG0kLe1ud3FjDishQ93Jx8s72r9xgkDxlVioxRJamJ0mE/+9KjfDRAFjWAzui8LIblOcIDw+NYPfbsA==
dependencies: dependencies:
"@msgpack/msgpack" "^1.12.2" "@msgpack/msgpack" "^1.12.2"
libsodium-wrappers "0.7.6" libsodium-wrappers "0.7.6"

Loading…
Cancel
Save