Skip to content

Commit

Permalink
fix(web): ensure new layer reorders correctly. (#1346)
Browse files Browse the repository at this point in the history
  • Loading branch information
mkumbobeaty authored Jan 14, 2025
1 parent 52f66e4 commit c8910cc
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions web/src/beta/features/Editor/hooks/useLayers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,23 @@ export default function ({

const [sortedLayerIds, setSortedLayerIds] = useState<string[]>([]);

useEffect(() => {
if (!originNlsLayers) return;
setSortedLayerIds((prev) =>
prev.length > 0
? prev
: [...originNlsLayers]
.sort((a, b) => (a.index ?? 0) - (b.index ?? 0))
.map((l) => l.id)
);
}, [originNlsLayers]);
useEffect(() => {
if (!originNlsLayers) return;

setSortedLayerIds((prev) => {
const originIds = originNlsLayers.map((l) => l.id);
if (
prev.length === originIds.length &&
prev.every((id, idx) => id === originIds[idx])
) {
return prev;
}
return [...originNlsLayers]
.sort((a, b) => (a.index ?? 0) - (b.index ?? 0))
.map((l) => l.id);
});
}, [originNlsLayers]);


const nlsLayers: NLSLayer[] = useMemo(
() =>
Expand Down

0 comments on commit c8910cc

Please sign in to comment.