Skip to content

Commit 0923bb1

Browse files
committed
for #4849
1 parent 0973ee4 commit 0923bb1

File tree

4 files changed

+42
-26
lines changed

4 files changed

+42
-26
lines changed

src/store/HomeStore.ts

+19-20
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,20 @@
11
/* tslint:disable:max-classes-per-file */
22
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'
44
import {autorun} from 'mobx'
55
import {INavStore} from './NavStore'
66

77
const DEFAULT_DELTA = 0.00522
88
const TRANS_DELTA = DEFAULT_DELTA + 0.005
99
export const INIT_DELTA = 0.04
1010

11-
const MapOptions = types.enumeration(['auto', 'satellite', 'street'])
12-
1311
const HomeStore = types
1412
.model('HomeStore', {
1513
fullScreenMode: false,
1614
focusedLocation: types.maybeNull(Location),
1715
mapCenterLocation: types.maybeNull(Location),
1816
selectedId: types.maybe(types.string),
1917
followingUser: false,
20-
mapOptions: types.optional(MapOptions, 'auto'),
2118
})
2219
.volatile(() => ({
2320
latitudeDelta: INIT_DELTA,
@@ -26,6 +23,9 @@ const HomeStore = types
2623
.views(self => {
2724
const {navStore, wocky}: {navStore: INavStore; wocky: IWocky} = getRoot(self)
2825
return {
26+
get mapOptions(): MapOptionsEnum | null {
27+
return wocky && wocky.profile ? wocky!.profile!.clientData.mapOptions : null
28+
},
2929
get creationMode() {
3030
return (
3131
navStore && ['createBot', 'botCompose', 'botEdit', 'editNote'].includes(navStore.scene)
@@ -52,19 +52,21 @@ const HomeStore = types
5252
}
5353
return [wocky.profile, ...wocky.profile!.allFriends]
5454
},
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-
},
6655
}
6756
})
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+
}))
6870
.actions(self => ({
6971
setFriendFilter(filter: string) {
7072
self.friendFilter = filter
@@ -113,9 +115,10 @@ const HomeStore = types
113115
}))
114116
.actions(self => {
115117
let disposer: any = null
118+
const {wocky}: {wocky: IWocky} = getRoot(self)
116119
return {
117120
setMapOptions(value) {
118-
self.mapOptions = value
121+
wocky!.profile!.clientData.setMapOptions(value)
119122
},
120123
followUserOnMap(user: IProfile) {
121124
if (user.location) {
@@ -135,10 +138,6 @@ const HomeStore = types
135138
},
136139
}
137140
})
138-
.postProcessSnapshot((snapshot: any) => {
139-
// store mapOptions
140-
return {mapOptions: snapshot.mapOptions}
141-
})
142141
.views(self => ({
143142
get filteredFriends() {
144143
const {wocky} = getRoot(self)

third-party/wocky-client/src/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export {IFileService} from './transport/FileService'
2424
export {Location, ILocationSnapshot, ILocation, createLocation} from './model/Location'
2525
export {Message, IMessage, Status as MessageStatus} from './model/Message'
2626
export {OwnProfile, IOwnProfile} from './model/OwnProfile'
27+
export {ClientData, MapOptions, MapOptionsEnum} from './model/ClientData'
2728
export {Transport} from './transport/Transport'
2829
export {IPagingList} from './transport/types'
2930
export {createFactory} from './store/Factory'

third-party/wocky-client/src/model/ClientData.ts

+21-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
import {types, getSnapshot, Instance, applySnapshot} from 'mobx-state-tree'
22
import {Base} from './Base'
33

4+
export enum MapOptionsEnum {
5+
AUTO = 'auto',
6+
SATELLITE = 'satellite',
7+
STREET = 'street',
8+
}
9+
10+
export const MapOptions = types.enumeration([...Object.values(MapOptionsEnum)])
11+
412
const Hidden = types
513
.model('HiddenType', {
614
enabled: false,
@@ -28,11 +36,12 @@ const Hidden = types
2836
}
2937
})
3038

31-
const ClientData = types
39+
export const ClientData = types
3240
.compose(
3341
Base,
3442
types
3543
.model({
44+
mapOptions: types.optional(MapOptions, MapOptionsEnum.AUTO),
3645
sharePresencePrimed: false,
3746
guestOnce: false,
3847
onboarded: false,
@@ -46,9 +55,18 @@ const ClientData = types
4655
)
4756
.named('ClientData')
4857
.actions(self => ({
58+
persist() {
59+
self.transport.updateProfile({clientData: getSnapshot(self)})
60+
},
61+
}))
62+
.actions(self => ({
63+
setMapOptions(value) {
64+
self.mapOptions = value
65+
self.persist()
66+
},
4967
hide(value: boolean, expires: Date | undefined) {
5068
self.hidden = Hidden.create({enabled: value, expires})
51-
self.transport.updateProfile({clientData: getSnapshot(self)})
69+
self.persist()
5270
},
5371
load: snapshot => {
5472
applySnapshot(self, JSON.parse(snapshot))
@@ -58,10 +76,8 @@ const ClientData = types
5876
},
5977
flip: (property: 'sharePresencePrimed' | 'guestOnce' | 'onboarded') => {
6078
self[property] = true
61-
self.transport.updateProfile({clientData: getSnapshot(self)})
79+
self.persist()
6280
},
6381
}))
6482

65-
export default ClientData
66-
6783
export interface IClientData extends Instance<typeof ClientData> {}

third-party/wocky-client/src/model/OwnProfile.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {createUpdatable} from './Updatable'
44
import {createUploadable} from './Uploadable'
55
import {InvitationPaginableList, Invitation} from './Invitation'
66
import {BlockedUserPaginableList, BlockedUser} from './BlockedUser'
7-
import ClientData from './ClientData'
7+
import {ClientData} from './ClientData'
88
import {reaction, IReactionDisposer} from 'mobx'
99

1010
export const OwnProfile = types

0 commit comments

Comments
 (0)