add Zustand and del unnecessary files
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user