@@ -2,6 +2,7 @@ import { writable } from 'svelte/store';
2
2
import { getDiagramType } from '$lib/utils' ;
3
3
import { loading } from './loading' ;
4
4
import type { MCDocument , MermaidChart } from '$lib/mermaidChartApi' ;
5
+ import { showUserMessage } from './messaging' ;
5
6
6
7
interface MCDocumentDB {
7
8
filterStr : string ;
@@ -15,6 +16,17 @@ const defaultDB: MCDocumentDB = {
15
16
documents : { }
16
17
} ;
17
18
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
+
18
30
function createDocumentStore ( ) {
19
31
const { subscribe, set, update } = writable ( defaultDB ) ;
20
32
return {
@@ -24,8 +36,15 @@ function createDocumentStore() {
24
36
const documents : MCDocument [ ] = [ ] ;
25
37
26
38
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
+ }
29
48
}
30
49
31
50
const res = update ( ( documentDB ) => {
@@ -37,6 +56,7 @@ function createDocumentStore() {
37
56
document . diagramType = getDiagramType ( document . code ) ;
38
57
documentDB . documents [ document . documentID ] = document ;
39
58
documentDB . documentIds . push ( document . documentID ) ;
59
+ addToFullList ( document ) ;
40
60
}
41
61
}
42
62
documentDB . documentIds . sort ( ( a , b ) => doSort ( a , b , 'updatedAt' , documentDB . documents , 'asc' ) ) ;
0 commit comments