Skip to content

Commit

Permalink
Merge pull request #4875 from hippware/4849
Browse files Browse the repository at this point in the history
for #4849
  • Loading branch information
southerneer authored Mar 5, 2020
2 parents 03fb2a8 + bc82129 commit 0435a39
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 26 deletions.
39 changes: 19 additions & 20 deletions src/store/HomeStore.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
/* tslint:disable:max-classes-per-file */
import {types, applySnapshot, getRoot, Instance} from 'mobx-state-tree'
import {IProfile, Location, IWocky} from 'wocky-client'
import {IProfile, Location, IWocky, MapOptionsEnum} from 'wocky-client'
import {autorun} from 'mobx'
import {INavStore} from './NavStore'

const DEFAULT_DELTA = 0.00522
const TRANS_DELTA = DEFAULT_DELTA + 0.005
export const INIT_DELTA = 0.04

const MapOptions = types.enumeration(['auto', 'satellite', 'street'])

const HomeStore = types
.model('HomeStore', {
fullScreenMode: false,
focusedLocation: types.maybeNull(Location),
mapCenterLocation: types.maybeNull(Location),
selectedId: types.maybe(types.string),
followingUser: false,
mapOptions: types.optional(MapOptions, 'auto'),
})
.volatile(() => ({
latitudeDelta: INIT_DELTA,
Expand All @@ -26,6 +23,9 @@ const HomeStore = types
.views(self => {
const {navStore, wocky}: {navStore: INavStore; wocky: IWocky} = getRoot(self)
return {
get mapOptions(): MapOptionsEnum | null {
return wocky && wocky.profile ? wocky!.profile!.clientData.mapOptions : null
},
get creationMode() {
return (
navStore && ['createBot', 'botCompose', 'botEdit', 'editNote'].includes(navStore.scene)
Expand All @@ -52,19 +52,21 @@ const HomeStore = types
}
return [wocky.profile, ...wocky.profile!.allFriends]
},
get mapType() {
switch (self.mapOptions) {
case 'satellite':
return 'hybrid'
case 'street':
return 'standard'
case 'auto':
default:
return self.latitudeDelta <= TRANS_DELTA ? 'hybrid' : 'standard'
}
},
}
})
.views(self => ({
get mapType() {
switch (self.mapOptions) {
case 'satellite':
return 'hybrid'
case 'street':
return 'standard'
case 'auto':
default:
return self.latitudeDelta <= TRANS_DELTA ? 'hybrid' : 'standard'
}
},
}))
.actions(self => ({
setFriendFilter(filter: string) {
self.friendFilter = filter
Expand Down Expand Up @@ -113,9 +115,10 @@ const HomeStore = types
}))
.actions(self => {
let disposer: any = null
const {wocky}: {wocky: IWocky} = getRoot(self)
return {
setMapOptions(value) {
self.mapOptions = value
wocky!.profile!.clientData.setMapOptions(value)
},
followUserOnMap(user: IProfile) {
if (user.location) {
Expand All @@ -135,10 +138,6 @@ const HomeStore = types
},
}
})
.postProcessSnapshot((snapshot: any) => {
// store mapOptions
return {mapOptions: snapshot.mapOptions}
})
.views(self => ({
get filteredFriends() {
const {wocky} = getRoot(self)
Expand Down
1 change: 1 addition & 0 deletions third-party/wocky-client/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export {IFileService} from './transport/FileService'
export {Location, ILocationSnapshot, ILocation, createLocation} from './model/Location'
export {Message, IMessage, Status as MessageStatus} from './model/Message'
export {OwnProfile, IOwnProfile} from './model/OwnProfile'
export {ClientData, MapOptions, MapOptionsEnum} from './model/ClientData'
export {Transport} from './transport/Transport'
export {IPagingList} from './transport/types'
export {createFactory} from './store/Factory'
26 changes: 21 additions & 5 deletions third-party/wocky-client/src/model/ClientData.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import {types, getSnapshot, Instance, applySnapshot} from 'mobx-state-tree'
import {Base} from './Base'

export enum MapOptionsEnum {
AUTO = 'auto',
SATELLITE = 'satellite',
STREET = 'street',
}

export const MapOptions = types.enumeration([...Object.values(MapOptionsEnum)])

const Hidden = types
.model('HiddenType', {
enabled: false,
Expand Down Expand Up @@ -28,11 +36,12 @@ const Hidden = types
}
})

const ClientData = types
export const ClientData = types
.compose(
Base,
types
.model({
mapOptions: types.optional(MapOptions, MapOptionsEnum.AUTO),
sharePresencePrimed: false,
guestOnce: false,
onboarded: false,
Expand All @@ -46,9 +55,18 @@ const ClientData = types
)
.named('ClientData')
.actions(self => ({
persist() {
self.transport.updateProfile({clientData: getSnapshot(self)})
},
}))
.actions(self => ({
setMapOptions(value) {
self.mapOptions = value
self.persist()
},
hide(value: boolean, expires: Date | undefined) {
self.hidden = Hidden.create({enabled: value, expires})
self.transport.updateProfile({clientData: getSnapshot(self)})
self.persist()
},
load: snapshot => {
applySnapshot(self, JSON.parse(snapshot))
Expand All @@ -58,10 +76,8 @@ const ClientData = types
},
flip: (property: 'sharePresencePrimed' | 'guestOnce' | 'onboarded') => {
self[property] = true
self.transport.updateProfile({clientData: getSnapshot(self)})
self.persist()
},
}))

export default ClientData

export interface IClientData extends Instance<typeof ClientData> {}
2 changes: 1 addition & 1 deletion third-party/wocky-client/src/model/OwnProfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {createUpdatable} from './Updatable'
import {createUploadable} from './Uploadable'
import {InvitationPaginableList, Invitation} from './Invitation'
import {BlockedUserPaginableList, BlockedUser} from './BlockedUser'
import ClientData from './ClientData'
import {ClientData} from './ClientData'
import {reaction, IReactionDisposer} from 'mobx'

export const OwnProfile = types
Expand Down

0 comments on commit 0435a39

Please sign in to comment.