Skip to content

Commit 2cafedd

Browse files
authored
Fix bugs saving drafts and storing photos (#1249)
Signed-off-by: Steve Cassidy <steve.cassidy@mq.edu.au> # Fix bugs saving drafts and storing photos ## JIRA Ticket None ## Description The app was not updating saved drafts as it should. On IOS and Android, it would not save a photo after it was captured. ## Proposed Changes Very obscure bugs. - draft saving is triggered by a call in form.tsx that had been placed after a conditional for inline forms, so wasn't being called for inline forms - photo saving was being interrupted by too frequent re-renders of the RecordForm component that lost data because it happened between GetPhoto returning and the data being stored. ## How to Test Check Android and Apple builds, see how you are able to take photos, notice how the draft is updated if you quit out of the form without saving. ## Additional Information OMG! OMG! OMG! ## Checklist - [x] I have confirmed all commits have been signed. - [x] I have added JSDoc style comments to any new functions or classes. - [x] Relevant documentation such as READMEs, guides, and class comments are updated.
2 parents 7032f4d + 73110f5 commit 2cafedd

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

app/src/constants/privateRouter.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export const PrivateRoute = (props: PrivateRouteProps): React.ReactElement => {
2020
// TODO use a context provider for listings instead of getting first entry
2121
const anyToken = useGetAnyToken();
2222
// The token is being retrieved
23-
if (anyToken.isFetching) {
23+
if (anyToken.isLoading) {
2424
return <LoadingApp />;
2525
}
2626

app/src/gui/components/record/form.tsx

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,6 @@ class RecordForm extends React.Component<
406406
} catch (error) {
407407
// here if there was no existing record with this id above
408408
// so we ca't update revision_id so it is still undefined
409-
if (DEBUG_APP) console.debug('new record', this.props.record_id);
410409
}
411410
}
412411
// work out the record type or default it
@@ -842,7 +841,7 @@ class RecordForm extends React.Component<
842841
// to never get here or provide a good reason if we do
843842
.catch(err => {
844843
const message = 'Could not save record';
845-
console.error('Could not save record:', err);
844+
logError(`Could not save record: ${JSON.stringify(err)}`);
846845
(this.context as any).dispatch({
847846
type: ActionType.ADD_ALERT,
848847
payload: {
@@ -1185,6 +1184,16 @@ class RecordForm extends React.Component<
11851184
)
11861185
);
11871186

1187+
// This fragment of code is critical to saving drafts, it needs
1188+
// to be called here on every render and as a side-effect will
1189+
// save the current draft.
1190+
this.draftState &&
1191+
this.draftState.renderHook(
1192+
formProps.values,
1193+
this.state.annotation,
1194+
this.state.relationship ?? {}
1195+
);
1196+
11881197
if (layout === 'inline')
11891198
return (
11901199
<div>
@@ -1303,13 +1312,6 @@ class RecordForm extends React.Component<
13031312
</div>
13041313
);
13051314

1306-
this.draftState &&
1307-
this.draftState.renderHook(
1308-
formProps.values,
1309-
this.state.annotation,
1310-
this.state.relationship ?? {}
1311-
);
1312-
13131315
const fieldNames = getFieldsMatchingCondition(
13141316
this.props.ui_specification,
13151317
formProps.values,

0 commit comments

Comments
 (0)