Skip to content

Commit 886addb

Browse files
committed
arrow 기능 렌더링 최적화
1 parent 4c19b02 commit 886addb

File tree

6 files changed

+87
-222
lines changed

6 files changed

+87
-222
lines changed

src/pages/Visualization/components/RightSection/RightSection.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { usePreprocessedCodesProcessor } from "./hooks/usePreprocessedCodesProce
1414
import { useResizeObserver } from "./hooks/useResizeObserver";
1515
import { useTutorialPosition } from "./hooks/useTutorialPosition";
1616
import { useScrollHandlers } from "./hooks/useScrollHandlers";
17+
import { useArrowPosition } from "./hooks/useArrowPosition";
1718

1819
// 컴포넌트
1920
import { VisualizationControls } from "./components/VisualizationControls";
@@ -73,6 +74,12 @@ const RightSection = ({ onboardingStep, setTutorialPosition }: RightSectionProps
7374
},
7475
});
7576

77+
useArrowPosition({
78+
stepIdx,
79+
codeFlowScrollTop,
80+
structuresScrollTop,
81+
});
82+
7683
// Location 변경 시 stepIdx 초기화
7784
useEffect(() => {
7885
return () => {
@@ -124,15 +131,11 @@ const RightSection = ({ onboardingStep, setTutorialPosition }: RightSectionProps
124131
stepIdx={stepIdx}
125132
width={width}
126133
height={height}
127-
codeFlowScrollTop={codeFlowScrollTop}
128134
onScroll={handleScrollCodeFlow}
129135
/>
130136
<CallStackView
131137
StructuresList={StructuresList}
132138
stepIdx={stepIdx}
133-
width={width}
134-
height={height}
135-
structuresScrollTop={structuresScrollTop}
136139
onScroll={handleScrollStructures}
137140
ref={rightSection2Ref}
138141
/>

src/pages/Visualization/components/RightSection/components/CallStackView.tsx

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,19 @@ import { WrapperDataStructureItem } from "@/pages/Visualization/types/dataStruct
66
interface CallStackViewProps {
77
StructuresList: AllDataStructureItem;
88
stepIdx: number;
9-
width: number;
10-
height: number;
11-
structuresScrollTop: number;
129
onScroll: (e: React.UIEvent<HTMLDivElement>) => void;
1310
}
1411

1512
export const CallStackView = React.forwardRef<HTMLDivElement, CallStackViewProps>(
16-
({ StructuresList, stepIdx, width, height, structuresScrollTop, onScroll }, ref) => {
13+
({ StructuresList, stepIdx, onScroll }, ref) => {
1714
return (
1815
<div id="split-2-2" className="view-section2-2" ref={ref}>
1916
<div className="view-data" onScroll={onScroll}>
2017
<p className="data-name">콜스택</p>
2118
<ul className="var-list">
2219
{StructuresList?.length > 0 &&
2320
stepIdx >= 0 &&
24-
renderingStructure(
25-
StructuresList[stepIdx] as WrapperDataStructureItem,
26-
width,
27-
height,
28-
structuresScrollTop
29-
)}
21+
renderingStructure(StructuresList[stepIdx] as WrapperDataStructureItem)}
3022
</ul>
3123
</div>
3224
</div>

src/pages/Visualization/components/RightSection/components/CodeFlowView.tsx

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,20 @@ interface CodeFlowViewProps {
77
stepIdx: number;
88
width: number;
99
height: number;
10-
codeFlowScrollTop: number;
1110
onScroll: (e: React.UIEvent<HTMLDivElement>) => void;
1211
}
1312

14-
export const CodeFlowView: React.FC<CodeFlowViewProps> = ({
15-
codeFlowList,
16-
stepIdx,
17-
width,
18-
height,
19-
codeFlowScrollTop,
20-
onScroll,
21-
}) => {
13+
export const CodeFlowView: React.FC<CodeFlowViewProps> = ({ codeFlowList, stepIdx, width, height, onScroll }) => {
2214
return (
2315
<div id="split-2-1" className="view-section2-1">
2416
<div className="view-data" onScroll={onScroll}>
2517
<p className="data-name">코드흐름</p>
2618
<div style={{ width: "600px", display: "flex", flexDirection: "column", flex: 1 }}>
2719
{codeFlowList?.length > 0 &&
2820
stepIdx >= 0 &&
29-
renderingCodeFlow(codeFlowList[stepIdx].objects[0].child, width, height, codeFlowScrollTop)}
21+
renderingCodeFlow(codeFlowList[stepIdx].objects[0].child, width, height)}
3022
</div>
3123
</div>
3224
</div>
3325
);
3426
};
35-
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { useEffect, useCallback } from "react";
2+
import { useArrowStore } from "@/store/arrow";
3+
4+
interface UseArrowPositionProps {
5+
stepIdx: number;
6+
codeFlowScrollTop: number;
7+
structuresScrollTop: number;
8+
}
9+
10+
export const useArrowPosition = ({ stepIdx, codeFlowScrollTop, structuresScrollTop }: UseArrowPositionProps) => {
11+
const setTop = useArrowStore((state) => state.setTop);
12+
const setRight = useArrowStore((state) => state.setRight);
13+
14+
const updatePosition = useCallback(() => {
15+
// Try to find the highlighted code flow item
16+
const codeFlowElement = document.getElementById("highlighted-code-flow");
17+
if (codeFlowElement) {
18+
const rect = codeFlowElement.getBoundingClientRect();
19+
20+
setTop(rect.top);
21+
setRight(rect.right);
22+
return;
23+
}
24+
25+
const structureElement = document.getElementById("highlighted-structure-item");
26+
if (structureElement) {
27+
const rect = structureElement.getBoundingClientRect();
28+
setTop(rect.top);
29+
setRight(rect.right);
30+
return;
31+
}
32+
}, [stepIdx, codeFlowScrollTop, structuresScrollTop, setTop, setRight]);
33+
34+
useEffect(() => {
35+
updatePosition();
36+
}, [updatePosition]);
37+
};

0 commit comments

Comments
 (0)