add Zustand and del unnecessary files

This commit is contained in:
Patryk
2025-05-15 00:06:38 +02:00
parent c0b8df55a6
commit 1a8144aee4
10 changed files with 295 additions and 248 deletions

View File

@@ -1,33 +1,42 @@
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 { deleteLocation } from '@/api/locations';
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 { useEffect } from "react";
import Ionicons from "@expo/vector-icons/Ionicons";
import useLocationStore from "@/locationStore";
export default function RootLayout() {
const colorScheme = useColorScheme();
const theme = colorScheme === 'dark' ? MD3DarkTheme :
MD3LightTheme;
const theme = colorScheme === "dark" ? MD3DarkTheme : MD3LightTheme;
const router = useRouter();
const fetchLocations = useLocationStore((state) => state.fetchLocations);
const handleDelete = (id) => {
deleteLocation(id);
while (router.canGoBack()) {
router.back();
useEffect(() => {
fetchLocations();
}, []);
console.log();
const deleteLocation = useLocationStore((state) => state.deleteLocation);
const handleDelete = async (id) => {
const isDeleted = await deleteLocation(id);
if (isDeleted) {
router.replace("/");
}
router.replace('/');
};
return (
<PaperProvider theme={theme} >
<Stack screenOptions={{
headerStyle: {
backgroundColor: theme.colors.primaryContainer,
borderBottomWidth: 0
},
headerTintColor: theme.colors.primary,
}}>
<PaperProvider theme={theme}>
<Stack
screenOptions={{
headerStyle: {
backgroundColor: theme.colors.primaryContainer,
borderBottomWidth: 0,
},
headerTintColor: theme.colors.primary,
}}
>
<Stack.Screen name="(tabs)" options={{ headerShown: false }} />
<Stack.Screen
name="location/[id]"
@@ -40,18 +49,28 @@ export default function RootLayout() {
asChild
style={{ marginRight: 11 }}
>
<Ionicons name="pencil" color={theme.colors.primary} size={24} />
<Ionicons
name="pencil"
color={theme.colors.primary}
size={24}
/>
</Link>
),
})}
/>
<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.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>