Skip to content

Commit 75439f4

Browse files
committedMar 26, 2024
Updated document call to short cut loading screen if error.
1 parent 581f159 commit 75439f4

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed
 

‎packages/office/src/lib/client/stores/documents.ts

+22-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { writable } from 'svelte/store';
22
import { getDiagramType } from '$lib/utils';
33
import { loading } from './loading';
44
import type { MCDocument, MermaidChart } from '$lib/mermaidChartApi';
5+
import { showUserMessage } from './messaging';
56

67
interface MCDocumentDB {
78
filterStr: string;
@@ -15,6 +16,17 @@ const defaultDB: MCDocumentDB = {
1516
documents: {}
1617
};
1718

19+
const fullDocumentList: MCDocument[] = [];
20+
21+
const addToFullList = (document: MCDocument) => {
22+
const existingDoc = fullDocumentList.find((doc) => doc.documentID === document.documentID);
23+
if (existingDoc) {
24+
return
25+
} else {
26+
fullDocumentList.push(document);
27+
}
28+
}
29+
1830
function createDocumentStore() {
1931
const { subscribe, set, update } = writable(defaultDB);
2032
return {
@@ -24,8 +36,15 @@ function createDocumentStore() {
2436
const documents: MCDocument[] = [];
2537

2638
for (const projectID of projectIDList) {
27-
const projectDocuments = await mermaidChartApi.getDocuments(projectID);
28-
documents.push(...projectDocuments);
39+
try {
40+
const projectDocuments = await mermaidChartApi.getDocuments(projectID);
41+
documents.push(...projectDocuments);
42+
} catch {
43+
loading.setState(false, '');
44+
return showUserMessage(
45+
'Failed to load documents for project with ID: ' + projectID,
46+
'error');
47+
}
2948
}
3049

3150
const res = update((documentDB) => {
@@ -37,6 +56,7 @@ function createDocumentStore() {
3756
document.diagramType = getDiagramType(document.code);
3857
documentDB.documents[document.documentID] = document;
3958
documentDB.documentIds.push(document.documentID);
59+
addToFullList(document);
4060
}
4161
}
4262
documentDB.documentIds.sort((a, b) => doSort(a, b, 'updatedAt', documentDB.documents, 'asc'));

0 commit comments

Comments
 (0)
Failed to load comments.