From d6cac249c69f5e3d71c38ef9590be3d8f093b060 Mon Sep 17 00:00:00 2001 From: simoleo89 Date: Sat, 13 Jun 2026 16:42:29 +0200 Subject: [PATCH] fix(camera): reset selected picture index after deleting a photo MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The 'delete' action spliced the selected picture out of the roll but never moved selectedPictureIndex, so it kept pointing at the slot the deleted photo vacated — now a different picture (or past the end), making the preview show the wrong photo or vanish while the UI still thinks one is selected. Move the selection back one after delete. --- src/components/camera/CameraWidgetView.tsx | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/components/camera/CameraWidgetView.tsx b/src/components/camera/CameraWidgetView.tsx index d4221e8..5df8c5e 100644 --- a/src/components/camera/CameraWidgetView.tsx +++ b/src/components/camera/CameraWidgetView.tsx @@ -14,7 +14,7 @@ export const CameraWidgetView: FC<{}> = props => { const [ mode, setMode ] = useState(MODE_NONE); const [ base64Url, setSavedPictureUrl ] = useState(null); - const { availableEffects = [], selectedPictureIndex = -1, cameraRoll = [], setCameraRoll = null, myLevel = 0, price = { credits: 0, duckets: 0, publishDucketPrice: 0 } } = useCamera(); + const { availableEffects = [], selectedPictureIndex = -1, setSelectedPictureIndex = null, cameraRoll = [], setCameraRoll = null, myLevel = 0, price = { credits: 0, duckets: 0, publishDucketPrice: 0 } } = useCamera(); const processAction = (type: string) => @@ -28,14 +28,11 @@ export const CameraWidgetView: FC<{}> = props => setMode(MODE_EDITOR); return; case 'delete': - setCameraRoll(prevValue => - { - const clone = [ ...prevValue ]; - - clone.splice(selectedPictureIndex, 1); - - return clone; - }); + setCameraRoll(prevValue => prevValue.filter((_, index) => (index !== selectedPictureIndex))); + // Without this the index keeps pointing at the slot the deleted + // photo vacated (now a different picture, or past the end) — move + // the selection back one so the preview stays in sync. + if(setSelectedPictureIndex) setSelectedPictureIndex(prev => (prev > 0 ? (prev - 1) : 0)); return; case 'editor_cancel': setMode(MODE_CAPTURE);