|
@@ -8,7 +8,7 @@
|
|
|
import { FontAwesome } from "@expo/vector-icons";
|
|
|
import { ImageInfo } from "expo-image-picker/build/ImagePicker.types";
|
|
|
import React, { memo, useEffect, useState, useRef } from "react";
|
|
|
-import { ActivityIndicator, Dimensions, Image, Platform, SafeAreaView, Text, TextInput, TouchableOpacity, View, ImageSourcePropType, Share, KeyboardEventName, Keyboard, StyleSheet, KeyboardAvoidingView, Alert } from 'react-native';
|
|
|
+import { ActivityIndicator, Dimensions, Image, Platform, SafeAreaView, Text, TextInput, TouchableOpacity, View, ImageSourcePropType, Share, KeyboardEventName, Keyboard, StyleSheet, KeyboardAvoidingView, Alert, Button } from 'react-native';
|
|
|
import { ScrollView } from "react-native-gesture-handler";
|
|
|
import Modal from 'react-native-modal';
|
|
|
import Picker from 'react-native-picker-select';
|
|
@@ -29,6 +29,10 @@ import LandmarkTypePicker from "../../LandmarkTypePicker";
|
|
|
import { values } from "mobx";
|
|
|
import { Icon } from "react-native-paper/lib/typescript/components/Avatar/Avatar";
|
|
|
|
|
|
+import DatePicker from 'react-native-date-picker'
|
|
|
+import CheckBox from "@react-native-community/checkbox";
|
|
|
+import { propertiesContainsFilter } from "@turf/turf";
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* Props for the {@link AddLandmarkPanel} component.
|
|
@@ -62,6 +66,9 @@ const AddLandmarkPanel: React.FC<AddLandmarkProps> = ({ newLandmark, setNewLandm
|
|
|
const [photos, setPhotos] = useState<LMPhoto[]>([])
|
|
|
const [photoSourceMenuOpened, togglePhotoSourceMenu] = useState<boolean>(false)
|
|
|
const [keyboardOpened, setKeyboardOpened] = useState<boolean>(false);
|
|
|
+ const [date, setDate] = useState(new Date())
|
|
|
+ const [showExpire, toggleShowExpire] = useState<boolean>(false)
|
|
|
+ var minDate = new Date();
|
|
|
|
|
|
const addLandmarkMutation = useAddLandmark()
|
|
|
|
|
@@ -80,13 +87,13 @@ const AddLandmarkPanel: React.FC<AddLandmarkProps> = ({ newLandmark, setNewLandm
|
|
|
const validEventString: KeyboardEventName = eventString as KeyboardEventName;
|
|
|
|
|
|
const keyboardDidShowListener = Keyboard.addListener(
|
|
|
- validEventString,
|
|
|
+ "keyboardDidShow",
|
|
|
() => {
|
|
|
setKeyboardOpened(true); // or some other action
|
|
|
}
|
|
|
);
|
|
|
const keyboardDidHideListener = Keyboard.addListener(
|
|
|
- validEventString,
|
|
|
+ "keyboardDidHide",
|
|
|
() => {
|
|
|
setKeyboardOpened(false); // or some other action
|
|
|
}
|
|
@@ -103,10 +110,9 @@ const AddLandmarkPanel: React.FC<AddLandmarkProps> = ({ newLandmark, setNewLandm
|
|
|
* Returns a height for the modal depending on if an image is maximzed, if the keyboard is opened, and if the current landmark has photos associated with it
|
|
|
*/
|
|
|
const determineModalHeight = () => {
|
|
|
- if (keyboardOpened) {
|
|
|
+ if (keyboardOpened)
|
|
|
return Dimensions.get("window").height * .45
|
|
|
- }
|
|
|
- else if (photos?.length > 0)
|
|
|
+ else if (photos?.length > 0 || showExpire)
|
|
|
return Dimensions.get("window").height * .9
|
|
|
else
|
|
|
return Dimensions.get("window").height * .6
|
|
@@ -140,6 +146,22 @@ const AddLandmarkPanel: React.FC<AddLandmarkProps> = ({ newLandmark, setNewLandm
|
|
|
addLandmarkMutation.reset()
|
|
|
}, [visible]);
|
|
|
|
|
|
+ useEffect(() => {
|
|
|
+ if (!showExpire && newLandmark) {
|
|
|
+ newLandmark.expiry_date = null
|
|
|
+ }
|
|
|
+ else if (showExpire && newLandmark) {
|
|
|
+ newLandmark.expiry_date = date
|
|
|
+ }
|
|
|
+ }, [showExpire])
|
|
|
+
|
|
|
+ useEffect(() => {
|
|
|
+ if (newLandmark) {
|
|
|
+ console.log(date)
|
|
|
+ newLandmark.expiry_date = date
|
|
|
+ }
|
|
|
+ }, [date])
|
|
|
+
|
|
|
/**
|
|
|
* Calls {@link addLandmarkAsync} from {@link useLandmarks} to initate the process of adding a landmark, then closes the modal.
|
|
|
*/
|
|
@@ -184,6 +206,8 @@ const AddLandmarkPanel: React.FC<AddLandmarkProps> = ({ newLandmark, setNewLandm
|
|
|
setVisible(false)
|
|
|
togglePhotoSourceMenu(false)
|
|
|
setNewLandmark({})
|
|
|
+ toggleShowExpire(false)
|
|
|
+ setDate(new Date())
|
|
|
}
|
|
|
|
|
|
const addPhoto = (result: ImageInfo) => {
|
|
@@ -267,10 +291,31 @@ const AddLandmarkPanel: React.FC<AddLandmarkProps> = ({ newLandmark, setNewLandm
|
|
|
value: icon, key: lmTypes[parseInt(icon)]?.cat.toUpperCase() }
|
|
|
)
|
|
|
})}/>
|
|
|
-
|
|
|
+ <View style={{ paddingHorizontal: 15, paddingVertical: 10, flex: 1, flexDirection: "row"}}>
|
|
|
+ <Text style={{color: "white", margin: 0, fontSize: 16}}>Add expiry date?</Text>
|
|
|
+ <CheckBox
|
|
|
+ value={showExpire}
|
|
|
+ boxType="square"
|
|
|
+ onValueChange={() => toggleShowExpire(!showExpire)}
|
|
|
+ tintColors={{true: "white", false: "white"}}
|
|
|
+ tintColor="white"
|
|
|
+ onCheckColor="#00000000"
|
|
|
+ onFillColor="white"
|
|
|
+ onTintColor="white"
|
|
|
+ style={{borderColor: "white", marginLeft: 10, width: 20, height: 20}}/>
|
|
|
+ </View>
|
|
|
+ <View style={{flex: 1, alignSelf: "stretch"}}>
|
|
|
+ {showExpire && !keyboardOpened && <DatePicker
|
|
|
+ mode="date"
|
|
|
+ date={date}
|
|
|
+ onDateChange={setDate}
|
|
|
+ fadeToColor="none"
|
|
|
+ timeZoneOffsetInMinutes={(-1) * (new Date()).getTimezoneOffset()}
|
|
|
+ minimumDate={minDate} />}
|
|
|
+ </View>
|
|
|
</View>
|
|
|
{newLandmark?.landmark_type ?
|
|
|
- <View style={{ justifyContent: 'flex-end', flexDirection: 'row', paddingHorizontal: 20, marginTop: 5 }}>
|
|
|
+ <View style={{ justifyContent: 'flex-end', flexDirection: 'row', paddingHorizontal: 20, paddingBottom: 10, marginTop: 5 }}>
|
|
|
{newLandmark.description && newLandmark.title ?
|
|
|
<View style={{ flexDirection: 'row' }}>
|
|
|
<TouchableOpacity onPress={async () => await submit()}><Text style={{ color: 'white', marginRight: 25 }}>Add</Text></TouchableOpacity>
|