Skip to content

Commit a13ebed

Browse files
authored
Merge pull request #97 from njxue/fix-resize-observer
Fix resize observer error
2 parents 9ae0f15 + 6171c8f commit a13ebed

File tree

2 files changed

+19
-69
lines changed

2 files changed

+19
-69
lines changed
Lines changed: 11 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
.container {
2-
height: 100vh;
2+
height: 100%;
33
width: 100%;
44
overflow-x: hidden;
55
display: flex;
@@ -19,36 +19,21 @@
1919
min-height: 0;
2020
}
2121

22-
.questionContent {
23-
height: 100%;
24-
display: flex;
25-
flex-direction: column;
26-
position: relative;
27-
}
28-
29-
.contentArea {
30-
position: relative;
31-
flex: 1;
22+
.outputContainer {
23+
flex-shrink: 0;
24+
overflow-y: auto;
3225
}
3326

34-
.questionDetail,
35-
.chatFrame {
36-
position: absolute;
37-
top: 0;
38-
left: 0;
39-
width: 100%;
27+
.leftContainer {
28+
flex-shrink: 0;
29+
display: flex;
30+
flex-direction: column;
4031
height: 100%;
41-
transition: opacity 0.3s ease, visibility 0.3s ease;
42-
}
43-
44-
.hidden {
45-
opacity: 0;
46-
visibility: hidden;
32+
overflow-y: auto;
4733
}
4834

49-
.visible {
50-
opacity: 1;
51-
visibility: visible;
35+
.questionAndChatContainer {
36+
flex: 1;
5237
}
5338

5439
.verticalSeparator,
@@ -71,8 +56,3 @@
7156
cursor: row-resize;
7257
height: 6px;
7358
}
74-
75-
.outputContainer {
76-
flex-shrink: 0;
77-
overflow-y: auto;
78-
}

frontend/src/presentation/pages/CollaborationRoomPage.tsx

Lines changed: 8 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,9 @@ const CollaborationRoomPage: React.FC = () => {
2828
const [showChat, setShowChat] = useState(false);
2929
const [loading, setLoading] = useState<boolean>(true);
3030
const [error, setError] = useState<string | null>(null);
31-
const resizeTimeoutRef = useRef<NodeJS.Timeout>();
3231

3332
// Extract details from location.state if available
3433
const { roomId, attemptStartedAt, matchUserId, questionId } = locationState || {};
35-
const handleResize = useCallback(() => {
36-
if (resizeTimeoutRef.current) {
37-
clearTimeout(resizeTimeoutRef.current);
38-
}
39-
resizeTimeoutRef.current = setTimeout(() => {
40-
console.log("Resizing...");
41-
}, 100);
42-
}, []);
4334

4435
useEffect(() => {
4536
const populateRoom = async () => {
@@ -98,33 +89,19 @@ const CollaborationRoomPage: React.FC = () => {
9889
fetchQuestion();
9990
}, [room]);
10091

101-
useEffect(() => {
102-
const resizeObserver = new ResizeObserver((entries) => {
103-
if (entries[0]) handleResize();
104-
});
105-
106-
const container = document.querySelector(`.${styles.container}`);
107-
if (container) resizeObserver.observe(container);
108-
109-
return () => {
110-
resizeObserver.disconnect();
111-
if (resizeTimeoutRef.current) clearTimeout(resizeTimeoutRef.current);
112-
};
113-
}, [handleResize]);
114-
11592
// Resizable Layout Configurations
11693
const { position: questionPosition, separatorProps: verticalSeparatorProps } = useResizable({
11794
axis: "x",
11895
min: 300,
119-
initial: window.innerWidth * 0.3,
120-
max: window.innerWidth * 0.6
96+
initial: window.innerWidth * 0.4,
97+
max: 800
12198
});
12299

123100
const { position: outputPosition, separatorProps: horizontalSeparatorProps } = useResizable({
124101
axis: "y",
125102
min: 60,
126-
initial: window.innerHeight * 0.2,
127-
max: window.innerHeight * 0.6,
103+
initial: 60,
104+
max: 500,
128105
reverse: true
129106
});
130107

@@ -145,17 +122,10 @@ const CollaborationRoomPage: React.FC = () => {
145122
<>
146123
{room && question ? (
147124
<div className={styles.container}>
148-
<div className={styles.questionContainer} style={{ width: questionPosition }}>
149-
<div className={styles.questionContent}>
150-
<ToggleButton showChat={showChat} onClick={() => setShowChat(!showChat)} />
151-
<div className={styles.contentArea}>
152-
<div className={`${styles.questionDetail} ${showChat ? styles.hidden : ""}`}>
153-
<QuestionDetail question={question} />
154-
</div>
155-
<div className={`${styles.chatFrame} ${showChat ? styles.visible : styles.hidden}`}>
156-
<ChatFrame roomId={room.roomId} />
157-
</div>
158-
</div>
125+
<div className={styles.leftContainer} style={{ width: questionPosition }}>
126+
<ToggleButton showChat={showChat} onClick={() => setShowChat((showChat) => !showChat)} />
127+
<div className={styles.questionAndChatContainer}>
128+
{showChat ? <ChatFrame roomId={roomId} /> : <QuestionDetail question={question} />}
159129
</div>
160130
</div>
161131

0 commit comments

Comments
 (0)