mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-04-05 14:47:40 +03:00
Fix fit-to-screen drag reset: use primitive deps in fitLayoutOverride effect
fitGridParams is recreated on every useMemo run, causing the useEffect to fire and clear fitLayoutOverride after each swap. Switch deps to fitGridParams?.gridUnitsPerCam and fitGridParams?.colsPerRow (primitives) so the reset only triggers when the grid geometry actually changes. Also remove all debug console.log added during investigation. https://claude.ai/code/session_01Cu7YDRKZrYX3sBs6g9w2dy
This commit is contained in:
parent
43d196c57c
commit
8216394c59
@ -471,7 +471,12 @@ export default function DraggableGridLayout({
|
||||
|
||||
useEffect(() => {
|
||||
setFitLayoutOverride(undefined);
|
||||
}, [fitGridParams, cameras, includeBirdseye]);
|
||||
}, [
|
||||
fitGridParams?.gridUnitsPerCam,
|
||||
fitGridParams?.colsPerRow,
|
||||
cameras,
|
||||
includeBirdseye,
|
||||
]);
|
||||
|
||||
const handleFitDragStop = useCallback(
|
||||
(
|
||||
@ -481,10 +486,7 @@ export default function DraggableGridLayout({
|
||||
_placeholder: LayoutItem | null,
|
||||
_event: Event,
|
||||
) => {
|
||||
if (!fitToScreen || !fitGridParams || !newItem) {
|
||||
console.log("[FitDrag] SKIP: early return", { fitToScreen, fitGridParams: !!fitGridParams, newItem: !!newItem });
|
||||
return;
|
||||
}
|
||||
if (!fitToScreen || !fitGridParams || !newItem) return;
|
||||
|
||||
const w = fitGridParams.gridUnitsPerCam;
|
||||
const colsPerRow = fitGridParams.colsPerRow;
|
||||
@ -512,22 +514,6 @@ export default function DraggableGridLayout({
|
||||
|
||||
const sourceIndex = orderedNames.indexOf(draggedId);
|
||||
|
||||
console.log("[FitDrag] CALC:", {
|
||||
draggedId,
|
||||
sourceIndex,
|
||||
targetIndex,
|
||||
targetCol,
|
||||
targetRow,
|
||||
clampedRow,
|
||||
totalRows,
|
||||
"newItem.x": newItem.x,
|
||||
"newItem.y": newItem.y,
|
||||
w,
|
||||
colsPerRow,
|
||||
orderedNames,
|
||||
willSwap: sourceIndex !== -1 && sourceIndex !== targetIndex,
|
||||
});
|
||||
|
||||
const snapBack = orderedNames.map((name, index) => ({
|
||||
i: name,
|
||||
x: (index % colsPerRow) * w,
|
||||
@ -537,7 +523,6 @@ export default function DraggableGridLayout({
|
||||
}));
|
||||
|
||||
if (sourceIndex === -1 || sourceIndex === targetIndex) {
|
||||
console.log("[FitDrag] SNAP BACK (no swap)");
|
||||
setFitLayoutOverride(snapBack);
|
||||
return;
|
||||
}
|
||||
@ -556,13 +541,6 @@ export default function DraggableGridLayout({
|
||||
h: w,
|
||||
}));
|
||||
|
||||
console.log("[FitDrag] SWAP:", {
|
||||
from: orderedNames[sourceIndex],
|
||||
to: orderedNames[targetIndex],
|
||||
newOrder,
|
||||
normalized: normalized.map(n => `${n.i}(${n.x},${n.y})`),
|
||||
});
|
||||
|
||||
setFitLayoutOverride(normalized);
|
||||
},
|
||||
[fitToScreen, fitGridParams, fitLayoutOverride, fitLayout],
|
||||
@ -570,13 +548,7 @@ export default function DraggableGridLayout({
|
||||
|
||||
const activeGridLayout = useMemo(() => {
|
||||
if (fitToScreen) {
|
||||
const result = fitLayoutOverride ?? fitLayout ?? currentGridLayout;
|
||||
console.log("[FitDrag] activeGridLayout:", {
|
||||
usingOverride: !!fitLayoutOverride,
|
||||
usingFitLayout: !fitLayoutOverride && !!fitLayout,
|
||||
layout: result?.map(n => `${n.i}(${n.x},${n.y})`),
|
||||
});
|
||||
return result;
|
||||
return fitLayoutOverride ?? fitLayout ?? currentGridLayout;
|
||||
}
|
||||
return currentGridLayout;
|
||||
}, [fitToScreen, fitLayoutOverride, fitLayout, currentGridLayout]);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user