Skip to content

Commit

Permalink
fix: add loading indicator and disable discard button when sound is b…
Browse files Browse the repository at this point in the history
…eing deleted (#2283)
  • Loading branch information
angielt authored Oct 18, 2024
1 parent 9ba36de commit 19f7a83
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/components/MediaViewer/MediaViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import MediaViewerHeader from "./MediaViewerHeader";
type Props = {
autoPlaySound?: boolean, // automatically start playing a sound when it is visible
editable?: boolean,
deleting?: boolean,
// Optional component to use as the header
header?: Function,
onClose?: Function,
Expand All @@ -44,6 +45,7 @@ type Props = {
const MediaViewer = ( {
autoPlaySound,
editable,
deleting,
header,
onClose = ( ) => undefined,
onDeletePhoto,
Expand Down Expand Up @@ -135,9 +137,10 @@ const MediaViewer = ( {
isLargeScreen={isLargeScreen}
selectedMediaIndex={selectedMediaIndex}
/>
{mediaToDelete && (
{( mediaToDelete || deleting ) && (
<WarningSheet
onPressClose={( ) => setMediaToDelete( null )}
loading={deleting}
confirm={confirmDelete}
headerText={t( "DISCARD-MEDIA--question" )}
buttonText={t( "DISCARD" )}
Expand Down
3 changes: 3 additions & 0 deletions src/components/MediaViewer/MediaViewerModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import React from "react";
type Props = {
autoPlaySound?: boolean, // automatically start playing a sound when it is visible
editable?: boolean,
deleting?: boolean,
// Optional component to use as the header
header?: Function,
onClose?: Function,
Expand All @@ -30,6 +31,7 @@ type Props = {
const MediaViewerModal = ( {
autoPlaySound,
editable,
deleting,
header,
onClose = ( ) => undefined,
onDeletePhoto,
Expand All @@ -48,6 +50,7 @@ const MediaViewerModal = ( {
<MediaViewer
autoPlaySound={autoPlaySound}
editable={editable}
deleting={deleting}
header={header}
onClose={onClose}
onDeletePhoto={onDeletePhoto}
Expand Down
7 changes: 6 additions & 1 deletion src/components/ObsEdit/EvidenceList.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const EvidenceList = ( {
const realm = useRealm( );
const { t } = useTranslation( );
const [selectedMediaUri, setSelectedMediaUri]: [string | null, Function] = useState( null );
const [deleting, setDeleting] = useState( false );
const imageClass = "h-16 w-16 justify-center mx-1.5 rounded-lg";

const observationPhotos = useMemo(
Expand Down Expand Up @@ -165,6 +166,7 @@ const EvidenceList = ( {
} else {
setSelectedMediaUri( mediaUris[mediaUris.length - 1] );
}
setDeleting( false );
}, [mediaUris, setSelectedMediaUri] );

const deleteObservationSoundMutation = useAuthenticatedMutation(
Expand All @@ -188,12 +190,14 @@ const EvidenceList = ( {
);
afterMediaDeleted( );
}
setDeleting( true );
// If sound was synced, delete the remote copy immediately and then remove
// the local
if ( obsSound?.id ) {
deleteObservationSoundMutation.mutate( { uuid: obsSound.uuid }, {
onSuccess: removeLocalSound,
onError: deleteRemoteObservationSoundError => {
setDeleting( false );
logger.error(
"[EvidenceList.js] failed to delete remote observation sound: ",
deleteRemoteObservationSoundError
Expand Down Expand Up @@ -243,11 +247,12 @@ const EvidenceList = ( {
{evidenceList}
<MediaViewerModal
editable
deleting={deleting}
onClose={( ) => setSelectedMediaUri( null )}
onDeletePhoto={onDeletePhoto}
onDeleteSound={onDeleteSound}
photos={observationPhotos.map( obsPhoto => obsPhoto.photo )}
showModal={!!selectedMediaUri}
showModal={!!selectedMediaUri || deleting}
sounds={observationSounds.map( obsSound => obsSound.sound )}
uri={selectedMediaUri}
/>
Expand Down
2 changes: 1 addition & 1 deletion src/components/SharedComponents/Buttons/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ const Button = ( {
{loading && (
<ActivityIndicator
size={18}
className="mr-2"
className="mr-3 absolute right-0"
color={!isNeutral
? activityIndicatorColor( {
isPrimary, isWarning, isFocus
Expand Down
4 changes: 4 additions & 0 deletions src/components/SharedComponents/Sheets/WarningSheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ interface Props {
headerText: string;
hidden?: boolean;
insideModal?: boolean;
loading: boolean;
onPressClose: () => void;
secondButtonText?: string;
testID?: string;
Expand All @@ -28,6 +29,7 @@ const WarningSheet = ( {
headerText,
hidden,
insideModal,
loading,
onPressClose,
secondButtonText,
testID,
Expand All @@ -50,6 +52,8 @@ const WarningSheet = ( {
) }
<Button
onPress={confirm}
loading={loading}
disabled={loading}
text={buttonText}
level={buttonType || "warning"}
className="grow ml-3"
Expand Down

0 comments on commit 19f7a83

Please sign in to comment.