Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

4850 onboard once #4907

Merged
merged 2 commits into from
Mar 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/components/Onboarding/OnboardingAccelerometer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {RText, GradientButton} from '../common'
import {WHITE} from 'src/constants/colors'
import {s} from '../Global'
import {onboardingSlideStyle as styles} from '../styles'
import {accelerometerSettingsName} from '../modals/MotionWarning'

type Props = {
onPress: () => void // the function that gets called when the user presses "Allow Accelerometer"
Expand All @@ -19,13 +20,13 @@ const OnboardingAccelerometer = ({onPress}: Props) => (
}}
>
<View style={{width: '80%', marginBottom: 33 * s}}>
<RText style={styles.onboardingH1}>Allow{'\r\n'} Accelerometer</RText>
<RText style={styles.onboardingH1}>{`Allow\r\n${accelerometerSettingsName}`}</RText>
</View>

<View style={{width: '70%', marginBottom: 42 * s}}>
<RText style={styles.onboardingSubtext}>
Using the accelerometer increases battery-efficiency by intelligently toggling
location-tracking while moving.
{`Using ${accelerometerSettingsName} increases battery-efficiency by intelligently toggling
location-tracking while moving.`}
</RText>
</View>

Expand Down
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
9 changes: 5 additions & 4 deletions src/components/modals/MotionWarning.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import {useAppState} from 'react-native-hooks'
import {Actions} from 'react-native-router-flux'
import {usePermissionStore} from '../../utils/injectors'

export const accelerometerSettingsName =
Platform.OS === 'ios' ? 'Motion & Fitness' : 'Physical Activity'

const MotionWarning = observer(() => {
const currentAppState = useAppState()
const permissionStore = usePermissionStore()
Expand All @@ -21,8 +24,6 @@ const MotionWarning = observer(() => {
}
}, [currentAppState])

const settingsName = Platform.OS === 'ios' ? 'Motion & Fitness' : 'Physical Activity'

return (
<View
style={[
Expand All @@ -35,10 +36,10 @@ const MotionWarning = observer(() => {
]}
>
<BlurView blurType="xlight" blurAmount={10} style={StyleSheet.absoluteFill as any} />
<RText style={styles.title}>{`Allow\r\n${settingsName}`}</RText>
<RText style={styles.title}>{`Allow\r\n${accelerometerSettingsName}`}</RText>

<RText style={styles.subtext}>
{`Using "${settingsName}" increases battery efficiency by intelligently toggling location tracking while moving.`}
{`Using "${accelerometerSettingsName}" increases battery efficiency by intelligently toggling location tracking while moving.`}
</RText>

<Image
Expand Down
3 changes: 1 addition & 2 deletions 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 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
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