fix(camera): reset selected picture index after deleting a photo

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.
This commit is contained in:
simoleo89
2026-06-13 16:42:29 +02:00
parent 93baedf206
commit d6cac249c6
+6 -9
View File
@@ -14,7 +14,7 @@ export const CameraWidgetView: FC<{}> = props =>
{ {
const [ mode, setMode ] = useState<number>(MODE_NONE); const [ mode, setMode ] = useState<number>(MODE_NONE);
const [ base64Url, setSavedPictureUrl ] = useState<string>(null); const [ base64Url, setSavedPictureUrl ] = useState<string>(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) => const processAction = (type: string) =>
@@ -28,14 +28,11 @@ export const CameraWidgetView: FC<{}> = props =>
setMode(MODE_EDITOR); setMode(MODE_EDITOR);
return; return;
case 'delete': case 'delete':
setCameraRoll(prevValue => setCameraRoll(prevValue => prevValue.filter((_, index) => (index !== selectedPictureIndex)));
{ // Without this the index keeps pointing at the slot the deleted
const clone = [ ...prevValue ]; // photo vacated (now a different picture, or past the end) — move
// the selection back one so the preview stays in sync.
clone.splice(selectedPictureIndex, 1); if(setSelectedPictureIndex) setSelectedPictureIndex(prev => (prev > 0 ? (prev - 1) : 0));
return clone;
});
return; return;
case 'editor_cancel': case 'editor_cancel':
setMode(MODE_CAPTURE); setMode(MODE_CAPTURE);