Compare commits

...

1 Commits

Author SHA1 Message Date
Gregory Schier
64f5d973eb Fix env editor switching 2025-05-23 21:44:34 -07:00

View File

@@ -12,6 +12,7 @@ import {
} from 'react'; } from 'react';
import type { XYCoord } from 'react-dnd'; import type { XYCoord } from 'react-dnd';
import { useDrag, useDrop } from 'react-dnd'; import { useDrag, useDrop } from 'react-dnd';
import { useRandomKey } from '../../hooks/useRandomKey';
import { useToggle } from '../../hooks/useToggle'; import { useToggle } from '../../hooks/useToggle';
import { languageFromContentType } from '../../lib/contentType'; import { languageFromContentType } from '../../lib/contentType';
import { showDialog } from '../../lib/dialog'; import { showDialog } from '../../lib/dialog';
@@ -107,6 +108,9 @@ export const PairEditor = forwardRef<PairEditorRef, PairEditorProps>(function Pa
const [hoveredIndex, setHoveredIndex] = useState<number | null>(null); const [hoveredIndex, setHoveredIndex] = useState<number | null>(null);
const [pairs, setPairs] = useState<PairWithId[]>([]); const [pairs, setPairs] = useState<PairWithId[]>([]);
const [showAll, toggleShowAll] = useToggle(false); const [showAll, toggleShowAll] = useToggle(false);
// NOTE: Use local force update key because we trigger an effect on forceUpdateKey change. If
// we simply pass forceUpdateKey to the editor, the data set by useEffect will be stale.
const [localForceUpdateKey, regenerateLocalForceUpdateKey] = useRandomKey();
useImperativeHandle( useImperativeHandle(
ref, ref,
@@ -136,6 +140,7 @@ export const PairEditor = forwardRef<PairEditorRef, PairEditorProps>(function Pa
} }
setPairs(newPairs); setPairs(newPairs);
regenerateLocalForceUpdateKey();
// eslint-disable-next-line react-hooks/exhaustive-deps // eslint-disable-next-line react-hooks/exhaustive-deps
}, [forceUpdateKey]); }, [forceUpdateKey]);
@@ -240,7 +245,7 @@ export const PairEditor = forwardRef<PairEditorRef, PairEditorProps>(function Pa
forcedEnvironmentId={forcedEnvironmentId} forcedEnvironmentId={forcedEnvironmentId}
forceFocusNamePairId={forceFocusNamePairId} forceFocusNamePairId={forceFocusNamePairId}
forceFocusValuePairId={forceFocusValuePairId} forceFocusValuePairId={forceFocusValuePairId}
forceUpdateKey={forceUpdateKey} forceUpdateKey={localForceUpdateKey}
index={i} index={i}
isLast={isLast} isLast={isLast}
nameAutocomplete={nameAutocomplete} nameAutocomplete={nameAutocomplete}