All files / atlas-mobile-ts/src/components/Map/Panels/LandmarkDetailsPanel DetailsBody.tsx

0% Statements 0/25
0% Branches 0/14
0% Functions 0/8
0% Lines 0/24

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183                                                                                                                                                                                                                                                                                                                                                                             
/* Copyright (C) Click & Push Accessibility, Inc - All Rights Reserved
 * Unauthorized copying of this file, via any medium is strictly prohibited
 * Proprietary and confidential
 * Written and maintained by the Click & Push Development team 
 * <dev@clicknpush.ca>, January 2022
 */
 
import { FontAwesome } from "@expo/vector-icons";
import { ImageInfo } from "expo-image-picker/build/ImagePicker.types";
import React, { MutableRefObject, useEffect, useState } from "react";
import { ActivityIndicator, FlatList, Image, ScrollView, StyleSheet, Text, TextInput, TouchableOpacity, View } from "react-native";
import Picker from "react-native-picker-select";
import { QueryStatus } from "react-query";
import { LMComment } from "../../../../hooks/useComments";
import { Landmark, LMPhoto, useLandmarks } from "../../../../hooks/useLandmarks";
import { lmTypes } from "../../../../utils/GlobalUtils";
import { IconButton, PrimaryButton } from "../../../Buttons";
import { PhotoPicker } from "../../../PhotoPicker";
import { Separator } from "../../../Separator";
import { CommentsContainer } from "./CommentsContainer";
import { LandmarkPhotos } from "./LandmarkPhotos";
 
interface DetailsBodyProps {
    editingEnabled: boolean,
    updatedLandmark?: Landmark,
    landmark?: Landmark,
    setUpdatedLandmark: (landmark: Landmark) => void,
    comments?: LMComment[],
    commentListRef: MutableRefObject<FlatList>
    commentTextInputRef: MutableRefObject<TextInput>
    focusedCommentId?: string,
    focusComment: (id: string) => void,
    startEditingComment: (comment: LMComment) => void,
    deleteComment: (id: string) => void
    commentBeingEdited?: LMComment, 
    setCommentBeingEdited: (comment: LMComment) => void,
    setNewComment: (commentId: string) => void,
    newCommentId?: string,
    editComment: (comment: LMComment) => void,
    addComment: () => void
    setSelectedImage: (index: number) => void 
    tryDeletePhoto: (photoId: string) => void
    addPhoto: (photo: LMPhoto) => void
    addPhotoStatus: QueryStatus
    deletePhotoStatus: QueryStatus 
    toggleLmDetails: (state: boolean) => void
    setKeyboardOpened: (state: boolean) => void
    keyboardOpened: boolean
    profileId: string
    processingPhoto: boolean
    setProcessingPhoto: (state: boolean) => void
}
 
/**
 * Component that renders the body of the Landmark details panel
*/
export const DetailsBody: React.FC<DetailsBodyProps> = (props) => {
 
    useEffect(() => {
        if (props.editingEnabled) {
            console.log("[LandmarkDetails]: Editing is enabled")
            props.setUpdatedLandmark(props.landmark)
        }
        else {
            props.setUpdatedLandmark(undefined)
        }
    }, [props.editingEnabled])
    
    /**
     * Sub-component that renders picker for landmark types
     * @param 
     */
    const LandmarkTypePicker: React.FC = () => {
        return (
        <View style={{flexDirection: 'row', marginBottom: 20, justifyContent: "space-between"}}> 
            {props.updatedLandmark?.landmark_type ? 
            <>
                <Picker
                    style={{
                        inputIOS: {color: 'white'}, 
                        inputAndroid: {color: 'white'},
                        iconContainer: {flex: 1, justifyContent: 'center', height: '100%'},
                        viewContainer: {padding: 5, elevation: 1, flex: 1, justifyContent: 'center'}, placeholder: {color: 'white'}}}
                    placeholder={{}}
                    value={props.updatedLandmark?.landmark_type}
                    onValueChange={(value) => {
                        props.setUpdatedLandmark({...props.updatedLandmark, landmark_type: value, title: lmTypes[value].label})
                    }}
                    useNativeAndroidPickerStyle={true}
                    items={Object.keys(lmTypes)?.filter(icon => parseInt(icon) != props.landmark?.landmark_type).map(icon => {
                        console.log(icon)
                        return (
                            {label: lmTypes[parseInt(icon)].label.toUpperCase(), value: icon, key: icon}
                        )})} />
                {props.updatedLandmark ? <Image style={{marginLeft: 20}} source={lmTypes[props.updatedLandmark?.landmark_type].image}/> : null}
            </>
            : null}
        </View>
        )
    }
 
    /**
     * Sub-component that renders the view to be displayed when editing is disabled
     * @param 
     */
    const EditingDisabledUpperView: React.FC = () => {
        return (
            <View style={{flexDirection: 'row', justifyContent: 'space-between'}}>
                <View style={{flex: 8, flexDirection: 'column', marginBottom: 20}}>
                    <Text style={{color: 'white', marginBottom: 10, fontSize: 15}}>{lmTypes[props.landmark?.landmark_type]?.label.toUpperCase()}</Text>
                    <ScrollView nestedScrollEnabled={true}>
                        <Text style={{color: 'white', fontSize: 13}}>{props.landmark?.description}</Text>
                    </ScrollView>
                </View>
                {props.landmark?.landmark_type ? <Image source={lmTypes[props.landmark?.landmark_type].image} /> : null}
            </View>
        )
    }
 
    return (
        <ScrollView nestedScrollEnabled={true} contentContainerStyle={{justifyContent: 'space-between'}} style={{flex: 1, marginHorizontal: 20}}>
            {props.editingEnabled ?
            <>
                <LandmarkTypePicker />
                <Separator style={{marginBottom: 20, opacity: .5}} color="lightgray" />
                <Text style={{color: 'white', marginBottom: 10}}>Description</Text>
                <ScrollView nestedScrollEnabled={true} style={{backgroundColor: 'white', marginBottom: 20}}>
                    <TextInput 
                        multiline={true} 
                        style={[styles.input, {fontSize: 13, marginBottom: 10}]}
                        onChangeText={text => props.setUpdatedLandmark({...props.updatedLandmark, description: text})} 
                        value={props.updatedLandmark?.description}/>
                </ScrollView>
            </>: <EditingDisabledUpperView />}
            {!props.editingEnabled ?
            <CommentsContainer
                setKeyboardOpened={props.setKeyboardOpened}
                keyboardOpened={props.keyboardOpened}
                comments={props.comments}
                focusComment={props.focusComment}
                focusedCommentId={props.focusedCommentId}
                commentListRef={props.commentListRef}
                commentTextInputRef={props.commentTextInputRef}
                commentBeingEdited={props.commentBeingEdited}
                addComment={props.addComment}
                setCommentBeingEdited={props.setCommentBeingEdited}
                setNewComment={props.setNewComment}
                newCommentId={props.newCommentId}
                editComment={props.editComment}
                startEditingComment={props.startEditingComment}
                deleteComment={props.deleteComment} /> : null}
            {!props.editingEnabled ?
            <LandmarkPhotos 
                profileId={props.profileId}
                deletePhotoStatus={props.deletePhotoStatus}
                addPhotoStatus={props.addPhotoStatus}
                tryDeletePhoto={props.tryDeletePhoto}
                addPhoto={props.addPhoto}
                toggleLmDetails={props.toggleLmDetails}
                editingEnabled={props.editingEnabled}
                setUpdatedLandmark={props.setUpdatedLandmark}
                updatedLandmark={props.updatedLandmark}
                landmark={props.landmark}
                setSelectedImage={props.setSelectedImage}
                processingPhoto={props.processingPhoto}
                setProcessingPhoto={props.setProcessingPhoto}/>
             : null}
            
        </ScrollView>
    )
}
 
const styles = StyleSheet.create({
    input: {
        padding: 5,
        color: 'black'
    },
    commentContainer: {
        flex: 5,
        marginBottom: 40,
    },
})