Skip to content

Commit

Permalink
onboarded flag stored locally and persisted for #4850
Browse files Browse the repository at this point in the history
  • Loading branch information
southerneer committed Mar 11, 2020
1 parent b3f70f5 commit 33c7e6e
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 33 deletions.
2 changes: 1 addition & 1 deletion src/components/Onboarding/OnboardingSwiper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ const OnboardingSwiper = inject(
}

const done = () => {
wocky!.profile!.setOnboarded()
permissionStore!.setOnboarded(true)
Actions.logged()
}

Expand Down
14 changes: 7 additions & 7 deletions src/components/Router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ import OnboardingSwiper from './Onboarding/OnboardingSwiper'
import {IAuthStore} from 'src/store/AuthStore'
import {IHomeStore} from 'src/store/HomeStore';
import MapOptions from './MapOptions'
import {IPermissionStore} from 'src/store/PermissionStore'
import LocationSettingsModal, {Props as LocationSettingsProps} from './LiveLocation/LocationSettingsModal'
import { IFirebaseStore } from '../store/FirebaseStore'
import {ContactInviteListWithLoad} from './people-lists/ContactInviteList'
import { usePermissionStore } from '../utils/injectors'

const iconClose = require('../../images/iconClose.png')

Expand All @@ -60,19 +60,19 @@ type Props = {
homeStore?: IHomeStore
iconStore?: IconStore
authStore?: IAuthStore
permissionStore?: IPermissionStore
analytics?: any
firebaseStore?: IFirebaseStore
}

const TinyRobotRouter = inject('wocky', 'permissionStore', 'locationStore', 'iconStore', 'analytics', 'homeStore', 'navStore', 'authStore', 'firebaseStore')(
observer(({wocky, permissionStore, locationStore, navStore, homeStore, iconStore, authStore, analytics, firebaseStore}: Props) => {
const TinyRobotRouter = inject('wocky', 'locationStore', 'iconStore', 'analytics', 'homeStore', 'navStore', 'authStore', 'firebaseStore')(
observer(({wocky, locationStore, navStore, homeStore, iconStore, authStore, analytics, firebaseStore}: Props) => {
const permissionStore = usePermissionStore()
useEffect(() => {
reaction(() => navStore!.scene, () => Keyboard.dismiss())

autorun(
() => {
if (permissionStore!.onboarded && !locationStore!.alwaysOn && navStore!.scene !== 'locationWarning' && Actions.locationWarning) {
if (permissionStore.onboarded && !locationStore!.alwaysOn && navStore!.scene !== 'locationWarning' && Actions.locationWarning) {
Actions.locationWarning({afterLocationAlwaysOn: () => Actions.popTo('home')})
}
},
Expand All @@ -81,7 +81,7 @@ const TinyRobotRouter = inject('wocky', 'permissionStore', 'locationStore', 'ico

autorun(
() => {
if (permissionStore!.onboarded && !permissionStore!.allowsAccelerometer && navStore!.scene !== 'motionWarning' && Actions.motionWarning) {
if (permissionStore.onboarded && !permissionStore.allowsAccelerometer && navStore!.scene !== 'motionWarning' && Actions.motionWarning) {
Actions.motionWarning()
}
},
Expand Down Expand Up @@ -189,7 +189,7 @@ const TinyRobotRouter = inject('wocky', 'permissionStore', 'locationStore', 'ico
<Scene key="connect" on={authStore!.login} success="checkHandle" failure="preConnection" />
<Scene key="checkProfile" on={() => wocky!.profile} success="checkHandle" failure="connect" />
<Scene key="checkHandle" on={() => wocky!.profile!.handle} success="checkOnboarded" failure="signUp" />
<Scene key="checkOnboarded" on={() => permissionStore!.onboarded} success={() => {
<Scene key="checkOnboarded" on={() => permissionStore.onboarded} success={() => {
Actions.logged()
if (firebaseStore!.inviteCode) {
showSharingModal()
Expand Down
4 changes: 2 additions & 2 deletions src/store/LocationStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ const LocationStore = types
}
})
.actions(self => {
const {wocky} = getRoot<any>(self)
const {wocky, permissionStore} = getRoot<any>(self)
let reactions: IReactionDisposer[] = []

const init = flow(function*() {
Expand All @@ -281,7 +281,7 @@ const LocationStore = types
wocky.connected &&
wocky.profile &&
wocky.profile.hidden &&
wocky.profile.clientData.onboarded &&
permissionStore.onboarded &&
self.alwaysOn
) {
try {
Expand Down
21 changes: 6 additions & 15 deletions src/store/PermissionStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const PermissionStore = types
allowsLocation: false,
allowsContacts: false,
loaded: false,
onboarded: false,
})
.actions(self => ({
setAllowsNotification(value: boolean) {
Expand All @@ -27,6 +28,9 @@ export const PermissionStore = types
setLoaded(value: boolean) {
self.loaded = value
},
setOnboarded(value: boolean) {
self.onboarded = value
},
}))
.actions(self => ({
checkMotionPermissions: (): Promise<boolean> =>
Expand Down Expand Up @@ -65,21 +69,8 @@ export const PermissionStore = types
})
},
}))
.views(self => ({
get onboarded() {
const {wocky} = getParent<any>(self)
return (
wocky &&
wocky.profile &&
wocky.profile.clientData.onboarded &&
// self.allowsAccelerometer &&
self.allowsNotification
)
},
}))
.postProcessSnapshot(() => {
// No need to persist this store
return {}
.postProcessSnapshot(({onboarded}) => {
return {onboarded}
})

export interface IPermissionStore extends Instance<typeof PermissionStore> {}
9 changes: 6 additions & 3 deletions src/store/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {autorun} from 'mobx'
import {settings} from '../globals'
import AsyncStorage from '@react-native-community/async-storage'
import deviceInfoFetch, {TRDeviceInfo} from 'src/utils/deviceInfoFetch'
import _ from 'lodash'

const jsVersion = require('../../package.json').version
const auth = firebase.auth()
Expand All @@ -48,7 +49,7 @@ export type IEnv = {
deviceInfo: TRDeviceInfo
}

const cleanState = {
export const cleanState = {
firebaseStore: {},
authStore: {},
locationStore: {},
Expand Down Expand Up @@ -111,10 +112,11 @@ export interface IStore extends Instance<typeof Store> {}
* Return only the mstStore data needed to prevent logout
* @param data - serialized mstStore object
*/
function getMinimalStoreData(data?: {authStore: object}): object {
function getMinimalStoreData(data?: {authStore: object; permissionStore: object}): object {
log('loadMinimal', data)
return {
authStore: data && data.authStore ? data.authStore : {},
authStore: _.get(data, 'authStore', cleanState.authStore),
permissionStore: _.get(data, 'permissionStore', cleanState.permissionStore),
}
}

Expand Down Expand Up @@ -170,6 +172,7 @@ export async function createStore() {
} catch (err) {
log('hydration error', err, storeData)
mstStore = Store.create({...cleanState, ...getMinimalStoreData(storeData), appInfo}, env)
// mstStore = Store.create({...cleanState, appInfo}, env)
}

const requestPushPermissions = initializePushNotifications(mstStore.wocky.enablePush)
Expand Down
3 changes: 1 addition & 2 deletions third-party/wocky-client/src/model/ClientData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ export const ClientData = types
mapOptions: types.optional(MapOptions, MapOptionsEnum.AUTO),
sharePresencePrimed: false,
guestOnce: false,
onboarded: false,
hidden: types.optional(Hidden, {}),
})
.views(self => ({
Expand Down Expand Up @@ -74,7 +73,7 @@ export const ClientData = types
clear: () => {
applySnapshot(self, {})
},
flip: (property: 'sharePresencePrimed' | 'guestOnce' | 'onboarded') => {
flip: (property: 'sharePresencePrimed' | 'guestOnce') => {
self[property] = true
self.persist()
},
Expand Down
3 changes: 0 additions & 3 deletions third-party/wocky-client/src/model/OwnProfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,6 @@ export const OwnProfile = types
}
})
.actions(self => ({
setOnboarded: () => {
self.clientData.flip('onboarded')
},
load({
avatar,
blocked = [],
Expand Down

0 comments on commit 33c7e6e

Please sign in to comment.