@@ -17,10 +17,12 @@ import {
1717import "@/components/corpus-chooser/corpus-time-graph"
1818import "@/components/corpus-chooser/info-box"
1919import "@/components/corpus-chooser/tree"
20+ import "@/services/store"
2021import { RootScope } from "@/root-scope.types"
2122import { LocationService } from "@/urlparams"
2223import { CorpusTransformed } from "@/settings/config-transformed.types"
2324import { LangString } from "@/i18n/types"
25+ import { StoreService } from "@/services/store"
2426
2527type CorpusChooserController = IController & {
2628 credentials : string [ ]
@@ -131,8 +133,8 @@ angular.module("korpApp").component("corpusChooser", {
131133 bindings : { } ,
132134 controller : [
133135 "$rootScope" ,
134- "$location " ,
135- function ( $rootScope : RootScope , $location : LocationService ) {
136+ "store " ,
137+ function ( $rootScope : RootScope , store : StoreService ) {
136138 const $ctrl = this as CorpusChooserController
137139
138140 statemachine . listen ( "login" , function ( ) {
@@ -187,14 +189,7 @@ angular.module("korpApp").component("corpusChooser", {
187189 select ( corpusIds , true )
188190
189191 // Sync when corpus selection is modified elsewhere.
190- $rootScope . $watch (
191- ( ) => $location . search ( ) . corpus ,
192- ( corpusIdsComma ) => {
193- const corpusIds = corpusIdsComma ? corpusIdsComma . split ( "," ) : [ ]
194- select ( corpusIds )
195- }
196- )
197- $rootScope . $on ( "corpuschooserchange" , ( e , selected ) => select ( selected ) )
192+ store . watch ( "selectedCorpusIds" , updateSelection )
198193 } )
199194
200195 $ctrl . updateSelectedCount = ( selection ) => {
@@ -233,14 +228,21 @@ angular.module("korpApp").component("corpusChooser", {
233228 }
234229 }
235230
231+ /** Apply a selection made locally */
236232 function select ( corporaIds : string [ ] , force ?: boolean ) {
237233 // Exit if no actual change
238234 const selectedIds = settings . corpusListing . mapSelectedCorpora ( ( corpus ) => corpus . id )
239235 if ( ! force && _ . isEqual ( corporaIds , selectedIds ) ) return
240236
237+ const selection = updateSelection ( corporaIds )
238+ store . set ( "selectedCorpusIds" , selection )
239+ }
240+
241+ /** Filter requested corpus selection and update internal state */
242+ function updateSelection ( corpusIds : string [ ] ) : string [ ] {
241243 const selection = filterCorporaOnCredentials (
242244 Object . values ( settings . corpora ) ,
243- corporaIds ,
245+ corpusIds ,
244246 $ctrl . credentials
245247 )
246248
@@ -251,9 +253,7 @@ angular.module("korpApp").component("corpusChooser", {
251253 $ctrl . firstCorpus = settings . corpora [ selection [ 0 ] ] . title
252254 }
253255
254- settings . corpusListing . select ( selection )
255- $rootScope . $broadcast ( "corpuschooserchange" , selection )
256- $location . search ( "corpus" , selection . join ( "," ) )
256+ return selection
257257 }
258258
259259 $ctrl . onShowInfo = ( node : ChooserFolderSub | CorpusTransformed ) => {
0 commit comments