Skip to content
This repository was archived by the owner on Feb 6, 2024. It is now read-only.

Commit f4ac017

Browse files
fix: clean offline slides
1 parent d16f5bb commit f4ac017

File tree

2 files changed

+12
-23
lines changed

2 files changed

+12
-23
lines changed

studio/src/app/utils/editor/firestore.utils.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export class FirestoreUtils {
2-
static filterDelete<T>(obj: T): T {
2+
static filterDelete<T>(obj: T, replaceWithNull: boolean = false): T {
33
if (typeof obj !== 'object' || Array.isArray(obj)) {
44
return obj;
55
}
@@ -13,6 +13,8 @@ export class FirestoreUtils {
1313
// We don't want to keep empty leaf {}
1414
if (Object.keys(value).length > 0) {
1515
res[key] = value;
16+
} else if (replaceWithNull) {
17+
res[key] = null;
1618
}
1719
} else {
1820
res[key] = value;

studio/src/app/utils/editor/offline.utils.tsx

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,18 @@ import {DeckAttributes} from '../../models/data/deck';
66
import {FirestoreUtils} from './firestore.utils';
77

88
export class OfflineUtils {
9-
static cleanAttributes(attributes: SlideAttributes | DeckAttributes): Promise<SlideAttributes | DeckAttributes> {
10-
return new Promise<SlideAttributes | DeckAttributes>((resolve) => {
11-
if (!attributes || attributes === undefined) {
12-
resolve(null);
13-
return;
14-
}
9+
static async cleanAttributes(attributes: SlideAttributes | DeckAttributes): Promise<SlideAttributes | DeckAttributes> {
10+
if (!attributes || attributes === undefined) {
11+
return null;
12+
}
1513

16-
const keys: string[] = Object.keys(attributes);
14+
const keys: string[] = Object.keys(attributes);
1715

18-
if (!keys || keys.length <= 0) {
19-
resolve(null);
20-
return;
21-
}
16+
if (!keys || keys.length <= 0) {
17+
return null;
18+
}
2219

23-
keys.forEach((key: string) => {
24-
const attr = attributes[key];
25-
26-
// Replace Firestore "to delete fields" with null values
27-
if (FirestoreUtils.shouldAttributeBeCleaned(attr)) {
28-
attributes[key] = null;
29-
}
30-
});
31-
32-
resolve(attributes);
33-
});
20+
return FirestoreUtils.filterDelete(attributes, true);
3421
}
3522

3623
static prepareAttributes(attributes: SlideAttributes | DeckAttributes): Promise<SlideAttributes | DeckAttributes> {

0 commit comments

Comments
 (0)