Bug fixing

This commit is contained in:
John Lyon-Smith
2018-04-23 14:01:52 -07:00
parent 5cb13f7498
commit 9730c83c9c
26 changed files with 121 additions and 147 deletions

Binary file not shown.

View File

@@ -390,14 +390,18 @@ class API extends EventEmitter {
method: "GET", method: "GET",
mode: "no-cors", mode: "no-cors",
} }
let headers = new Headers()
fetch( headers.set("Referer", config.refererURL)
fetchOptions.headers = headers
const path =
config.googleGeocodeURL + config.googleGeocodeURL +
`?latlng=${coord.latitude},${coord.longitude}&key=${ `?latlng=${coord.latitude},${coord.longitude}&key=${
config.googleAPIKey config.googleGeocodeAPIKey
}`, }`
fetchOptions
) fetch(path, fetchOptions)
.then((res) => { .then((res) => {
return Promise.all([Promise.resolve(res), res.json()]) return Promise.all([Promise.resolve(res), res.json()])
}) })
@@ -407,7 +411,7 @@ class API extends EventEmitter {
if (res.ok) { if (res.ok) {
let address = "" let address = ""
if (responseBody.results && responseBody.result.length > 0) { if (responseBody.results && responseBody.results.length > 0) {
address = responseBody.results[0].formatted_address address = responseBody.results[0].formatted_address
} }

View File

@@ -15,6 +15,7 @@ import {
import autobind from "autobind-decorator" import autobind from "autobind-decorator"
import backImage from "./images/back.png" import backImage from "./images/back.png"
import { config } from "../config" import { config } from "../config"
import "url-search-params-polyfill"
const shapes = { const shapes = {
order: { order: {

View File

@@ -27,6 +27,7 @@ import KeyboardSpacer from "react-native-keyboard-spacer"
import { isIphoneX } from "react-native-iphone-x-helper" import { isIphoneX } from "react-native-iphone-x-helper"
import { api } from "../API" import { api } from "../API"
import { formatLatLng, parseLatLng } from "../util" import { formatLatLng, parseLatLng } from "../util"
import "url-search-params-polyfill"
const styles = StyleSheet.create({ const styles = StyleSheet.create({
container: { container: {
@@ -189,7 +190,7 @@ export class Activity extends React.Component {
<BoundHeader <BoundHeader
binder={binder} binder={binder}
name="header" name="header"
title="Work Item" title="Activity"
leftButton={{ icon: "back", onPress: this.handleBackPress }} leftButton={{ icon: "back", onPress: this.handleBackPress }}
rightButton={{ icon: "done", onPress: this.handleDonePress }} rightButton={{ icon: "done", onPress: this.handleDonePress }}
/> />
@@ -220,6 +221,7 @@ export class Activity extends React.Component {
label="Date &amp; Time:" label="Date &amp; Time:"
/> />
<BoundInput binder={binder} name="location" label="Location:" /> <BoundInput binder={binder} name="location" label="Location:" />
<View style={{ flexDirection: "column", justifyContent: "center" }}>
<MapView <MapView
style={{ style={{
flexDirection: "column", flexDirection: "column",
@@ -244,7 +246,8 @@ export class Activity extends React.Component {
longitude: -79.384293, longitude: -79.384293,
latitudeDelta: 0.0922, latitudeDelta: 0.0922,
longitudeDelta: 0.0421, longitudeDelta: 0.0421,
}}> }}
/>
<Icon <Icon
name="target" name="target"
size={24} size={24}
@@ -254,7 +257,7 @@ export class Activity extends React.Component {
alignSelf: "center", alignSelf: "center",
}} }}
/> />
</MapView> </View>
</View> </View>
<View style={styles.panel}> <View style={styles.panel}>
<PhotoPanel /> <PhotoPanel />

View File

@@ -3,5 +3,5 @@ import { Route, Redirect } from "react-router-native"
export const DefaultRoute = () => { export const DefaultRoute = () => {
// NOTE: When working on the app, change this to the page you are working on // NOTE: When working on the app, change this to the page you are working on
return <Route render={() => <Redirect to={"/activity"} />} /> return <Route render={() => <Redirect to={"/workItem"} />} />
} }

View File

@@ -125,7 +125,7 @@ export class Login extends React.Component {
} }
render() { render() {
const { messageModal, apiModal } = this.state const { messageModal, apiModal, waitModal } = this.state
return ( return (
<View style={Login.styles.page} behavior="padding"> <View style={Login.styles.page} behavior="padding">

View File

@@ -27,9 +27,9 @@ import { ensurePermissions } from "../App"
import { versionInfo } from "../version" import { versionInfo } from "../version"
import { config } from "../config" import { config } from "../config"
import KeyboardSpacer from "react-native-keyboard-spacer" import KeyboardSpacer from "react-native-keyboard-spacer"
import hardhatPinImage from "./images/hardhat.png" import hardhatPinImage from "./images/hardhat-pin.png"
import clipboardPinImage from "./images/clipboard.png" import clipboardPinImage from "./images/clipboard-pin.png"
import questionPinImage from "./images/question.png" import questionPinImage from "./images/question-pin.png"
const neverAskForLocationPermissionKeyName = "NeverAskForLocationPermission" const neverAskForLocationPermissionKeyName = "NeverAskForLocationPermission"
const neverAskForCameraKeyName = "NeverAskForCameraPermission" const neverAskForCameraKeyName = "NeverAskForCameraPermission"
@@ -141,7 +141,7 @@ export class Home extends React.Component {
if (this.state.positionInfo) { if (this.state.positionInfo) {
const coords = this.state.positionInfo.coords const coords = this.state.positionInfo.coords
const workItem = sections[sectionIndex] const workItem = this.sections[sectionIndex]
const [lng, lat] = workItem.location.coordinates const [lng, lat] = workItem.location.coordinates
this.setState({ this.setState({
@@ -159,16 +159,16 @@ export class Home extends React.Component {
@autobind @autobind
handleWorkItemsListPress() { handleWorkItemsListPress() {
const { positionInfo } = this.state const { positionInfo } = this.state
if (positionInfo) {
const { coords } = positionInfo
this.props.history.push( this.props.history.push(
`/workItemList${ `/workItemList?latLng=${coords.latitude},${coords.longitude}`
positionInfo
? "?latLng=" +
coords.latitude.toString() +
"," +
coords.longitude.toString()
: ""
}`
) )
} else {
this.props.history.push("/workItemList")
}
} }
@autobind @autobind
@@ -184,8 +184,8 @@ export class Home extends React.Component {
@autobind @autobind
handleGlassesPress() { handleGlassesPress() {
const { lat: lat1, lng: lng1 } = this.state.positionInfo.coords const { lat: lat1, lng: lng1 } = this.state.positionInfo.coords
const closestWorkItem = null let closestWorkItem = null
const shortestDistance = config.minDistanceToItem let shortestDistance = config.minDistanceToItem
this.state.sections.forEach((workItem) => { this.state.sections.forEach((workItem) => {
const [lng2, lat2] = workItem.location.coordinates const [lng2, lat2] = workItem.location.coordinates
@@ -270,7 +270,7 @@ export class Home extends React.Component {
showsBuildings={false} showsBuildings={false}
showsTraffic={false} showsTraffic={false}
showsIndoors={false} showsIndoors={false}
zoomControlEnabled zoomControlEnabled={false}
region={region}> region={region}>
{sections.map((workItem, index) => ( {sections.map((workItem, index) => (
<Marker <Marker

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.6 KiB

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.6 KiB

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.8 KiB

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.0 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.5 KiB

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 5.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.1 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.5 KiB

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 5.1 KiB

View File

@@ -1,7 +1,7 @@
import React, { Component } from "react" import React, { Component } from "react"
import Modal from "react-native-modal" import Modal from "react-native-modal"
import PropTypes from "prop-types" import PropTypes from "prop-types"
import { View, ActivityIndicator } from "react-native" import { View, Text, ActivityIndicator } from "react-native"
export class WaitModal extends Component { export class WaitModal extends Component {
static propTypes = { static propTypes = {
@@ -18,10 +18,18 @@ export class WaitModal extends Component {
style={{ style={{
flexDirection: "column", flexDirection: "column",
justifyContent: "center", justifyContent: "center",
backgroundColor: "#FFFFFF", backgroundColor: "transparent",
}}> }}>
<ActivityIndicator size="large" color="#0000FF" /> <ActivityIndicator size="large" color="#0000FF" />
<Text style={{ marginTop: 5, fontSize: 18 }}>{message}</Text> <Text
style={{
marginTop: 15,
fontSize: 18,
alignSelf: "center",
color: "#FFFFFF",
}}>
{message}
</Text>
</View> </View>
</Modal> </Modal>
) )

View File

@@ -28,6 +28,7 @@ import { ifIphoneX, isIphoneX } from "react-native-iphone-x-helper"
import KeyboardSpacer from "react-native-keyboard-spacer" import KeyboardSpacer from "react-native-keyboard-spacer"
import { api } from "../API" import { api } from "../API"
import "url-search-params-polyfill" import "url-search-params-polyfill"
import { config } from "../config"
import { workItemTypeEnum, formatLatLng, parseLatLng } from "../util" import { workItemTypeEnum, formatLatLng, parseLatLng } from "../util"
const styles = StyleSheet.create({ const styles = StyleSheet.create({
@@ -58,6 +59,7 @@ export class WorkItem extends React.Component {
location: { location: {
isValid: (r, v) => v !== "", isValid: (r, v) => v !== "",
isReadOnly: true, isReadOnly: true,
alwaysGet: true,
}, },
address: { address: {
isValid: true, isValid: true,
@@ -74,15 +76,18 @@ export class WorkItem extends React.Component {
constructor(props) { constructor(props) {
super(props) super(props)
this.state = {
binder: new FormBinder({}, WorkItem.bindings), region = {
messageModal: null,
region: {
latitude: 43.653908, latitude: 43.653908,
longitude: -79.384293, longitude: -79.384293,
latitudeDelta: 0.0922, latitudeDelta: 0.0922,
longitudeDelta: 0.0421, longitudeDelta: 0.0421,
}, }
this.state = {
binder: new FormBinder({}, WorkItem.bindings),
messageModal: null,
region,
} }
const { search } = this.props.location const { search } = this.props.location
@@ -96,15 +101,17 @@ export class WorkItem extends React.Component {
.then((workItem) => { .then((workItem) => {
if (workItem) { if (workItem) {
const [lng, lat] = workItem.location.coordinates const [lng, lat] = workItem.location.coordinates
workItem.location = formatLatLng(lat, lng) const region = {
this.setState({
binder: new FormBinder(workItem, WorkItem.bindings),
region: {
latitude: lat, latitude: lat,
longitude: lng, longitude: lng,
latitudeDelta: 0.01, latitudeDelta: 0.01,
longitudeDelta: 0.01, longitudeDelta: 0.01,
}, }
workItem.location = formatLatLng(lat, lng)
this.setState({
binder: new FormBinder(workItem, WorkItem.bindings),
region,
}) })
} }
}) })
@@ -198,6 +205,7 @@ export class WorkItem extends React.Component {
if (this.geoCodeTimer) { if (this.geoCodeTimer) {
clearTimeout(this.geoCodeTimer) clearTimeout(this.geoCodeTimer)
this.geoCodeTimer = null
} }
this.geoCodeTimer = setTimeout( this.geoCodeTimer = setTimeout(
@@ -209,12 +217,16 @@ export class WorkItem extends React.Component {
@autobind @autobind
handleStartAddressLookup(latLng) { handleStartAddressLookup(latLng) {
api api
.addressLookup(latLng) .getAddress(latLng)
.then((address) => { .then((address) => {
this.setState({ address }) if (this.addressInput) {
this.addressInput.handleChangeText(address)
}
}) })
.catch(() => { .catch(() => {
this.setState({ address: "" }) if (this.addressInput) {
this.addressInput.handleChangeText("")
}
}) })
} }
@@ -252,6 +264,7 @@ export class WorkItem extends React.Component {
<View style={styles.panel}> <View style={styles.panel}>
<View style={{ flexDirection: "column", justifyContent: "center" }}> <View style={{ flexDirection: "column", justifyContent: "center" }}>
<MapView <MapView
ref={(ref) => (this.mapView = ref)}
style={{ style={{
flexDirection: "column", flexDirection: "column",
justifyContent: "center", justifyContent: "center",
@@ -262,7 +275,7 @@ export class WorkItem extends React.Component {
showsBuildings={false} showsBuildings={false}
showsTraffic={false} showsTraffic={false}
showsIndoors={false} showsIndoors={false}
zoomControlEnabled zoomControlEnabled={false}
rotateEnabled={false} rotateEnabled={false}
region={region} region={region}
onRegionChange={this.handleRegionChange} onRegionChange={this.handleRegionChange}

View File

@@ -20,7 +20,9 @@ import {
parseLatLng, parseLatLng,
pad, pad,
geoDistance, geoDistance,
dotify,
} from "../util" } from "../util"
import "url-search-params-polyfill"
const styles = StyleSheet.create({ const styles = StyleSheet.create({
container: { container: {
@@ -179,7 +181,7 @@ export class WorkItemList extends React.Component {
{workItemTypeText[item.workItemType]} {workItemTypeText[item.workItemType]}
</Text> </Text>
<Text style={{ fontSize: 14, color: "gray" }}> <Text style={{ fontSize: 14, color: "gray" }}>
{`${item.address || "..."} | ${ {`${dotify(item.address) || "..."} | ${
this.position this.position
? geoDistance( ? geoDistance(
this.position.latitude, this.position.latitude,

View File

@@ -4,11 +4,9 @@ import { Platform } from "react-native"
export const config = { export const config = {
localIPAddr: "192.168.1.175", localIPAddr: "192.168.1.175",
viroAPIKey: "06F37B6A-74DA-4A83-965A-7DE2209A5C46", viroAPIKey: "06F37B6A-74DA-4A83-965A-7DE2209A5C46",
googleAPIKey: googleGeocodeAPIKey: "AIzaSyCs4JVT6gysnY5dAJ7KjVJYeykLv_xz1GI",
Platform.os === "ios"
? "AIzaSyDN4E_vzO4cKjKHkMg_49hX1GBnU34kx4U"
: "AIzaSyAC7r1GjMFL1atZdbEcFSdCaXDrPnISqTc",
googleGeocodeURL: "https://maps.googleapis.com/maps/api/geocode/json", googleGeocodeURL: "https://maps.googleapis.com/maps/api/geocode/json",
refererURL: "https://dar.kss.us.com",
defaultUser: "john@lyon-smith.org", defaultUser: "john@lyon-smith.org",
//defaultUser: "", //defaultUser: "",
//minGPSAccuracy: 20, //minGPSAccuracy: 20,

View File

@@ -54,7 +54,12 @@ export class BoundInput extends React.Component {
return ( return (
<View style={{ width: "100%" }}> <View style={{ width: "100%" }}>
<Text style={{ color: "black", fontSize: 14, marginBottom: 5 }}> <Text
style={{
color: "black",
fontSize: 14,
marginBottom: 5,
}}>
{label} {label}
</Text> </Text>
<TextInput <TextInput
@@ -68,6 +73,7 @@ export class BoundInput extends React.Component {
paddingTop: 7, paddingTop: 7,
paddingBottom: Platform.OS === "ios" ? 7 : 0, paddingBottom: Platform.OS === "ios" ? 7 : 0,
textAlignVertical: "top", textAlignVertical: "top",
marginBottom: 5,
}} }}
multiline={lines > 1} multiline={lines > 1}
numberOfLines={lines} numberOfLines={lines}

View File

@@ -56,6 +56,14 @@ export const pad = (num, size) => {
return s return s
} }
export const dotify = (s) => {
if (s.length < 30) {
return s
} else {
return s.substring(0, 26) + "..."
}
}
export const regionContainingPoints = (points, inset) => { export const regionContainingPoints = (points, inset) => {
let minX, let minX,
maxX, maxX,

View File

@@ -143,75 +143,6 @@ export class Teams extends Component {
}) })
} }
@autobind
handleResendEmail() {
this.setState({
waitModal: { message: "Resending Email..." },
})
api
.sendConfirmEmail({ existingEmail: this.state.selectedTeam.email })
.then(() => {
this.setState({
waitModal: null,
messageModal: {
icon: "thumb",
message: `An email has been sent to '${
this.state.selectedTeam.email
}' with further instructions.`,
},
})
})
.catch((error) => {
this.setState({
error: true,
waitModal: null,
messageModal: {
icon: "hand",
message: "Unable to request email change.",
detail: error.message,
},
})
})
}
@autobind
handleChangeEmailDismiss(newEmail) {
this.setState({ changeEmailModal: null })
if (!newEmail) {
return
}
this.setState({
waitModal: { message: "Requesting Email Change..." },
})
if (this.state.selectedTeam) {
api
.sendConfirmEmail({
existingEmail: this.state.selectedTeam.email,
newEmail,
})
.then(() => {
this.setState({
waitModal: null,
messageModal: {
icon: "hand",
message: `An email has been sent to '${newEmail}' to confirm this email.`,
},
})
})
.catch((error) => {
this.setState({
error: true,
waitModal: null,
messageModal: {
icon: "hand",
message: "Unable to request email change.",
detail: error.message,
},
})
})
}
}
@autobind @autobind
handleRemove() { handleRemove() {
this.setState({ this.setState({