init State Mangement and add del function

This commit is contained in:
Patryk
2025-04-22 18:35:39 +02:00
parent 5e44b30a49
commit 8f5b151d87
8 changed files with 252 additions and 185 deletions

View File

@@ -1,13 +1,21 @@
import { Link, Stack } from 'expo-router';
import { useColorScheme } from 'react-native';
import { Link, Stack, useRouter } from 'expo-router';
import { useColorScheme} from 'react-native';
import { PaperProvider} from 'react-native-paper';
import { MD3LightTheme, MD3DarkTheme } from 'react-native-paper';
import Ionicons from '@expo/vector-icons/Ionicons';
import useLocationStore from '@/store';
export default function RootLayout() {
const colorScheme = useColorScheme();
const theme = colorScheme === 'dark' ? MD3DarkTheme :
MD3LightTheme;
const deleteLocation = useLocationStore((state) => state.deleteLocation);
const router = useRouter();
const handleDelete = (id) => {
deleteLocation(id);
router.replace('/');
};
return (
<PaperProvider theme={theme} >
@@ -35,7 +43,12 @@ export default function RootLayout() {
),
})}
/>
<Stack.Screen name="location/edit/[id]" options={{ title: "Edycja" }} />
<Stack.Screen name="location/edit/[id]" options={({ route }) =>({ title: "Edycja",
headerRight: () => (
<Ionicons name="trash-bin" color={theme.colors.primary} size={24} onPress={() => handleDelete(route.params.id)}/>
), })}
/>
</Stack>
</PaperProvider>
);