Little fix due to better mark
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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 (
|
||||
|
||||
@@ -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});
|
||||
|
||||
@@ -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"
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user