Little fix due to better mark
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
|
|
||||||
const API_URL = "https://hopp.zikor.pl";
|
const API_URL = "http://192.168.0.130:9010";
|
||||||
|
|
||||||
export async function listLocations() {
|
export async function listLocations() {
|
||||||
try {
|
try {
|
||||||
@@ -9,6 +9,8 @@ export async function listLocations() {
|
|||||||
return "No locations found";
|
return "No locations found";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log("Locations fetched successfully");
|
||||||
|
|
||||||
return response.data.map(location => ({
|
return response.data.map(location => ({
|
||||||
...location,
|
...location,
|
||||||
imageSource: normalizeImageSource(location.image)
|
imageSource: normalizeImageSource(location.image)
|
||||||
@@ -63,6 +65,7 @@ export async function addLocation(location) {
|
|||||||
console.log("Error adding location");
|
console.log("Error adding location");
|
||||||
return("Failed to add location");
|
return("Failed to add location");
|
||||||
}
|
}
|
||||||
|
console.log("Location added successfully:", response.data);
|
||||||
return response.data;
|
return response.data;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error adding location:", error);
|
console.error("Error adding location:", error);
|
||||||
@@ -79,6 +82,7 @@ export async function updateLocation(id, location) {
|
|||||||
console.log("Failed to update location");
|
console.log("Failed to update location");
|
||||||
return("Failed to update location");
|
return("Failed to update location");
|
||||||
}
|
}
|
||||||
|
console.log("Location updated successfully:", response.data);
|
||||||
return response.data;
|
return response.data;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error while updating location:", error);
|
console.error("Error while updating location:", error);
|
||||||
@@ -93,6 +97,7 @@ export async function deleteLocation(id) {
|
|||||||
console.log("Error deleting location");
|
console.log("Error deleting location");
|
||||||
return("Failed to delete location");
|
return("Failed to delete location");
|
||||||
}
|
}
|
||||||
|
console.log("Location deleted successfully:", response.data);
|
||||||
return response.data;
|
return response.data;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error while deleting location:", error);
|
console.error("Error while deleting location:", error);
|
||||||
|
|||||||
@@ -9,8 +9,7 @@ import useLocationStore from "@/locationStore";
|
|||||||
|
|
||||||
export default function Index() {
|
export default function Index() {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const {locations} = useLocationStore();
|
const {locations, loading} = useLocationStore();
|
||||||
const loading = useLocationStore((state) => state.loading);
|
|
||||||
|
|
||||||
if (loading) {
|
if (loading) {
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ const useLocationStore = create((set, get) => ({
|
|||||||
},
|
},
|
||||||
|
|
||||||
addLocation: async (location) => {
|
addLocation: async (location) => {
|
||||||
set({loading: true, error: null});
|
|
||||||
try {
|
try {
|
||||||
const newLoc = await api.addLocation(location);
|
const newLoc = await api.addLocation(location);
|
||||||
const normalizedLoc = {
|
const normalizedLoc = {
|
||||||
@@ -26,7 +25,6 @@ const useLocationStore = create((set, get) => ({
|
|||||||
};
|
};
|
||||||
set((state) => ({
|
set((state) => ({
|
||||||
locations: [...state.locations, normalizedLoc],
|
locations: [...state.locations, normalizedLoc],
|
||||||
loading: false,
|
|
||||||
}));
|
}));
|
||||||
return normalizedLoc;
|
return normalizedLoc;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -36,18 +34,22 @@ const useLocationStore = create((set, get) => ({
|
|||||||
},
|
},
|
||||||
|
|
||||||
updateLocation: async (id, location) => {
|
updateLocation: async (id, location) => {
|
||||||
set({loading: true, error: null});
|
|
||||||
try {
|
try {
|
||||||
const updated = await api.updateLocation(id, location);
|
const updated = await api.updateLocation(id, location);
|
||||||
|
const normalizedLoc = {
|
||||||
|
...updated,
|
||||||
|
imageSource: api.normalizeImageSource(updated.image)
|
||||||
|
};
|
||||||
|
|
||||||
|
const stringId = String(id);
|
||||||
|
|
||||||
set((state) => ({
|
set((state) => ({
|
||||||
locations: state.locations.map((loc) =>
|
locations: state.locations.map((loc) =>
|
||||||
loc.id === id ? updated : loc
|
String(loc.id) === stringId ? normalizedLoc : loc
|
||||||
),
|
),
|
||||||
|
|
||||||
loading: false,
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
return updated;
|
return normalizedLoc;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
set({error, loading: false});
|
set({error, loading: false});
|
||||||
return null;
|
return null;
|
||||||
@@ -55,13 +57,15 @@ const useLocationStore = create((set, get) => ({
|
|||||||
},
|
},
|
||||||
|
|
||||||
deleteLocation: async (id) => {
|
deleteLocation: async (id) => {
|
||||||
set({loading: true, error: null});
|
|
||||||
try {
|
try {
|
||||||
const deleted = await api.deleteLocation(id);
|
const deleted = await api.deleteLocation(id);
|
||||||
|
const stringId = String(id);
|
||||||
|
|
||||||
set((state) => ({
|
set((state) => ({
|
||||||
locations: state.locations.filter((loc) => loc.id !== id),
|
locations: state.locations.filter((loc) => String(loc.id) !== stringId),
|
||||||
loading: false,
|
loading: false,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
return deleted;
|
return deleted;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
set({error, loading: false});
|
set({error, loading: false});
|
||||||
|
|||||||
@@ -15,16 +15,16 @@
|
|||||||
"expo": "^53.0.0",
|
"expo": "^53.0.0",
|
||||||
"expo-constants": "~17.1.6",
|
"expo-constants": "~17.1.6",
|
||||||
"expo-linking": "~7.1.4",
|
"expo-linking": "~7.1.4",
|
||||||
"expo-router": "~5.0.7",
|
"expo-router": "~5.1.0",
|
||||||
"expo-status-bar": "~2.2.3",
|
"expo-status-bar": "~2.2.3",
|
||||||
"expo-image-picker": "~16.1.4",
|
"expo-image-picker": "~16.1.4",
|
||||||
"expo-location": "~18.1.5",
|
"expo-location": "~18.1.5",
|
||||||
"react": "19.0.0",
|
"react": "19.0.0",
|
||||||
"react-dom": "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-paper": "^5.13.1",
|
||||||
"react-native-safe-area-context": "5.4.0",
|
"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",
|
"react-native-web": "^0.20.0",
|
||||||
"zustand": "^5.0.3"
|
"zustand": "^5.0.3"
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user