fix add
This commit is contained in:
@@ -1,19 +1,23 @@
|
||||
import { useState } from 'react';
|
||||
import { StyleSheet, Platform, KeyboardAvoidingView, ScrollView } from 'react-native';
|
||||
import { TextInput, Button, Snackbar } from 'react-native-paper';
|
||||
import useLocationStore from '@/store';
|
||||
import { useState } from "react";
|
||||
import {
|
||||
StyleSheet,
|
||||
Platform,
|
||||
KeyboardAvoidingView,
|
||||
ScrollView,
|
||||
} from "react-native";
|
||||
import { TextInput, Button, Snackbar } from "react-native-paper";
|
||||
import useLocationStore from "@/store";
|
||||
|
||||
export default function FormScreen() {
|
||||
const addLocation = useLocationStore((state) => state.addLocation);
|
||||
|
||||
const [formData, setFormData] = useState({
|
||||
name: '',
|
||||
description: '',
|
||||
image: '',
|
||||
area: '',
|
||||
population: '',
|
||||
name: "",
|
||||
description: "",
|
||||
image: "",
|
||||
area: "",
|
||||
population: "",
|
||||
});
|
||||
const [message, setMessage] = useState('');
|
||||
const [message, setMessage] = useState("");
|
||||
const [visible, setVisible] = useState(false);
|
||||
|
||||
const handleAddLocation = () => {
|
||||
@@ -25,7 +29,7 @@ export default function FormScreen() {
|
||||
formData.population
|
||||
) {
|
||||
const newLocation = {
|
||||
id: Date.now(), // Generowanie unikalnego ID
|
||||
id: Date.now(),
|
||||
name: formData.name,
|
||||
description: formData.description,
|
||||
image: formData.image,
|
||||
@@ -36,16 +40,16 @@ export default function FormScreen() {
|
||||
addLocation(newLocation);
|
||||
|
||||
setFormData({
|
||||
name: '',
|
||||
description: '',
|
||||
image: '',
|
||||
area: '',
|
||||
population: '',
|
||||
name: "",
|
||||
description: "",
|
||||
image: "",
|
||||
area: "",
|
||||
population: "",
|
||||
});
|
||||
setMessage('Lokalizacja została dodana!');
|
||||
setMessage("Lokalizacja została dodana!");
|
||||
setVisible(true);
|
||||
} else {
|
||||
setMessage('Wypełnij wszystkie pola!');
|
||||
setMessage("Wypełnij wszystkie pola!");
|
||||
setVisible(true);
|
||||
}
|
||||
};
|
||||
@@ -53,7 +57,7 @@ export default function FormScreen() {
|
||||
return (
|
||||
<KeyboardAvoidingView
|
||||
style={{ flex: 1 }}
|
||||
behavior={Platform.OS === 'ios' ? 'padding' : 'height'}
|
||||
behavior={Platform.OS === "ios" ? "padding" : "height"}
|
||||
>
|
||||
<ScrollView contentContainerStyle={styles.container}>
|
||||
<Snackbar
|
||||
@@ -67,7 +71,7 @@ export default function FormScreen() {
|
||||
mode="outlined"
|
||||
label="Nazwa"
|
||||
placeholder="Wpisz nazwę"
|
||||
style={{ margin: 10, width: '100%' }}
|
||||
style={{ margin: 10, width: "100%" }}
|
||||
value={formData.name}
|
||||
onChangeText={(e) => setFormData({ ...formData, name: e })}
|
||||
/>
|
||||
@@ -75,7 +79,7 @@ export default function FormScreen() {
|
||||
mode="outlined"
|
||||
label="Opis"
|
||||
placeholder="Wpisz opis"
|
||||
style={{ margin: 10, width: '100%' }}
|
||||
style={{ margin: 10, width: "100%" }}
|
||||
multiline={true}
|
||||
value={formData.description}
|
||||
onChangeText={(e) => setFormData({ ...formData, description: e })}
|
||||
@@ -85,7 +89,7 @@ export default function FormScreen() {
|
||||
label="Link do zdjęcia"
|
||||
placeholder="Wpisz link do zdjęcia"
|
||||
multiline={true}
|
||||
style={{ margin: 10, width: '100%' }}
|
||||
style={{ margin: 10, width: "100%" }}
|
||||
value={formData.image}
|
||||
onChangeText={(e) => setFormData({ ...formData, image: e })}
|
||||
/>
|
||||
@@ -93,7 +97,7 @@ export default function FormScreen() {
|
||||
mode="outlined"
|
||||
label="Powierzchnia"
|
||||
placeholder="Wpisz powierzchnię"
|
||||
style={{ margin: 10, width: '100%' }}
|
||||
style={{ margin: 10, width: "100%" }}
|
||||
value={formData.area}
|
||||
onChangeText={(e) => setFormData({ ...formData, area: e })}
|
||||
/>
|
||||
@@ -101,15 +105,15 @@ export default function FormScreen() {
|
||||
mode="outlined"
|
||||
label="Ludność"
|
||||
placeholder="Wpisz liczbę ludności"
|
||||
style={{ margin: 10, width: '100%' }}
|
||||
style={{ margin: 10, width: "100%" }}
|
||||
value={formData.population}
|
||||
keyboardType="numeric"
|
||||
onChangeText={(e) => setFormData({ ...formData, population: e })}
|
||||
/>
|
||||
<Button
|
||||
style={{ margin: 10, width: '100%' }}
|
||||
style={{ margin: 10, width: "100%" }}
|
||||
icon="plus-circle-outline"
|
||||
mode={'contained'}
|
||||
mode={"contained"}
|
||||
onPress={handleAddLocation}
|
||||
>
|
||||
Dodaj
|
||||
@@ -122,8 +126,8 @@ export default function FormScreen() {
|
||||
const styles = StyleSheet.create({
|
||||
container: {
|
||||
flex: 1,
|
||||
backgroundColor: '#25292e',
|
||||
justifyContent: 'flex-start',
|
||||
alignItems: 'center',
|
||||
backgroundColor: "#25292e",
|
||||
justifyContent: "flex-start",
|
||||
alignItems: "center",
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user