@@ -23,6 +23,7 @@ interface AppState {
23
23
sampleName : string ;
24
24
backgroundColor : string ;
25
25
textColor : string ;
26
+ isLoading : boolean ;
26
27
setTemplateMarkdown : ( template : string ) => Promise < void > ;
27
28
setEditorValue : ( value : string ) => void ;
28
29
setModelCto : ( model : string ) => Promise < void > ;
@@ -44,8 +45,6 @@ export interface DecompressedData {
44
45
agreementHtml : string ;
45
46
}
46
47
47
- const rebuildDeBounce = debounce ( rebuild , 500 ) ;
48
-
49
48
async function rebuild ( template : string , model : string , dataString : string ) {
50
49
const modelManager = new ModelManager ( { strict : true } ) ;
51
50
modelManager . addCTOModel ( model , undefined , true ) ;
@@ -69,6 +68,11 @@ async function rebuild(template: string, model: string, dataString: string) {
69
68
) ;
70
69
}
71
70
71
+ const rebuildDeBounce = debounce ( async ( template : string , model : string , data : string ) => {
72
+ const result = await rebuild ( template , model , data ) ;
73
+ return result ;
74
+ } , 500 ) ;
75
+
72
76
const useAppStore = create < AppState > ( ) (
73
77
immer (
74
78
devtools ( ( set , get ) => ( {
@@ -83,6 +87,7 @@ const useAppStore = create<AppState>()(
83
87
editorAgreementData : JSON . stringify ( playground . DATA , null , 2 ) ,
84
88
agreementHtml : "" ,
85
89
error : undefined ,
90
+ isLoading : false ,
86
91
samples : SAMPLES ,
87
92
init : async ( ) => {
88
93
const params = new URLSearchParams ( window . location . search ) ;
@@ -108,16 +113,21 @@ const useAppStore = create<AppState>()(
108
113
editorAgreementData : JSON . stringify ( sample . DATA , null , 2 ) ,
109
114
} ) ) ;
110
115
get ( ) . rebuild ( ) ;
111
-
112
116
}
113
117
} ,
114
118
rebuild : async ( ) => {
115
- const { templateMarkdown , modelCto , data } = get ( ) ;
119
+ set ( ( ) => ( { isLoading : true } ) ) ;
116
120
try {
117
- const result = await rebuildDeBounce ( templateMarkdown , modelCto , data ) ;
121
+ const result = await rebuildDeBounce (
122
+ get ( ) . templateMarkdown ,
123
+ get ( ) . modelCto ,
124
+ get ( ) . data
125
+ ) ;
118
126
set ( ( ) => ( { agreementHtml : result , error : undefined } ) ) ;
119
127
} catch ( error : any ) {
120
128
set ( ( ) => ( { error : error instanceof Error ? error . message : 'Unknown error' } ) ) ;
129
+ } finally {
130
+ set ( ( ) => ( { isLoading : false } ) ) ;
121
131
}
122
132
} ,
123
133
setTemplateMarkdown : async ( template : string ) => {
0 commit comments