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

@@ -6,7 +6,7 @@ import {
ScrollView,
} from "react-native";
import { TextInput, Button, Snackbar } from "react-native-paper";
import { addLocation } from "@/api/locations";
import useLocationStore from "@/locationStore";
export default function FormScreen() {
const [formData, setFormData] = useState({
@@ -19,7 +19,9 @@ export default function FormScreen() {
const [message, setMessage] = useState("");
const [visible, setVisible] = useState(false);
const handleAddLocation = () => {
const addLocation = useLocationStore((state) => state.addLocation);
const handleAddLocation = async () => {
if (
formData.name &&
formData.description &&
@@ -36,8 +38,7 @@ export default function FormScreen() {
population: parseInt(formData.population),
};
addLocation(newLocation);
const added = await addLocation(newLocation);
setFormData({
name: "",
description: "",
@@ -45,7 +46,7 @@ export default function FormScreen() {
area: 0,
population: 0,
});
if(addLocation != null) {
if (added != null) {
setMessage("Lokalizacja została dodana!");
setVisible(true);
} else {