import React from "react" import { StyleSheet, Text, TextInput, SectionList, Image, View, TouchableOpacity, } from "react-native" import MapView, { Marker } from "react-native-maps" import { Icon, Header } from "../ui" import { api } from "../API" import autobind from "autobind-decorator" import { ifIphoneX } from "react-native-iphone-x-helper" import { workItemTypeText, pad } from "../util" import pinImage from "./images/pin.png" const styles = StyleSheet.create({ container: { flex: 1, backgroundColor: "#FFFFFF", alignItems: "flex-start", justifyContent: "flex-start", }, }) export class Home extends React.Component { constructor(props) { super(props) this.state = { sections: [], } api .listWorkItemActivities() .then((list) => { this.setState({ sections: list.items }) }) .catch((err) => { console.error(err) }) } @autobind _handleNavigatorEvent(event) { switch (event.id) { case "logout": api.logout().then(() => { this.props.history.replace("/login") }) break case "viewer": this.props.push("/viewer") break } } @autobind handleMarkerPress(e, sectionIndex) { if (this.sectionList) { this.sectionList.scrollToLocation({ sectionIndex, itemIndex: 0, viewOffset: 45, }) } } @autobind handleWorkItemsListPress() { this.props.history.push("/workitemlist") } @autobind handleItemSelect(item, index) { this.props.history.push("/activity") } @autobind handleLogoutPress() { this.props.history.replace("/logout") } @autobind handleGlassesPress() { this.props.history.push("/arviewer") } @autobind handleMyLocationPress() { navigator.geolocation.getCurrentPosition((info) => { if (this.map) { this.map.animateToCoordinate({ latitude: info.coords.latitude, longitude: info.coords.longitude, }) } }) } render() { const { sections } = this.state return (
{ this.map = ref }} style={{ width: "100%", height: "50%", }} showsUserLocation showsBuildings={false} showsTraffic={false} showsIndoors={false} zoomControlEnabled initialRegion={{ latitude: 43.653908, longitude: -79.384293, latitudeDelta: 0.0922, longitudeDelta: 0.0922, }}> {sections.map((workItem, index) => ( this.handleMarkerPress(e, index)} /> ))} (this.sectionList = ref)} style={{ width: "100%", flexGrow: 1 }} sections={sections} stickySectionHeadersEnabled={true} renderSectionHeader={({ section: workItem }) => ( {workItemTypeText[workItem.workItemType].toUpperCase()}{" "} {pad(workItem.ticketNumber, 4)} )} keyExtractor={(item) => item._id} renderItem={({ item: activity, section }) => { return ( {activity.status.toUpperCase()} {activity.resolution} {activity.address || "..."} this.handleItemSelect(activity, index)}> ) }} /> Hide List ) } }