@@ -61,23 +61,35 @@ class AppState {
6161 mobx . makeObservable ( this ) ;
6262 }
6363
64+ // change the currently selected file in the database
65+ @mobx . action
66+ setSelectedFilePath ( path : string ) {
67+ this . selectedFilePath = path ;
68+ }
69+
6470 // open a new database
6571 @mobx . action
6672 async openDatabase ( filename : string ) : Promise < void > {
6773 ++ this . isLoadingDatabase ;
6874 try {
6975 this . selectedFilePath = "" ;
7076 await this . _database . open ( filename ) ;
71- this . databasePath = filename ;
72- this . databaseError = "" ;
77+ mobx . runInAction ( ( ) => {
78+ this . databasePath = filename ;
79+ this . databaseError = "" ;
80+ } ) ;
7381 }
7482 catch ( err ) {
75- this . databasePath = filename ;
76- this . databaseError = ( err as any ) . message || String ( err ) ;
83+ mobx . runInAction ( ( ) => {
84+ this . databasePath = filename ;
85+ this . databaseError = ( err as any ) . message || String ( err ) ;
86+ } )
7787 throw err ;
7888 }
7989 finally {
80- -- this . isLoadingDatabase ;
90+ mobx . runInAction ( ( ) => {
91+ -- this . isLoadingDatabase ;
92+ } ) ;
8193 }
8294 }
8395
@@ -91,22 +103,10 @@ class AppState {
91103 return this . _database . categoryNames ;
92104 }
93105
94- // fetch files at \param rootPath
95- @mobx . action
96- async fetchFiles ( rootPath : string ) : Promise < File [ ] > {
97- ++ this . isLoadingFiles ;
98- try {
99- return await this . _database . fetchFiles ( rootPath ) ;
100- }
101- finally {
102- -- this . isLoadingFiles ;
103- }
104- }
105-
106- // create a normalized abs path of the given file path.
106+ // get a normalized abs path for the given file path.
107107 // When the file path is relative, prefix it with the DB path,
108108 // else return the path as it is, normalized.
109- async fileAbsPath ( filePath : string ) : Promise < string > {
109+ async databaseFilePath ( filePath : string ) : Promise < string > {
110110 if ( ! filePath ) {
111111 return "" ;
112112 }
@@ -118,21 +118,40 @@ class AppState {
118118 return absPath ;
119119 }
120120
121+ // fetch files at \param rootPath
122+ @mobx . action
123+ async fetchFiles ( rootPath : string ) : Promise < File [ ] > {
124+ ++ this . isLoadingFiles ;
125+ try {
126+ return await this . _database . fetchFiles ( rootPath ) ;
127+ }
128+ finally {
129+ mobx . runInAction ( ( ) => {
130+ -- this . isLoadingFiles ;
131+ } ) ;
132+ }
133+ }
134+
121135 // calculate a mono waveform for selected file
136+ @mobx . action
122137 async generateWaveform ( width : number ) : Promise < WaveformPoint [ ] > {
123138 if ( ! this . databasePath || this . databaseError || ! this . selectedFilePath ) {
124139 return Promise . reject ( new Error ( "No file selected" ) ) ;
125140 }
126141
127142 ++ this . isGeneratingWaveform ;
128143 try {
129- let filePath = await this . fileAbsPath ( this . selectedFilePath ) ;
144+ let filePath = await this . databaseFilePath ( this . selectedFilePath ) ;
130145 let results = await generateWaveform ( filePath , width ) ;
131- -- this . isGeneratingWaveform ;
146+ mobx . runInAction ( ( ) => {
147+ -- this . isGeneratingWaveform ;
148+ } ) ;
132149 return results ;
133150
134151 } catch ( err ) {
135- -- this . isGeneratingWaveform ;
152+ mobx . runInAction ( ( ) => {
153+ -- this . isGeneratingWaveform ;
154+ } ) ;
136155 throw err ;
137156 }
138157 }
@@ -146,7 +165,9 @@ class AppState {
146165 return await createPlot ( this . databasePath , this . mapPerplexity , this . mapTheta , this . mapEpochs ) ;
147166 }
148167 finally {
149- -- this . isGeneratingMap ;
168+ mobx . runInAction ( ( ) => {
169+ -- this . isGeneratingMap ;
170+ } ) ;
150171 }
151172 }
152173
0 commit comments