1
1
/* tslint:disable:max-classes-per-file */
2
2
import { types , applySnapshot , getRoot , Instance } from 'mobx-state-tree'
3
- import { IProfile , Location , IWocky } from 'wocky-client'
3
+ import { IProfile , Location , IWocky , MapOptionsEnum } from 'wocky-client'
4
4
import { autorun } from 'mobx'
5
5
import { INavStore } from './NavStore'
6
6
7
7
const DEFAULT_DELTA = 0.00522
8
8
const TRANS_DELTA = DEFAULT_DELTA + 0.005
9
9
export const INIT_DELTA = 0.04
10
10
11
- const MapOptions = types . enumeration ( [ 'auto' , 'satellite' , 'street' ] )
12
-
13
11
const HomeStore = types
14
12
. model ( 'HomeStore' , {
15
13
fullScreenMode : false ,
16
14
focusedLocation : types . maybeNull ( Location ) ,
17
15
mapCenterLocation : types . maybeNull ( Location ) ,
18
16
selectedId : types . maybe ( types . string ) ,
19
17
followingUser : false ,
20
- mapOptions : types . optional ( MapOptions , 'auto' ) ,
21
18
} )
22
19
. volatile ( ( ) => ( {
23
20
latitudeDelta : INIT_DELTA ,
@@ -26,6 +23,9 @@ const HomeStore = types
26
23
. views ( self => {
27
24
const { navStore, wocky} : { navStore : INavStore ; wocky : IWocky } = getRoot ( self )
28
25
return {
26
+ get mapOptions ( ) : MapOptionsEnum | null {
27
+ return wocky && wocky . profile ? wocky ! . profile ! . clientData . mapOptions : null
28
+ } ,
29
29
get creationMode ( ) {
30
30
return (
31
31
navStore && [ 'createBot' , 'botCompose' , 'botEdit' , 'editNote' ] . includes ( navStore . scene )
@@ -52,19 +52,21 @@ const HomeStore = types
52
52
}
53
53
return [ wocky . profile , ...wocky . profile ! . allFriends ]
54
54
} ,
55
- get mapType ( ) {
56
- switch ( self . mapOptions ) {
57
- case 'satellite' :
58
- return 'hybrid'
59
- case 'street' :
60
- return 'standard'
61
- case 'auto' :
62
- default :
63
- return self . latitudeDelta <= TRANS_DELTA ? 'hybrid' : 'standard'
64
- }
65
- } ,
66
55
}
67
56
} )
57
+ . views ( self => ( {
58
+ get mapType ( ) {
59
+ switch ( self . mapOptions ) {
60
+ case 'satellite' :
61
+ return 'hybrid'
62
+ case 'street' :
63
+ return 'standard'
64
+ case 'auto' :
65
+ default :
66
+ return self . latitudeDelta <= TRANS_DELTA ? 'hybrid' : 'standard'
67
+ }
68
+ } ,
69
+ } ) )
68
70
. actions ( self => ( {
69
71
setFriendFilter ( filter : string ) {
70
72
self . friendFilter = filter
@@ -113,9 +115,10 @@ const HomeStore = types
113
115
} ) )
114
116
. actions ( self => {
115
117
let disposer : any = null
118
+ const { wocky} : { wocky : IWocky } = getRoot ( self )
116
119
return {
117
120
setMapOptions ( value ) {
118
- self . mapOptions = value
121
+ wocky ! . profile ! . clientData . setMapOptions ( value )
119
122
} ,
120
123
followUserOnMap ( user : IProfile ) {
121
124
if ( user . location ) {
@@ -135,10 +138,6 @@ const HomeStore = types
135
138
} ,
136
139
}
137
140
} )
138
- . postProcessSnapshot ( ( snapshot : any ) => {
139
- // store mapOptions
140
- return { mapOptions : snapshot . mapOptions }
141
- } )
142
141
. views ( self => ( {
143
142
get filteredFriends ( ) {
144
143
const { wocky} = getRoot ( self )
0 commit comments