fix: optimize ArtifactListImpl
This commit is contained in:
@@ -3,6 +3,7 @@ import {
|
||||
type FormEvent,
|
||||
memo,
|
||||
type MouseEvent as ReactMouseEvent,
|
||||
useCallback,
|
||||
useEffect,
|
||||
useMemo,
|
||||
useRef,
|
||||
@@ -307,6 +308,35 @@ export default function SchedulePage({
|
||||
: artifacts;
|
||||
}, [artifacts, artifactKeyword]);
|
||||
|
||||
// 稳定传给 ArtifactList 的 3 个回调,让 memo 真正生效 —— 否则父级
|
||||
// (SchedulePage) 任何 store 字段变化都会让卡片列表重新绑定拖拽事件,
|
||||
// 在拖动/快速 hover 时放大体感卡顿。
|
||||
const handleArtifactDrop = useCallback(
|
||||
(artifact: ScheduleArtifact, x: number, y: number) => {
|
||||
useSchedulesStore.getState().addArtifactAt(artifact, x, y);
|
||||
},
|
||||
[],
|
||||
);
|
||||
const handleArtifactDoubleClick = useCallback(
|
||||
(artifact: ScheduleArtifact) => {
|
||||
useSchedulesStore.getState().addArtifactAt(
|
||||
artifact,
|
||||
90 + (schedule?.nodes.length ?? 0) * 245,
|
||||
130,
|
||||
);
|
||||
},
|
||||
[schedule],
|
||||
);
|
||||
const handleArtifactContextMenu = useCallback(
|
||||
(event: ReactMouseEvent, artifact: ScheduleArtifact) => {
|
||||
openScheduleContextMenu(
|
||||
event as ReactMouseEvent<HTMLElement | SVGElement>,
|
||||
{ kind: "artifact", artifact },
|
||||
);
|
||||
},
|
||||
[],
|
||||
);
|
||||
|
||||
return (
|
||||
<section className="schedule-page">
|
||||
<header className="schedule-toolbar">
|
||||
@@ -364,9 +394,9 @@ export default function SchedulePage({
|
||||
<ArtifactList
|
||||
artifacts={filteredArtifacts}
|
||||
keyword={artifactKeyword}
|
||||
onDrop={(artifact, x, y) => void useSchedulesStore.getState().addArtifactAt(artifact, x, y)}
|
||||
onDoubleClick={(artifact) => void useSchedulesStore.getState().addArtifactAt(artifact, 90 + (schedule?.nodes.length ?? 0) * 245, 130)}
|
||||
onContextMenu={(event, artifact) => openScheduleContextMenu(event as ReactMouseEvent<HTMLElement | SVGElement>, { kind: "artifact", artifact })}
|
||||
onDrop={handleArtifactDrop}
|
||||
onDoubleClick={handleArtifactDoubleClick}
|
||||
onContextMenu={handleArtifactContextMenu}
|
||||
onKeywordChange={setArtifactKeyword}
|
||||
/>
|
||||
</aside>
|
||||
|
||||
Reference in New Issue
Block a user