From cffa0734b8ea3f97e55b3dd5393ff054e6389609 Mon Sep 17 00:00:00 2001 From: John Lyon-Smith Date: Mon, 4 Jun 2018 16:29:58 -0700 Subject: [PATCH] Added work item details to activity --- mobile/src/Activity/Activity.js | 47 ++++++++++++++------------ mobile/src/App.js | 5 +-- mobile/src/WorkItem/WorkItem.js | 13 +++---- mobile/src/ui/BoundInput.js | 3 +- mobile/src/ui/BoundOptionStrip.js | 3 +- mobile/src/ui/FormStaticInput.js | 1 + mobile/src/ui/FormStaticOptionStrip.js | 33 ++++++++++++++++++ mobile/src/ui/OptionStrip.js | 13 +++++-- mobile/src/ui/index.js | 1 + 9 files changed, 81 insertions(+), 38 deletions(-) create mode 100644 mobile/src/ui/FormStaticOptionStrip.js diff --git a/mobile/src/Activity/Activity.js b/mobile/src/Activity/Activity.js index 5d9a706..172698c 100644 --- a/mobile/src/Activity/Activity.js +++ b/mobile/src/Activity/Activity.js @@ -27,10 +27,11 @@ import { reactAutoBind } from "auto-bind2" import KeyboardSpacer from "react-native-keyboard-spacer" import { isIphoneX } from "react-native-iphone-x-helper" import { api } from "../API" -import { formatLatLng } from "../util" +import { formatLatLng, workItemTypeEnum } from "../util" import moment from "moment" import "url-search-params-polyfill" import { config } from "../config" +import { FormStaticOptionStrip } from "../ui/FormStaticOptionStrip" const styles = StyleSheet.create({ container: { @@ -124,6 +125,8 @@ export class Activity extends React.Component { ), location: formatLatLng(lat, lng), dateTime: moment().format(), + details: workItem.details, + workItemType: workItem.workItemType, }) this.region = { @@ -288,6 +291,8 @@ export class Activity extends React.Component { waitModal, dateTime, location, + details, + workItemType, uploadPercent, } = this.state @@ -301,14 +306,6 @@ export class Activity extends React.Component { rightButton={{ icon: "done", onPress: this.handleDonePress }} /> - - - - - + + + - + + - - - {isIphoneX ? : null} - + {/* */} - + {/* */} + diff --git a/mobile/src/WorkItem/WorkItem.js b/mobile/src/WorkItem/WorkItem.js index 8f1be6d..3e607b0 100644 --- a/mobile/src/WorkItem/WorkItem.js +++ b/mobile/src/WorkItem/WorkItem.js @@ -100,6 +100,7 @@ export class WorkItem extends React.Component { messageModal: null, waitModal: null, progressModal: null, + allowLocationUpdates: false, } this.region = null this.isMapReady = false @@ -151,6 +152,8 @@ export class WorkItem extends React.Component { }, }) }) + } else { + this.setState({ allowLocationUpdates: true }) } } @@ -221,7 +224,7 @@ export class WorkItem extends React.Component { } handleRegionChange(region) { - if (this.state.binder._id || !this.isMapReady) { + if (!this.state.allowLocationUpdates || !this.isMapReady) { // On iOS we get this after setting the initial region, before the map declared as ready! // Also, if we are only viewing the work item, then don't allow region changes return @@ -349,8 +352,6 @@ export class WorkItem extends React.Component { options={workItemTypeEnum} message="Select a work item type" /> - - - - (this.mapView = ref)} @@ -406,8 +405,6 @@ export class WorkItem extends React.Component { name="address" label="Address:" /> - - : null} - {!this.state.binder._id && ( + {!this.state.allowLocationUpdates && ( )} - {message} + {valid ? " " : message} ) diff --git a/mobile/src/ui/BoundOptionStrip.js b/mobile/src/ui/BoundOptionStrip.js index db4205e..b649fad 100644 --- a/mobile/src/ui/BoundOptionStrip.js +++ b/mobile/src/ui/BoundOptionStrip.js @@ -55,10 +55,9 @@ export class BoundOptionStrip extends React.Component { - {message} + {valid ? " " : message} ) diff --git a/mobile/src/ui/FormStaticInput.js b/mobile/src/ui/FormStaticInput.js index 7666510..680a221 100644 --- a/mobile/src/ui/FormStaticInput.js +++ b/mobile/src/ui/FormStaticInput.js @@ -39,6 +39,7 @@ export class FormStaticInput extends React.Component { underlineColorAndroid="white" value={value} /> +   ) } diff --git a/mobile/src/ui/FormStaticOptionStrip.js b/mobile/src/ui/FormStaticOptionStrip.js new file mode 100644 index 0000000..81163f7 --- /dev/null +++ b/mobile/src/ui/FormStaticOptionStrip.js @@ -0,0 +1,33 @@ +import React from "react" +import PropTypes from "prop-types" +import { Text, View, Platform } from "react-native" +import { OptionStrip } from "." + +export class FormStaticOptionStrip extends React.Component { + static propTypes = { + label: PropTypes.string, + options: PropTypes.arrayOf( + PropTypes.shape({ value: PropTypes.string, text: PropTypes.string }) + ).isRequired, + value: PropTypes.string, + } + + render() { + const { label, value, options } = this.props + + return ( + + + {label} + + +   + + ) + } +} diff --git a/mobile/src/ui/OptionStrip.js b/mobile/src/ui/OptionStrip.js index 724faac..bd4f8d7 100644 --- a/mobile/src/ui/OptionStrip.js +++ b/mobile/src/ui/OptionStrip.js @@ -9,6 +9,7 @@ export class OptionStrip extends Component { PropTypes.shape({ value: PropTypes.string, text: PropTypes.string }) ).isRequired, value: PropTypes.string, + readOnly: PropTypes.bool, onValueChanged: PropTypes.func, } @@ -41,14 +42,15 @@ export class OptionStrip extends Component { handlePress(option) { const { onValueChanged } = this.props - this.setState({ selectedOption: option }) if (onValueChanged) { onValueChanged(option.value) + } else if (!this.props.readOnly) { + this.setState({ selectedOption: option }) } } render() { - const { style, options, value } = this.props + const { style, options, value, readOnly } = this.props const { selectedOption } = this.state // TODO: Handle visible, disabled & read-only @@ -58,6 +60,7 @@ export class OptionStrip extends Component { {options.map((option, index) => (