Skip to content

Commit

Permalink
feat: update header with new UI (#312)
Browse files Browse the repository at this point in the history
* chore: update header to include modal

* chore: translations

* chore: missing dependencies

* chore: update save icon

* chore: delete old save icon

* chore: update use of save icon

* chore: destructure foruseEffect dependecy
  • Loading branch information
ErikSin authored May 1, 2024
1 parent 9750502 commit 1dd8130
Show file tree
Hide file tree
Showing 9 changed files with 127 additions and 132 deletions.
16 changes: 11 additions & 5 deletions messages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,23 @@
"description": "Button on dialog to keep editing (cancelling close action)",
"message": "Continue editing"
},
"AppContainer.EditHeader.discardChangesContent": {
"description": "Button on dialog to cancel observation edits",
"AppContainer.EditHeader.discardChangesButton": {
"description": "Title of dialog that shows when cancelling observation edits",
"message": "Discard changes"
},
"AppContainer.EditHeader.discardChangesDescription": {
"message": "Your changes will not be saved. This cannot be undone."
},
"AppContainer.EditHeader.discardChangesTitle": {
"description": "Title of dialog that shows when cancelling observation edits",
"message": "Discard changes?"
},
"AppContainer.EditHeader.discardContent": {
"description": "Button on dialog to cancel a new observation",
"message": "Discard without saving"
"AppContainer.EditHeader.discardObservationButton": {
"description": "Title of dialog that shows when cancelling observation edits",
"message": "Discard Observation"
},
"AppContainer.EditHeader.discardObservationDescription": {
"message": "Your Observation will not be saved. This cannot be undone."
},
"AppContainer.EditHeader.discardTitle": {
"description": "Title of dialog that shows when cancelling a new observation",
Expand Down
4 changes: 4 additions & 0 deletions src/frontend/images/CheckMark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions src/frontend/screens/ObservationEdit/SaveButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import debug from 'debug';
import {defineMessages, useIntl} from 'react-intl';

import {IconButton} from '../../sharedComponents/IconButton';
import {SaveIcon} from '../../sharedComponents/icons/SaveIcon';
import {useNavigationFromRoot} from '../../hooks/useNavigationWithTypes';
import {usePersistedDraftObservation} from '../../hooks/persistedState/usePersistedDraftObservation';
import {useCreateObservation} from '../../hooks/server/observations';
Expand All @@ -14,6 +13,7 @@ import {useCreateBlobMutation} from '../../hooks/server/media';
import {DraftPhoto, Photo} from '../../contexts/PhotoPromiseContext/types';
import {useDraftObservation} from '../../hooks/useDraftObservation';
import {useCurrentTrackStore} from '../../hooks/tracks/useCurrentTrackStore';
import SaveCheck from '../../images/CheckMark.svg';

const m = defineMessages({
noGpsTitle: {
Expand Down Expand Up @@ -242,7 +242,7 @@ export const SaveButton = ({
</View>
) : (
<IconButton onPress={handleSavePress} testID="saveButton">
<SaveIcon inprogress={false} />
<SaveCheck />
</IconButton>
);
};
Expand Down
6 changes: 3 additions & 3 deletions src/frontend/screens/ObservationEdit/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ export const ObservationEdit: NativeNavigationComponent<'ObservationEdit'> & {
navigation.navigate('AddPhoto');
}, [navigation]);

const handleDetailsPress = React.useCallback(() => {
navigation.navigate('ObservationDetails', {question: 1});
}, [navigation]);
// const handleDetailsPress = React.useCallback(() => {
// navigation.navigate('ObservationDetails', {question: 1});
// }, [navigation]);

const bottomSheetItems = [
{
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/screens/PresetChooser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export const PresetChooser: NativeNavigationComponent<'PresetChooser'> = ({
<CustomHeaderLeftClose headerBackButtonProps={props} />
),
});
}, [prevRouteNameInStack, CustomHeaderLeft, CustomHeaderLeftClose]);
}, [prevRouteNameInStack, navigation]);

const presetsList = !presets
? null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
import {BLACK} from '../../../../lib/styles';
import {HookFormTextInput} from '../../../../sharedComponents/HookFormTextInput';
import {IconButton} from '../../../../sharedComponents/IconButton';
import {SaveIcon} from '../../../../sharedComponents/icons';
import SaveIcon from '../../../../images/CheckMark.svg';
import {useBottomSheetModal} from '../../../../sharedComponents/BottomSheetModal';
import {ErrorModal} from '../../../../sharedComponents/ErrorModal';
import {FieldRow} from './FieldRow';
Expand Down Expand Up @@ -72,14 +72,16 @@ export const EditScreen = ({
deviceName: string;
}>({defaultValues: {deviceName}});

const editDeviceInfoMutation = useEditDeviceInfo();
const {isPending, mutate} = useEditDeviceInfo();

const {isDirty: nameHasChanges} = control.getFieldState(
'deviceName',
formState,
);

const errorModal = useBottomSheetModal({openOnMount: false});
const {openSheet, sheetRef, closeSheet, isOpen} = useBottomSheetModal({
openOnMount: false,
});

React.useEffect(
function showDiscardChangesAlert() {
Expand Down Expand Up @@ -117,41 +119,30 @@ export const EditScreen = ({
return (
<IconButton
onPress={
editDeviceInfoMutation.isPending
isPending
? () => {}
: handleSubmit(async value => {
if (!nameHasChanges) {
navigation.navigate('DeviceNameDisplay');
return;
}

editDeviceInfoMutation.mutate(value.deviceName, {
mutate(value.deviceName, {
onSuccess: () =>
navigation.navigate('DeviceNameDisplay'),
onError: () => {
errorModal.openSheet();
openSheet();
},
});
})
}>
{editDeviceInfoMutation.isPending ? (
<UIActivityIndicator size={30} />
) : (
<SaveIcon />
)}
{isPending ? <UIActivityIndicator size={30} /> : <SaveIcon />}
</IconButton>
);
},
});
},
[
handleSubmit,
navigation,
editDeviceInfoMutation.mutate,
editDeviceInfoMutation.isPending,
nameHasChanges,
errorModal.openSheet,
],
[handleSubmit, navigation, isPending, mutate, nameHasChanges, openSheet],
);

return (
Expand All @@ -168,15 +159,11 @@ export const EditScreen = ({
style={{flex: 1, color: BLACK, fontSize: 16}}
showCharacterCount
autoFocus
editable={!editDeviceInfoMutation.isPending}
editable={isPending}
/>
</FieldRow>
</ScrollView>
<ErrorModal
sheetRef={errorModal.sheetRef}
closeSheet={errorModal.closeSheet}
isOpen={errorModal.isOpen}
/>
<ErrorModal sheetRef={sheetRef} closeSheet={closeSheet} isOpen={isOpen} />
</>
);
};
Expand Down
Loading

0 comments on commit 1dd8130

Please sign in to comment.