Deal with initially having no work items

This commit is contained in:
John Lyon-Smith
2018-04-26 15:48:56 -07:00
parent 0a5677b59b
commit 5e5daa2e78
7 changed files with 1504 additions and 1464 deletions

View File

@@ -92,36 +92,66 @@ export class Activity extends React.Component {
}
const { search } = this.props.location
const params = search ? new URLSearchParams(search) : { get: () => null }
const id = params.get("id")
const workItemId = params.get("workItemId")
if (search) {
const id = new URLSearchParams(search).get("id")
const getWorkItem = (id) => {
api
.getWorkItem(id)
.then((workitem) => {
if (workItem) {
const [lng, lat] = workItem.location.coordinates
if (id) {
api
.getActivity(id)
.then((activity) => {
if (activity) {
this.setState({
binder: new FormBinder(activity, Activity.bindings),
// region: {
// latitude: lat,
// longitude: lng,
// latitudeDelta: 0.01,
// longitudeDelta: 0.01,
// },
})
}
})
.catch((err) => {
this.setState({
messageModal: {
icon: "hand",
message: "Unable to get activity details",
detail: err.message,
back: true,
region: {
latitude: lat,
longitude: lng,
latitudeDelta: 0.01,
longitudeDelta: 0.01,
},
})
}
})
.catch((err) => {
this.setState({
messageModal: {
icon: "hand",
message: "Unable to get work item details",
detail: err.message,
back: true,
},
})
})
}
if (id) {
api
.getActivity(id)
.then((activity) => {
if (activity) {
this.setState({
binder: new FormBinder(activity, Activity.bindings),
})
getWorkItem(activity.workItemId)
}
})
.catch((err) => {
this.setState({
messageModal: {
icon: "hand",
message: "Unable to get activity details",
detail: err.message,
back: true,
},
})
})
} else {
if (workItemId) {
getWorkItem(workItemId)
} else {
this.handleBackPress()
}
}
}