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