Skip to content

Commit

Permalink
Create separate page for Friends Sit, so Props are up-to-date
Browse files Browse the repository at this point in the history
  • Loading branch information
dsernst committed Sep 8, 2020
1 parent a4feb36 commit 6c60808
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 88 deletions.
103 changes: 103 additions & 0 deletions src/FriendsSitScreen.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import firestore from '@react-native-firebase/firestore'
import React from 'react'
import { Text, TouchableOpacity, View } from 'react-native'
import OneSignal from 'react-native-onesignal'
import Feather from 'react-native-vector-icons/Feather'
import Ionicons from 'react-native-vector-icons/Ionicons'

import BackButton from './BackButton'
import { Props } from './reducer'
import setDailyNotifications from './SettingsScreen/notification'
import TitleBar from './TitleBar'

const FriendsSitScreen = ({
amNotification,
amNotificationTime,
autoSyncCompletedSits,
displayName,
friendsSit,
history,
pmNotification,
pmNotificationTime,
setState,
user,
}: Props) => {
if (!friendsSit) {
return (
<>
<Text style={{ color: '#fffa', margin: 30 }}>Loading...</Text>
<BackButton text="Done" />
</>
)
}

const { host_name, host_onesignal, host_phone, sit, sit_date } = friendsSit

return (
<>
<TitleBar name="FRIENDS SIT" />

<Ionicons color="#fff4" name="ios-people" size={83} style={{ alignSelf: 'center', marginBottom: 40 }} />
<View style={{ paddingHorizontal: 20 }}>
<Text style={{ color: '#fffc', fontSize: 18, lineHeight: 26 }}>
Your friend {host_name} sat for {sit?.duration} minutes.
</Text>
<TouchableOpacity
activeOpacity={0.7}
onPress={() => {
const newSit = { ...sit, date: new Date(sit_date), host_name, host_phone }

// Add to history
const newHistory = [newSit, ...history]
setState({ history: newHistory, screen: 'HistoryScreen' })

// Send reply to host that sit was copied
OneSignal.postNotification(
{
en: `${displayName} said they sat with you 🙂`,
},
{},
[host_onesignal],
)

// Update daily notifications
setDailyNotifications(amNotification, amNotificationTime, pmNotification, pmNotificationTime, newHistory)

// Sync sit to cloud
if (!user) {
return console.log(' Not logged in.')
}
if (!autoSyncCompletedSits) {
return console.log(' AutoSync disabled.')
}
setTimeout(async () => {
await firestore()
.collection('sits')
.add({ ...newSit, user_id: user.uid, user_phone: user.phoneNumber })
console.log('⬆️ Autosync complete.')
}, 500)
}}
style={{
alignItems: 'center',
alignSelf: 'center',
borderColor: '#fff3',
borderRadius: 5,
borderWidth: 1,
flexDirection: 'row',
marginTop: 30,
paddingHorizontal: 20,
paddingVertical: 10,
}}
>
<Feather color="#fffa" name="copy" size={15} style={{ paddingRight: 12, paddingTop: 1 }} />
<Text style={{ color: '#fff9', fontSize: 16, fontWeight: '500' }}>I sat with them</Text>
</TouchableOpacity>
</View>
<BackButton text="Done" />
</>
)
}

FriendsSitScreen.paddingHorizontal = 2

export default FriendsSitScreen
76 changes: 0 additions & 76 deletions src/copy-friends-sit.ts

This file was deleted.

6 changes: 4 additions & 2 deletions src/onesignal-helper.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Platform } from 'react-native'
import OneSignal from 'react-native-onesignal'

import { copyFriendsSit } from './copy-friends-sit'
import { Props } from './reducer'

function init(props: Props) {
Expand Down Expand Up @@ -55,7 +54,10 @@ function onOpened(props: Props) {
setState({ expandFriendsSection: true, screen: 'SettingsScreen' })
}
if (body.includes(' just finished a ')) {
copyFriendsSit(openResult.notification.payload.additionalData, props)
setState({
friendsSit: openResult.notification.payload.additionalData.p2p_notification,
screen: 'FriendsSitScreen',
})
}
}
}
7 changes: 7 additions & 0 deletions src/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ export interface State extends ToggleableStates {
customDuration: number
displayName: string | null
expandFriendsSection?: boolean
friendsSit?: {
host_name: string
host_onesignal: string
host_phone: string
sit: Sit
sit_date: string
}
history: Sit[]
historyViewIndex: number
incomingFriendRequests: FriendRequest[]
Expand Down
16 changes: 6 additions & 10 deletions src/screens.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import CountdownScreen from './CountdownScreen/CountdownScreen'
import FriendsSitScreen from './FriendsSitScreen'
import HistoryScreen from './HistoryScreen/HistoryScreen'
import MultiDeleteScreen from './HistoryScreen/MultiDeleteScreen'
import InitFriendsScreen from './InitFriendsScreen'
Expand All @@ -7,9 +8,10 @@ import MainScreen from './MainScreen/MainScreen'
import CheckContactsScreen from './SettingsScreen/Friends/CheckContactsScreen'
import SettingsScreen from './SettingsScreen/SettingsScreen'

export default {
const screens = {
CheckContactsScreen,
CountdownScreen,
FriendsSitScreen,
HistoryScreen,
InitFriendsScreen,
InitQuestionScreen,
Expand All @@ -18,12 +20,6 @@ export default {
SettingsScreen,
}

export type ScreenNames =
| 'CountdownScreen'
| 'HistoryScreen'
| 'MainScreen'
| 'SettingsScreen'
| 'MultiDeleteScreen'
| 'InitQuestionScreen'
| 'CheckContactsScreen'
| 'InitFriendsScreen'
export type ScreenNames = keyof typeof screens

export default screens

0 comments on commit 6c60808

Please sign in to comment.