Add arrival buffer and transport options to notification settings
Update notification calculation to use arrival buffer Add advanced settings toggle for arrival buffer and transport options Fix reverse geocode call in SettingsScreen
This commit is contained in:
@@ -41,6 +41,7 @@ export function SettingsScreen({ navigation }: ScreenProps) {
|
||||
showWalkingOption: true,
|
||||
showBikeOption: true,
|
||||
});
|
||||
const [showAdvanced, setShowAdvanced] = useState(false);
|
||||
const [locPermission, setLocPermission] = useState<'granted' | 'denied' | 'prompt'>('prompt');
|
||||
const searchTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
|
||||
|
||||
@@ -102,7 +103,7 @@ export function SettingsScreen({ navigation }: ScreenProps) {
|
||||
|
||||
// Search for stations near the user's actual GPS coordinates
|
||||
// Use Nominatim reverse geocode via the API to find a nearby station
|
||||
const geoResults = await api.geocode('Wien', 'at');
|
||||
const geoResults = await api.reverseGeocode(userLat, userLng);
|
||||
// Find the station closest to the user's actual coordinates
|
||||
if (geoResults.length > 0) {
|
||||
const closest = geoResults.reduce((best: { lat: number; lng: number; display_name: string } | null, candidate) => {
|
||||
@@ -144,6 +145,34 @@ export function SettingsScreen({ navigation }: ScreenProps) {
|
||||
}
|
||||
};
|
||||
|
||||
const updateArrivalBuffer = async (value: string) => {
|
||||
const minutes = parseInt(value, 10);
|
||||
if (!isNaN(minutes) && minutes >= 0) {
|
||||
const updated = { ...notifSettings, arrivalBufferMinutes: minutes };
|
||||
setNotifSettings(updated);
|
||||
await saveNotificationSettings(updated);
|
||||
await rescheduleAllNotifications();
|
||||
}
|
||||
};
|
||||
|
||||
const toggleWalking = async (value: boolean) => {
|
||||
const updated = { ...notifSettings, showWalkingOption: value };
|
||||
setNotifSettings(updated);
|
||||
await saveNotificationSettings(updated);
|
||||
await rescheduleAllNotifications();
|
||||
};
|
||||
|
||||
const toggleBike = async (value: boolean) => {
|
||||
const updated = { ...notifSettings, showBikeOption: value };
|
||||
setNotifSettings(updated);
|
||||
await saveNotificationSettings(updated);
|
||||
await rescheduleAllNotifications();
|
||||
};
|
||||
|
||||
const toggleAdvanced = () => {
|
||||
setShowAdvanced(!showAdvanced);
|
||||
};
|
||||
|
||||
return (
|
||||
<View style={styles.container}>
|
||||
{/* Origin Station */}
|
||||
@@ -199,6 +228,46 @@ export function SettingsScreen({ navigation }: ScreenProps) {
|
||||
<Text style={styles.hint}>
|
||||
Du wirst {notifSettings.bufferMinutes} Minuten vor der geplanten Abfahrt erinnert.
|
||||
</Text>
|
||||
|
||||
<TouchableOpacity style={[styles.advancedToggle, styles.locBtn]} onPress={toggleAdvanced}>
|
||||
<Text style={styles.locBtnText}>
|
||||
{showAdvanced ? '↑ Weniger Optionen zeigen' : '↓ Mehr Optionen zeigen'}
|
||||
</Text>
|
||||
</TouchableOpacity>
|
||||
|
||||
{showAdvanced && (
|
||||
<View style={styles.advancedSection}>
|
||||
<Text style={styles.settingLabel}>Ankunfts-Puffer (Minuten)</Text>
|
||||
<TextInput
|
||||
style={[styles.input, styles.numberInput]}
|
||||
value={String(notifSettings.arrivalBufferMinutes)}
|
||||
onChangeText={updateArrivalBuffer}
|
||||
keyboardType="numeric"
|
||||
accessibilityLabel="Ankunfts-Puffer in Minuten"
|
||||
/>
|
||||
<Text style={styles.hint}>Wie viele Minuten vor der Event-Zeit du am Ziel ankommen möchtest</Text>
|
||||
|
||||
<View style={styles.settingRow}>
|
||||
<Text style={styles.settingLabel}>Zu Fuß-Option anzeigen</Text>
|
||||
<Switch
|
||||
value={notifSettings.showWalkingOption}
|
||||
onValueChange={toggleWalking}
|
||||
trackColor={{ true: '#007AFF', false: '#e5e5ea' }}
|
||||
accessibilityLabel="Zu Fuß-Option umschalten"
|
||||
/>
|
||||
</View>
|
||||
|
||||
<View style={styles.settingRow}>
|
||||
<Text style={styles.settingLabel}>Fahrrad-Option anzeigen</Text>
|
||||
<Switch
|
||||
value={notifSettings.showBikeOption}
|
||||
onValueChange={toggleBike}
|
||||
trackColor={{ true: '#007AFF', false: '#e5e5ea' }}
|
||||
accessibilityLabel="Fahrrad-Option umschalten"
|
||||
/>
|
||||
</View>
|
||||
</View>
|
||||
)}
|
||||
</View>
|
||||
</View>
|
||||
);
|
||||
@@ -235,6 +304,16 @@ const styles = StyleSheet.create({
|
||||
},
|
||||
locBtnText: { fontSize: 15, color: '#007AFF', fontWeight: '500' },
|
||||
locStatus: { fontSize: 12, color: '#8e8e93', marginTop: 6 },
|
||||
advancedToggle: {
|
||||
marginTop: 12,
|
||||
marginBottom: 12,
|
||||
},
|
||||
advancedSection: {
|
||||
marginTop: 16,
|
||||
paddingTop: 16,
|
||||
borderTopWidth: 1,
|
||||
borderTopColor: '#e5e5ea',
|
||||
},
|
||||
settingRow: { flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center', marginBottom: 12 },
|
||||
settingLabel: { fontSize: 14, color: '#1c1c1e' },
|
||||
hint: { fontSize: 12, color: '#8e8e93', marginTop: 6 },
|
||||
|
||||
Reference in New Issue
Block a user