From 19f7a83750b6221faa39e78c3bc97cddd53de293 Mon Sep 17 00:00:00 2001 From: Angie Date: Fri, 18 Oct 2024 11:21:51 -0700 Subject: [PATCH] fix: add loading indicator and disable discard button when sound is being deleted (#2283) --- src/components/MediaViewer/MediaViewer.js | 5 ++++- src/components/MediaViewer/MediaViewerModal.js | 3 +++ src/components/ObsEdit/EvidenceList.js | 7 ++++++- src/components/SharedComponents/Buttons/Button.tsx | 2 +- src/components/SharedComponents/Sheets/WarningSheet.tsx | 4 ++++ 5 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/components/MediaViewer/MediaViewer.js b/src/components/MediaViewer/MediaViewer.js index 4a53bfc8bf..fe36bcff17 100644 --- a/src/components/MediaViewer/MediaViewer.js +++ b/src/components/MediaViewer/MediaViewer.js @@ -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, @@ -44,6 +45,7 @@ type Props = { const MediaViewer = ( { autoPlaySound, editable, + deleting, header, onClose = ( ) => undefined, onDeletePhoto, @@ -135,9 +137,10 @@ const MediaViewer = ( { isLargeScreen={isLargeScreen} selectedMediaIndex={selectedMediaIndex} /> - {mediaToDelete && ( + {( mediaToDelete || deleting ) && ( setMediaToDelete( null )} + loading={deleting} confirm={confirmDelete} headerText={t( "DISCARD-MEDIA--question" )} buttonText={t( "DISCARD" )} diff --git a/src/components/MediaViewer/MediaViewerModal.js b/src/components/MediaViewer/MediaViewerModal.js index 80fb3a042a..42af2d57d7 100644 --- a/src/components/MediaViewer/MediaViewerModal.js +++ b/src/components/MediaViewer/MediaViewerModal.js @@ -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, @@ -30,6 +31,7 @@ type Props = { const MediaViewerModal = ( { autoPlaySound, editable, + deleting, header, onClose = ( ) => undefined, onDeletePhoto, @@ -48,6 +50,7 @@ const MediaViewerModal = ( { { + setDeleting( false ); logger.error( "[EvidenceList.js] failed to delete remote observation sound: ", deleteRemoteObservationSoundError @@ -243,11 +247,12 @@ const EvidenceList = ( { {evidenceList} 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} /> diff --git a/src/components/SharedComponents/Buttons/Button.tsx b/src/components/SharedComponents/Buttons/Button.tsx index 14124e603d..f66b0ef5ef 100644 --- a/src/components/SharedComponents/Buttons/Button.tsx +++ b/src/components/SharedComponents/Buttons/Button.tsx @@ -201,7 +201,7 @@ const Button = ( { {loading && ( void; secondButtonText?: string; testID?: string; @@ -28,6 +29,7 @@ const WarningSheet = ( { headerText, hidden, insideModal, + loading, onPressClose, secondButtonText, testID, @@ -50,6 +52,8 @@ const WarningSheet = ( { ) }