Skip to content
Snippets Groups Projects
Commit e8769d69 authored by Antoine Marquis's avatar Antoine Marquis
Browse files

Intelligence in select.js

parent 7ac5fb86
No related branches found
No related tags found
No related merge requests found
import { View, Text } from "react-native"
export function SelectInput({list, onChangeText, style, value}) {
export function SelectInput({
list,
onChangeText,
style,
value,
useOther = false,
otherStr = "Autre",
SetIsMain = null
}) {
useOther ? SetIsMain(otherStr == value) : null
return (
<View style={{...style, flexDirection:"row"}}>
{list.map((item) => {
{(useOther ? [...list, otherStr] : list).map((item) => {
const fontColor = value == item ? "red" : "black"
return (
<Text
......
......@@ -13,6 +13,12 @@ export default function NewPlace() {
const [prix, setprix] = useState("");
const [type, settype] = useState("");
const [isMainCity, setIsMainCity] = useState(true);
const [isMainType, setIsMainType] = useState(true);
const cityList = ["Compiègne", "Margny", "Venette"]
const typeList = ["Maison", "Appartement", "Studio"]
function createPlace() {
if (!address || !city || !name || !prix || !type)
{
......@@ -38,25 +44,6 @@ export default function NewPlace() {
marginBottom: 15
}
})
const cityList = ["Compiègne", "Margny", "Venette", "Autre"]
const typeList = ["Maison", "Appartement", "Studio", "Autre"]
const isMainCity = () => {
let is = false
cityList.forEach(element => {
if(city == element && city != cityList[cityList.length - 1]) is = true
});
return is
}
const isMainType = () => {
let is = false
typeList.forEach(element => {
if(type == element && type != typeList[typeList.length - 1]) is = true
});
return is
}
return (
<View style={{marginTop:20, backgroundColor:"white", height:"100%"}} >
......@@ -64,8 +51,8 @@ export default function NewPlace() {
<Text style={style.titles}>Adresse</Text>
<TextInput style={style.input} onChangeText={setaddress} value={address} placeholder="Adresse"/>
<TextInput style={style.input} onChangeText={setcomp} value={comp} placeholder="Complément"/>
<SelectInput style={{fontSize:style.input.fontSize, marginTop:10, marginBottom:10}} onChangeText={setcity} value={city} list={cityList}/>
{isMainCity() ? null : <TextInput style={style.input} onChangeText={setcity} value={city}/>}
<SelectInput style={{fontSize:style.input.fontSize, marginTop:10, marginBottom:10}} SetIsMain={setIsMainCity} useOther={true} onChangeText={setcity} value={city} list={cityList}/>
{isMainCity ? <TextInput style={style.input} onChangeText={setcity} value={city}/> : null}
<Text style={style.titles}>Nom</Text>
<TextInput style={style.input} onChangeText={setname} value={name} placeholder="Nom"/>
<Text style={style.titles}>Places restantes</Text>
......@@ -73,8 +60,8 @@ export default function NewPlace() {
<Text style={style.titles}>Prix</Text>
<TextInput style={style.input} onChangeText={setprix} value={prix} placeholder="Prix"/>
<Text style={style.titles}>Type de logement</Text>
<SelectInput style={{fontSize:style.input.fontSize, marginTop:10, marginBottom:10}} onChangeText={settype} value={type} list={typeList}/>
{isMainType() ? null : <TextInput style={{...style.input, marginBottom:25}} onChangeText={settype} value={type}/>}
<SelectInput style={{fontSize:style.input.fontSize, marginTop:10, marginBottom:10}} SetIsMain={setIsMainType} useOther={true} onChangeText={settype} value={type} list={typeList}/>
{isMainType ? <TextInput style={{...style.input, marginBottom:25}} onChangeText={settype} value={type}/> : null}
<TouchableOpacity style={{borderRadius:1, backgroundColor:"black", padding:10, width:180}} onPress={createPlace}>
<Text style={{fontSize:16, color:"white", fontWeight:"bold", textAlign:"center"}}>Ajouter le logement</Text>
</TouchableOpacity>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment