Skip to content

Commit

Permalink
Merge pull request #4921 from hippware/4828-debug-options-screen
Browse files Browse the repository at this point in the history
4828 debug options screen
  • Loading branch information
aksonov authored Mar 17, 2020
2 parents 66035b3 + 5027cc0 commit 422560a
Show file tree
Hide file tree
Showing 9 changed files with 124 additions and 19 deletions.
10 changes: 10 additions & 0 deletions __tests__/wocky/profile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@ describe('New GraphQL profile tests', () => {
expect(clientData.guestOnce).toBeTruthy()
})

it('toggle userFullAudit', async () => {
expect(user.profile!.fullAudit).toBe(false)
await user.userFullAudit(true)
await user.loadProfile(user.profile!.id)
expect(user.profile!.fullAudit).toBe(true)
await user.userFullAudit(false)
await user.loadProfile(user.profile!.id)
expect(user.profile!.fullAudit).toBe(false)
})

it('user1 sent friend invite to user2', async () => {
expect(user.profile!.sortedFriends.length).toBe(0)
expect(user2.profile!.sortedFriends.length).toBe(0)
Expand Down
73 changes: 73 additions & 0 deletions src/components/DebugOptionsScreen.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import React from 'react'
import {observer} from 'mobx-react'
import {TouchableOpacity, View} from 'react-native'
import {RText, Switch} from './common'
import {colors} from '../constants'
import Screen from './Screen'
import {useLocationStore, useWocky} from 'src/utils/injectors'

const DebugOptionsScreen = observer(() => {
const {emailLog, setLogVerbose} = useLocationStore()
const {profile, userFullAudit} = useWocky()

return profile ? (
<Screen style={{flex: 1, paddingVertical: 10}}>
<View
style={{
flexDirection: 'row',
justifyContent: 'space-between',
borderBottomWidth: 1,
borderColor: colors.DARK_GREY,
paddingVertical: 20,
paddingHorizontal: 30,
}}
>
<RText size={16} color={colors.DARK_PURPLE}>
Enable Logging
</RText>
<Switch
isOn={!!profile.fullAudit}
onColor={colors.PINK}
offColor={colors.GREY}
onToggle={value => {
userFullAudit(value).then(_successful => {
setLogVerbose(value)
profile.setFullAudit(value)
})
}}
/>
</View>
{!!profile.fullAudit && (
<View
style={{
marginTop: 20,
alignItems: 'center',
}}
>
<TouchableOpacity
onPress={() => emailLog()}
style={{
borderWidth: 1,
borderRadius: 12,
borderColor: colors.PINK,
padding: 10,
width: 225,
}}
>
<RText
size={16}
color={colors.PINK}
style={{
textAlign: 'center',
}}
>
Email log
</RText>
</TouchableOpacity>
</View>
)}
</Screen>
) : null
})

export default DebugOptionsScreen
13 changes: 1 addition & 12 deletions src/components/LocationDebug.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const options = {
}

const LocationDebug = observer(() => {
const {configOptions, setBackgroundConfig, emailLog, uploadLog} = useLocationStore()
const {configOptions, setBackgroundConfig, uploadLog} = useLocationStore()
const [uploadStatusText, setUploadStatusText] = useState('')

return (
Expand Down Expand Up @@ -78,17 +78,6 @@ const LocationDebug = observer(() => {
{uploadStatusText}
</RText>
)}
<TouchableOpacity
// Calling emailLog with empty string seems to work
onPress={() => {
emailLog('')
}}
style={styles.button}
>
<RText size={20} color={colors.WHITE}>
Email log
</RText>
</TouchableOpacity>
</KeyboardAwareScrollView>
</Screen>
)
Expand Down
2 changes: 1 addition & 1 deletion src/components/MyAccount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ const MyAccount = inject(
<LinkButton onPress={() => Linking.openURL('https://tinyrobot.com/privacy-policy/')}>
Privacy Policy
</LinkButton>
<LinkButton onPress={Actions.debugOptionsScreen}>Debug Options</LinkButton>
<LinkButton
onPress={() => {
Alert.alert('Log Out', `Are you sure you want to log out?`, [
Expand Down Expand Up @@ -180,7 +181,6 @@ const MyAccount = inject(
)}
{settings.allowProfileDelete && (
<LinkButton
style={{marginTop: 50}}
onPress={() => {
Alert.alert(
'Delete Profile',
Expand Down
2 changes: 2 additions & 0 deletions src/components/Router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import VerifyCode from './VerifyCode'
import LocationDebug from './LocationDebug'
import BottomMenu from './BottomMenu'
import DebugScreen from './DebugScreen'
import DebugOptionsScreen from './DebugOptionsScreen'
import LocationWarning from './modals/LocationWarning'
import MotionWarning from './modals/MotionWarning'
import SharePresencePrimer from './modals/SharePresencePrimer'
Expand Down Expand Up @@ -237,6 +238,7 @@ const TinyRobotRouter = inject('wocky', 'locationStore', 'iconStore', 'analytics
<Scene key="debugScreen" component={DebugScreen} title="Debug" back />,
<Scene key="codePush" component={CodePushScene} title="CodePush" back />,
]}
<Scene key="debugOptionsScreen" component={DebugOptionsScreen} title="Debug Options" navigationBarStyle={{paddingBottom: 20, borderBottomWidth:1}} back />
</Stack>
<Scene key="reportUser" component={ReportUser} wrap title="Report User" leftButtonImage={iconClose} onLeft={Actions.pop} right={ReportUserRightButton} />
<Scene key="reportBot" component={ReportBot} wrap title="Report Location" leftButtonImage={iconClose} onLeft={Actions.pop} right={ReportBotRightButton} />
Expand Down
4 changes: 4 additions & 0 deletions src/model/OwnProfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const OwnProfile = types
types.model('OwnProfile', {
email: types.maybeNull(types.string),
phoneNumber: types.maybeNull(types.string),
fullAudit: types.maybeNull(types.boolean),
sentInvitations: types.optional(InvitationPaginableList, {}),
receivedInvitations: types.optional(InvitationPaginableList, {}),
friends: types.optional(ProfilePaginableList, {}),
Expand Down Expand Up @@ -107,6 +108,9 @@ export const OwnProfile = types
)
profile.receivedInvite()
},
setFullAudit: (enable: boolean) => {
self.fullAudit = enable
},
}))
.actions(self => {
const timers: any[] = []
Expand Down
15 changes: 10 additions & 5 deletions src/store/LocationStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,6 @@ const LocationStore = types
desiredAccuracy: BackgroundGeolocation.DESIRED_ACCURACY_HIGH,
enableHeadless: true,
foregroundService: true, // android only
logLevel:
__DEV__ || settings.configurableLocationSettings
? BackgroundGeolocation.LOG_LEVEL_VERBOSE
: BackgroundGeolocation.LOG_LEVEL_OFF,
maxRecordsToPersist: 20,
notification: {
// android only
Expand Down Expand Up @@ -235,7 +231,7 @@ const LocationStore = types
: Promise.reject(new Error('No uploadUrl'))
}

async function emailLog(email) {
async function emailLog(email = '[email protected]') {
// emailLog doesn't work in iOS simulator so fetch and dump instead
if (await DeviceInfo.isEmulator()) {
log(prefix, await BackgroundGeolocation.logger.getLog())
Expand All @@ -244,6 +240,14 @@ const LocationStore = types
}
}

function setLogVerbose(verbose: boolean) {
return BackgroundGeolocation.setConfig({
logLevel: verbose
? BackgroundGeolocation.LOG_LEVEL_VERBOSE
: BackgroundGeolocation.LOG_LEVEL_OFF,
})
}

return {
refreshCredentials,
invalidateCredentials,
Expand All @@ -253,6 +257,7 @@ const LocationStore = types
stopStandaloneGeolocation,
uploadLog,
emailLog,
setLogVerbose,
}
})
.actions(self => {
Expand Down
21 changes: 20 additions & 1 deletion src/store/Transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export class Transport {
${PROFILE_PROPS}
${
id === this.username
? `... on CurrentUser { email phoneNumber clientData
? `... on CurrentUser { email phoneNumber fullAudit clientData
sentInvitations(first:100) {
edges {
node {
Expand Down Expand Up @@ -1112,6 +1112,25 @@ export class Transport {
})
}

async userFullAudit(enable: boolean): Promise<boolean> {
const res = await this.mutate({
mutation: gql`
mutation userFullAudit(
$enable: Boolean!
) {
userFullAudit(
input: {enable: $enable}
) {
${VOID_PROPS}
}
}
`,
variables: {enable},
})

return (res.data as any).userFullAudit!.successful
}

async userInviteGetSender(code: string): Promise<IProfilePartial | null> {
const res = await this.query({
query: gql`
Expand Down
3 changes: 3 additions & 0 deletions src/store/Wocky.ts
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,9 @@ export const Wocky = types
triggerSilentPush(userId: string): Promise<void> {
return self.transport.triggerSilentPush(userId)
},
userFullAudit(enable: boolean): Promise<boolean> {
return self.transport.userFullAudit(enable)
},
}))
.actions(self => {
function clearCache() {
Expand Down

0 comments on commit 422560a

Please sign in to comment.