From 7b275c4e39dc00315c3e52169aa116f404b993d1 Mon Sep 17 00:00:00 2001 From: Andrii Solianyk Date: Tue, 17 Jun 2025 19:09:27 +0200 Subject: [PATCH] Little fix due to better mark --- api/locations.jsx | 7 ++++++- app/(tabs)/index.jsx | 3 +-- locationStore.js | 22 +++++++++++++--------- package.json | 6 +++--- 4 files changed, 23 insertions(+), 15 deletions(-) diff --git a/api/locations.jsx b/api/locations.jsx index 1adad5c..aceee72 100644 --- a/api/locations.jsx +++ b/api/locations.jsx @@ -1,6 +1,6 @@ import axios from "axios"; -const API_URL = "https://hopp.zikor.pl"; +const API_URL = "http://192.168.0.130:9010"; export async function listLocations() { try { @@ -9,6 +9,8 @@ export async function listLocations() { return "No locations found"; } + console.log("Locations fetched successfully"); + return response.data.map(location => ({ ...location, imageSource: normalizeImageSource(location.image) @@ -63,6 +65,7 @@ export async function addLocation(location) { console.log("Error adding location"); return("Failed to add location"); } + console.log("Location added successfully:", response.data); return response.data; } catch (error) { console.error("Error adding location:", error); @@ -79,6 +82,7 @@ export async function updateLocation(id, location) { console.log("Failed to update location"); return("Failed to update location"); } + console.log("Location updated successfully:", response.data); return response.data; } catch (error) { console.error("Error while updating location:", error); @@ -93,6 +97,7 @@ export async function deleteLocation(id) { console.log("Error deleting location"); return("Failed to delete location"); } + console.log("Location deleted successfully:", response.data); return response.data; } catch (error) { console.error("Error while deleting location:", error); diff --git a/app/(tabs)/index.jsx b/app/(tabs)/index.jsx index cb9725f..c77c1b0 100644 --- a/app/(tabs)/index.jsx +++ b/app/(tabs)/index.jsx @@ -9,8 +9,7 @@ import useLocationStore from "@/locationStore"; export default function Index() { const theme = useTheme(); - const {locations} = useLocationStore(); - const loading = useLocationStore((state) => state.loading); + const {locations, loading} = useLocationStore(); if (loading) { return ( diff --git a/locationStore.js b/locationStore.js index 4bff801..1113fa0 100644 --- a/locationStore.js +++ b/locationStore.js @@ -17,7 +17,6 @@ const useLocationStore = create((set, get) => ({ }, addLocation: async (location) => { - set({loading: true, error: null}); try { const newLoc = await api.addLocation(location); const normalizedLoc = { @@ -26,7 +25,6 @@ const useLocationStore = create((set, get) => ({ }; set((state) => ({ locations: [...state.locations, normalizedLoc], - loading: false, })); return normalizedLoc; } catch (error) { @@ -36,18 +34,22 @@ const useLocationStore = create((set, get) => ({ }, updateLocation: async (id, location) => { - set({loading: true, error: null}); try { const updated = await api.updateLocation(id, location); + const normalizedLoc = { + ...updated, + imageSource: api.normalizeImageSource(updated.image) + }; + + const stringId = String(id); + set((state) => ({ locations: state.locations.map((loc) => - loc.id === id ? updated : loc + String(loc.id) === stringId ? normalizedLoc : loc ), - - loading: false, })); - return updated; + return normalizedLoc; } catch (error) { set({error, loading: false}); return null; @@ -55,13 +57,15 @@ const useLocationStore = create((set, get) => ({ }, deleteLocation: async (id) => { - set({loading: true, error: null}); try { const deleted = await api.deleteLocation(id); + const stringId = String(id); + set((state) => ({ - locations: state.locations.filter((loc) => loc.id !== id), + locations: state.locations.filter((loc) => String(loc.id) !== stringId), loading: false, })); + return deleted; } catch (error) { set({error, loading: false}); diff --git a/package.json b/package.json index 50195d4..c84bee3 100644 --- a/package.json +++ b/package.json @@ -15,16 +15,16 @@ "expo": "^53.0.0", "expo-constants": "~17.1.6", "expo-linking": "~7.1.4", - "expo-router": "~5.0.7", + "expo-router": "~5.1.0", "expo-status-bar": "~2.2.3", "expo-image-picker": "~16.1.4", "expo-location": "~18.1.5", "react": "19.0.0", "react-dom": "19.0.0", - "react-native": "0.79.2", + "react-native": "0.79.3", "react-native-paper": "^5.13.1", "react-native-safe-area-context": "5.4.0", - "react-native-screens": "~4.10.0", + "react-native-screens": "~4.11.1", "react-native-web": "^0.20.0", "zustand": "^5.0.3" },