get list of location and get location by id

This commit is contained in:
2025-05-13 15:55:20 +02:00
parent c242f92745
commit 395d68a31a
5 changed files with 344 additions and 10 deletions

View File

@@ -1,13 +1,36 @@
import { View, ScrollView, StyleSheet } from 'react-native';
import { Text, Card } from 'react-native-paper';
import { View, ScrollView, StyleSheet, ActivityIndicator } from 'react-native';
import { useTheme, Text, Card } from 'react-native-paper';
import { useLocalSearchParams } from 'expo-router';
import useLocationStore from '@/store';
import { useEffect, useState } from 'react';
import { getLocation } from '@/api/locations';
export default function Location() {
const theme = useTheme();
const { id } = useLocalSearchParams();
const location = useLocationStore((state) =>
state.locations.find((loc) => loc.id == id)
);
const [location, setLocation] = useState(null);
const [loading, setLoading] = useState(true);
useEffect(() => {
const fetchLocation = async () => {
try {
const data = await getLocation(id)
setLocation(data);
} catch (error) {
console.error("Error fetching location:", error);
} finally {
setLoading(false);
}
}
fetchLocation();
}, [id]);
if (loading) {
return (
<View style={[styles.container, { backgroundColor: theme.colors.background }]}>
<ActivityIndicator size="large" color={theme.colors.primary} />
</View>
);
}
if (!location) {
return (