Fix saving notification data
This commit is contained in:
parent
85dc440fe8
commit
ad990ca528
5 changed files with 43 additions and 28 deletions
|
@ -2,7 +2,7 @@ import React from 'react';
|
||||||
import { Stack } from 'expo-router';
|
import { Stack } from 'expo-router';
|
||||||
import { StyleSheet, TextInput, TouchableOpacity } from 'react-native';
|
import { StyleSheet, TextInput, TouchableOpacity } from 'react-native';
|
||||||
import { router } from 'expo-router';
|
import { router } from 'expo-router';
|
||||||
// import DeviceInfo from 'react-native-device-info';
|
import DeviceInfo from 'react-native-device-info';
|
||||||
|
|
||||||
import { ThemedText } from '@/lib/components/ThemedText';
|
import { ThemedText } from '@/lib/components/ThemedText';
|
||||||
import { ThemedView } from '@/lib/components/ThemedView';
|
import { ThemedView } from '@/lib/components/ThemedView';
|
||||||
|
@ -12,7 +12,7 @@ import { useColorScheme } from '@/lib/hooks/useColorScheme';
|
||||||
import { Message } from '@/lib/services/message';
|
import { Message } from '@/lib/services/message';
|
||||||
import { Request } from '@/lib/services/request';
|
import { Request } from '@/lib/services/request';
|
||||||
import { store } from '@/lib/store/store';
|
import { store } from '@/lib/store/store';
|
||||||
import { setSession, setReloadCalendar } from '@/lib/store/dataStore';
|
import { setSession } from '@/lib/store/dataStore';
|
||||||
|
|
||||||
export default function OnboardStartScreen() {
|
export default function OnboardStartScreen() {
|
||||||
const colorScheme = useColorScheme() ?? 'light';
|
const colorScheme = useColorScheme() ?? 'light';
|
||||||
|
@ -29,7 +29,7 @@ export default function OnboardStartScreen() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get device name info
|
// Get device name info
|
||||||
const deviceName = ''; // DeviceInfo.getModel();
|
const deviceName = DeviceInfo.getModel();
|
||||||
|
|
||||||
Request
|
Request
|
||||||
.post( 'sessions/create', {
|
.post( 'sessions/create', {
|
||||||
|
|
|
@ -12,6 +12,8 @@ import { ThemedText } from '@/lib/components/ThemedText';
|
||||||
import { Request } from '@/lib/services/request';
|
import { Request } from '@/lib/services/request';
|
||||||
import { useToken } from '@/lib/context/AppProvider';
|
import { useToken } from '@/lib/context/AppProvider';
|
||||||
import { Message } from '@/lib/services/message';
|
import { Message } from '@/lib/services/message';
|
||||||
|
import { store } from '@/lib/store/store';
|
||||||
|
import { setSession } from '@/lib/store/dataStore';
|
||||||
|
|
||||||
export default function CategoryScreen() {
|
export default function CategoryScreen() {
|
||||||
const colorScheme = useColorScheme() ?? 'light';
|
const colorScheme = useColorScheme() ?? 'light';
|
||||||
|
@ -19,6 +21,8 @@ export default function CategoryScreen() {
|
||||||
const { token } = useToken();
|
const { token } = useToken();
|
||||||
const session = useSelector( (state: any) => state.data.session );
|
const session = useSelector( (state: any) => state.data.session );
|
||||||
|
|
||||||
|
const [ sessionSet, setSessionSet ] = useState( false );
|
||||||
|
|
||||||
const [ isDayBeforeEnabled, setIsDayBeforeEnabled ] = useState( true );
|
const [ isDayBeforeEnabled, setIsDayBeforeEnabled ] = useState( true );
|
||||||
const [ dayBefore, setDayBefore ] = useState( '19:30' );
|
const [ dayBefore, setDayBefore ] = useState( '19:30' );
|
||||||
|
|
||||||
|
@ -35,6 +39,7 @@ export default function CategoryScreen() {
|
||||||
|
|
||||||
// Set session data
|
// Set session data
|
||||||
useEffect( () => {
|
useEffect( () => {
|
||||||
|
if (!sessionSet) {
|
||||||
if (session.notifications.dayBefore === 'off') {
|
if (session.notifications.dayBefore === 'off') {
|
||||||
setIsDayBeforeEnabled( false );
|
setIsDayBeforeEnabled( false );
|
||||||
} else {
|
} else {
|
||||||
|
@ -46,8 +51,11 @@ export default function CategoryScreen() {
|
||||||
setIsSameDayEnabled( false );
|
setIsSameDayEnabled( false );
|
||||||
} else {
|
} else {
|
||||||
setIsSameDayEnabled( true );
|
setIsSameDayEnabled( true );
|
||||||
setSameDay( session.notifications.dayBefore );
|
setSameDay( session.notifications.sameDay );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
setSessionSet( true );
|
||||||
}, [ session ] );
|
}, [ session ] );
|
||||||
|
|
||||||
// Update session when something changes
|
// Update session when something changes
|
||||||
|
@ -101,6 +109,10 @@ export default function CategoryScreen() {
|
||||||
}
|
}
|
||||||
|
|
||||||
const updateSession = () => {
|
const updateSession = () => {
|
||||||
|
if (!sessionSet) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const postData = {
|
const postData = {
|
||||||
token: token,
|
token: token,
|
||||||
notification_day_before: isDayBeforeEnabled ? dayBefore : 'off',
|
notification_day_before: isDayBeforeEnabled ? dayBefore : 'off',
|
||||||
|
@ -108,7 +120,9 @@ export default function CategoryScreen() {
|
||||||
};
|
};
|
||||||
|
|
||||||
Request.post( 'sessions/update', postData ).then( (response) => {
|
Request.post( 'sessions/update', postData ).then( (response) => {
|
||||||
if (!response.success) {
|
if (response.success) {
|
||||||
|
store.dispatch( setSession( response.session ) );
|
||||||
|
} else {
|
||||||
Message.error( 'Er ging iets mis. Probeer het later opnieuw.' );
|
Message.error( 'Er ging iets mis. Probeer het later opnieuw.' );
|
||||||
}
|
}
|
||||||
} )
|
} )
|
||||||
|
|
|
@ -35,8 +35,7 @@ export default function HomeScreen() {
|
||||||
OneSignal.initialize("6ef15aa7-9dc0-4d8b-b6b1-e2005bcd3dc6");
|
OneSignal.initialize("6ef15aa7-9dc0-4d8b-b6b1-e2005bcd3dc6");
|
||||||
|
|
||||||
// Request permission
|
// Request permission
|
||||||
OneSignal.Notifications.requestPermission(true)
|
OneSignal.Notifications.requestPermission(true).then(() => {
|
||||||
|
|
||||||
// Retrieve one signal user token
|
// Retrieve one signal user token
|
||||||
OneSignal.User.pushSubscription.getIdAsync().then((notificationsToken) => {
|
OneSignal.User.pushSubscription.getIdAsync().then((notificationsToken) => {
|
||||||
if (notificationsToken) {
|
if (notificationsToken) {
|
||||||
|
@ -47,6 +46,7 @@ export default function HomeScreen() {
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
})
|
||||||
|
|
||||||
// Disable loading again
|
// Disable loading again
|
||||||
setOnesignalLoaded(true);
|
setOnesignalLoaded(true);
|
||||||
|
|
|
@ -157,6 +157,7 @@ export default function SettingsScreen() {
|
||||||
</ThemedView>
|
</ThemedView>
|
||||||
|
|
||||||
<TouchableOpacity style={styles.listEdit} onPress={() => router.push( '/(settings)/notifications' )}>
|
<TouchableOpacity style={styles.listEdit} onPress={() => router.push( '/(settings)/notifications' )}>
|
||||||
|
<ThemedText style={styles.listEditText}>Wijzigen</ThemedText>
|
||||||
<Ionicons size={18} name="chevron-forward" style={styles.listEditIcon}/>
|
<Ionicons size={18} name="chevron-forward" style={styles.listEditIcon}/>
|
||||||
</TouchableOpacity>
|
</TouchableOpacity>
|
||||||
</ThemedView>
|
</ThemedView>
|
||||||
|
|
|
@ -20,8 +20,8 @@ const dataStore = createSlice( {
|
||||||
longitude: '',
|
longitude: '',
|
||||||
},
|
},
|
||||||
notifications: {
|
notifications: {
|
||||||
dayBefore: '',
|
dayBefore: 'off',
|
||||||
sameDay: '',
|
sameDay: 'off',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
reloadCalendar: true,
|
reloadCalendar: true,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue