Skip to content

Commit e923f8a

Browse files
committed
Fix duplicate username
1 parent 0ba9a76 commit e923f8a

File tree

2 files changed

+9
-17
lines changed

2 files changed

+9
-17
lines changed

frontend/src/domain/context/CollaborationContext.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export const CollaborationProvider: React.FC<{ children: ReactNode }> = ({ child
5656
provider.awareness.setLocalStateField(USERNAME, username);
5757
provider.awareness.on("change", () => {
5858
const users = Array.from(provider.awareness.getStates().values());
59-
setConnectedUsers(users.map((user) => user[USERNAME]));
59+
setConnectedUsers(Array.from(new Set(users.map((user) => user[USERNAME]))));
6060
});
6161

6262
return () => provider.destroy();

frontend/src/presentation/pages/CollaborationRoomPage.tsx

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ import { questionUseCases } from "../../domain/usecases/QuestionUseCases";
1313
import { roomUseCases } from "../../domain/usecases/RoomUseCases";
1414
import { Room } from "../../domain/entities/Room";
1515
import { useAuth } from "../../domain/context/AuthContext";
16-
import { message, Spin } from "antd";
16+
import { Spin } from "antd";
17+
import { toast } from "react-toastify";
1718

1819
const CollaborationRoomPage: React.FC = () => {
1920
const location = useLocation();
@@ -30,12 +31,7 @@ const CollaborationRoomPage: React.FC = () => {
3031
const resizeTimeoutRef = useRef<NodeJS.Timeout>();
3132

3233
// Extract details from location.state if available
33-
const {
34-
roomId,
35-
attemptStartedAt,
36-
matchUserId,
37-
questionId,
38-
} = locationState || {};
34+
const { roomId, attemptStartedAt, matchUserId, questionId } = locationState || {};
3935

4036
const handleResize = useCallback(() => {
4137
if (resizeTimeoutRef.current) {
@@ -52,11 +48,7 @@ const CollaborationRoomPage: React.FC = () => {
5248
setError(null);
5349
try {
5450
// Check if location.state has all required details
55-
const hasAllDetails =
56-
roomId &&
57-
attemptStartedAt &&
58-
matchUserId &&
59-
questionId;
51+
const hasAllDetails = roomId && attemptStartedAt && matchUserId && questionId;
6052

6153
if (hasAllDetails) {
6254
// Populate room with details from location.state
@@ -65,10 +57,10 @@ const CollaborationRoomPage: React.FC = () => {
6557
attemptStartedAt: attemptStartedAt,
6658
userIdOne: user.user!._id,
6759
userIdTwo: matchUserId,
68-
questionId: questionId,
60+
questionId: questionId
6961
});
7062
} else {
71-
if (!urlRoomId) return ;
63+
if (!urlRoomId) return;
7264
// Fetch room details from API
7365
const fetchedRoom = await roomUseCases.getRoomDetails(urlRoomId);
7466
// Ensure the current user is userIdOne
@@ -82,7 +74,7 @@ const CollaborationRoomPage: React.FC = () => {
8274
} catch (err) {
8375
console.error("Failed to populate room:", err);
8476
setError("Failed to load room details.");
85-
message.error("Failed to load room details.");
77+
toast.error("Failed to load room details.", { toastId: "roomError" });
8678
} finally {
8779
setLoading(false);
8880
}
@@ -101,7 +93,7 @@ const CollaborationRoomPage: React.FC = () => {
10193
} catch (err) {
10294
console.warn("Failed to fetch question:", err);
10395
setError("Failed to load question details.");
104-
message.error("Failed to load question details.");
96+
toast.error("Failed to load question details.", { toastId: "questionError" });
10597
}
10698
}
10799
};

0 commit comments

Comments
 (0)