1
1
import { storage } from "../storage" ;
2
- import { type EnrichedList , type List , defaultLists } from "../types/types" ;
2
+ import { type List , defaultLists } from "../types/types" ;
3
3
4
- export function getList ( id : string ) : EnrichedList {
5
- const defaultList = defaultLists . find ( ( l ) => l . id === id ) ;
6
-
7
- if ( defaultList != null ) {
8
- return { ...defaultList , isDefault : true } ;
9
- }
10
-
11
- const userList = storage . getLists ( ) . find ( ( l ) => l . id === id ) ;
12
-
13
- if ( userList != null ) {
14
- return { ...userList , isDefault : false } ;
15
- }
16
-
17
- throw Error ( `Can't find list '${ id } '` ) ;
18
- }
19
-
20
- export function getActiveList ( ) : EnrichedList {
21
- const { activeList } = storage . getConfig ( ) ;
22
- return getList ( activeList ) ;
4
+ export function getActiveList ( ) : { activeList : List ; activeListIsDefault : boolean } {
5
+ const [ activeList , activeListIsDefault ] = getListInternal ( storage . getConfig ( ) . activeList ) ;
6
+ return { activeList, activeListIsDefault } ;
23
7
}
24
8
25
9
export function tryGetListByNameIgnoreCase ( name : string ) : List | undefined {
@@ -39,3 +23,19 @@ export function getListByNameIgnoreCase(name: string): List {
39
23
40
24
return list ;
41
25
}
26
+
27
+ function getListInternal ( id : string ) : [ List , boolean ] {
28
+ const defaultList = defaultLists . find ( ( l ) => l . id === id ) ;
29
+
30
+ if ( defaultList != null ) {
31
+ return [ defaultList , true ] ;
32
+ }
33
+
34
+ const userList = storage . getLists ( ) . find ( ( l ) => l . id === id ) ;
35
+
36
+ if ( userList != null ) {
37
+ return [ userList , false ] ;
38
+ }
39
+
40
+ throw Error ( `Can't find list '${ id } '` ) ;
41
+ }
0 commit comments