Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
165 changes: 0 additions & 165 deletions frontend/src/Pages/Game.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,96 +50,13 @@ const Game: React.FC = () => {
[key: string]: unknown;
};

<<<<<<< HEAD
const parseContent = useCallback(
<T,>(raw: string, messageType: string): T | null => {
try {
return JSON.parse(raw) as T;
} catch (error) {
console.error(`Failed to parse ${messageType} content:`, error);
return null;
=======
const handleWebSocketMessage = (message: any) => {
switch (message.type) {
case "DEBATE_START":
setState((prevState) => ({ ...prevState, loading: false }));
break;
case "DEBATE_END":
setState((prevState) => ({ ...prevState, gameEnded: true }));
break;
case "TURN_START": {
const { currentTurn, duration } = JSON.parse(message.content);
setState((prevState) => ({
...prevState,
isTurn: currentTurn === userId,
turnDuration: duration,
}));
break;
}
case "TURN_END":
setState((prevState) => ({
...prevState,
isTurn: false,
turnDuration: 0,
}));
break;
case "CHAT_MESSAGE": {
const { sender, message: chatMessage } = JSON.parse(message.content);
const newMessage: ChatMessage = {
isUser: sender === userId,
text: chatMessage,
};
setState((prevState) => ({
...prevState,
messages: [...prevState.messages, newMessage],
transcriptStatus: { ...prevState.transcriptStatus, loading: false },
typingIndicators: prevState.typingIndicators.filter(
(indicator) => indicator.userId !== sender
),
}));
break;
}
case "TYPING_STATUS": {
const data = JSON.parse(message.content);
const senderId: string | undefined = data.userId ?? data.sender;
if (!senderId || senderId === userId) {
break;
}
setState((prevState) => ({
...prevState,
typingIndicators: upsertIndicator(prevState.typingIndicators, {
userId: senderId,
username: data.username,
isTyping: data.isTyping,
partialText: data.partialText,
}),
}));
break;
}
case "SPEAKING_STATUS": {
const data = JSON.parse(message.content);
const senderId: string | undefined = data.userId ?? data.sender;
if (!senderId || senderId === userId) {
break;
}
setState((prevState) => ({
...prevState,
typingIndicators: upsertIndicator(prevState.typingIndicators, {
userId: senderId,
username: data.username,
isSpeaking: data.isSpeaking,
}),
}));
break;
}
case "GENERATING_TRANSCRIPT": {
const { sender } = JSON.parse(message.content);
setState((prevState) => ({
...prevState,
transcriptStatus: { loading: true, isUser: sender === userId }, //transcript is getting generated
}));
break;
>>>>>>> main
}
},
[]
Expand Down Expand Up @@ -374,85 +291,7 @@ const Game: React.FC = () => {
ws.onclose = () => console.log("WebSocket connection closed");

return () => ws.close();
<<<<<<< HEAD
}, [userId, handleWebSocketMessage]);
=======
}, [userId]);

const handleSendChatMessage = useCallback(
(messageText: string, mode: "type" | "speak") => {
const trimmed = messageText.trim();
if (!trimmed) {
return;
}

sendWebSocketMessage({
type: "CHAT_MESSAGE",
content: JSON.stringify({
sender: userId,
message: trimmed,
mode,
timestamp: Date.now(),
}),
});
},
[sendWebSocketMessage, userId]
);

const handleTypingChange = useCallback(
(isTyping: boolean, partialText?: string) => {
if (lastTypingStateRef.current === isTyping && !partialText) {
return;
}

lastTypingStateRef.current = isTyping;
sendWebSocketMessage({
type: "TYPING_STATUS",
content: JSON.stringify({
userId,
isTyping,
partialText,
}),
});
setState((prevState) => ({
...prevState,
typingIndicators: upsertIndicator(prevState.typingIndicators, {
userId: userId ?? "local",
username: "You",
isTyping,
partialText,
}),
}));
},
[sendWebSocketMessage, userId]
);

const handleSpeakingChange = useCallback(
(isSpeaking: boolean) => {
if (lastSpeakingStateRef.current === isSpeaking) {
return;
}

lastSpeakingStateRef.current = isSpeaking;
sendWebSocketMessage({
type: "SPEAKING_STATUS",
content: JSON.stringify({
userId,
isSpeaking,
}),
});
setState((prevState) => ({
...prevState,
typingIndicators: upsertIndicator(prevState.typingIndicators, {
userId: userId ?? "local",
username: "You",
isSpeaking,
}),
}));
},
[sendWebSocketMessage, userId]
);
>>>>>>> main

const renderGameContent = () => (
<div className="w-screen h-screen flex justify-center items-center">
Expand Down Expand Up @@ -589,11 +428,7 @@ const Game: React.FC = () => {
}}
typingIndicators={state.typingIndicators}
isMyTurn={state.isTurn}
<<<<<<< HEAD
disabled={!(state.isTurn && !state.gameEnded)}
=======
disabled={state.gameEnded || state.loading}
>>>>>>> main
/>
</div>
</div>
Expand Down
5 changes: 0 additions & 5 deletions frontend/src/Pages/MatchLogs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,16 +112,11 @@ const MatchLogs: React.FC = () => {
const [score1, score2] = log.score.total.split("-").map(Number);
if (score1 > score2) winner = player1.split(": ")[1];
else if (score2 > score1) winner = player2;
<<<<<<< HEAD
else {
winner = log.match.includes("First Round Match 3")
? "Ayaan Khanna (Tiebreaker)"
: "";
}
=======
else
winner = isFirstRoundMatch3 ? "Ayaan Khanna (Tiebreaker)" : "";
>>>>>>> main
}
return {
player1: player1.split(": ")[1] || player1,
Expand Down
19 changes: 14 additions & 5 deletions frontend/src/Pages/OnlineDebateRoom.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,13 @@ const extractJSON = (response: string): string => {
if (match && match[1]) return match[1].trim();
return response;
};
const BASE_URL = import.meta.env.VITE_BASE_URL || window.location.origin;

const WS_BASE_URL = BASE_URL.replace(
/^https?/,
(match) => (match === "https" ? "wss" : "ws")
);


const OnlineDebateRoom = (): JSX.Element => {
const { roomId } = useParams<{ roomId: string }>();
Expand Down Expand Up @@ -508,7 +515,7 @@ const OnlineDebateRoom = (): JSX.Element => {
judgePollRef.current = setInterval(async () => {
try {
const pollResponse = await fetch(
`http://localhost:1313/submit-transcripts`,
`${BASE_URL}/submit-transcripts`,
{
method: "POST",
headers: {
Expand Down Expand Up @@ -595,7 +602,7 @@ const OnlineDebateRoom = (): JSX.Element => {

try {
const response = await fetch(
`http://localhost:1313/submit-transcripts`,
`${BASE_URL}/submit-transcripts`,
{
method: "POST",
headers: {
Expand Down Expand Up @@ -867,7 +874,8 @@ const OnlineDebateRoom = (): JSX.Element => {

try {
const token = getAuthToken();
const response = await fetch(`http://localhost:1313/rooms`, {
const response = await fetch(`${BASE_URL}/rooms`, {

method: "POST",
headers: {
"Content-Type": "application/json",
Expand Down Expand Up @@ -900,7 +908,7 @@ const OnlineDebateRoom = (): JSX.Element => {
try {
const token = getAuthToken();
const response = await fetch(
`http://localhost:1313/rooms/${roomId}/participants`,
`${BASE_URL}/rooms/${roomId}/participants`,
{
headers: {
Authorization: `Bearer ${token}`,
Expand Down Expand Up @@ -1084,7 +1092,8 @@ const OnlineDebateRoom = (): JSX.Element => {
const token = getAuthToken();
if (!token || !roomId) return;

const wsUrl = `ws://localhost:1313/ws?room=${roomId}&token=${token}`;
const wsUrl = `${WS_BASE_URL}/ws?room=${roomId}&token=${token}`;

const rws = new ReconnectingWebSocket(wsUrl, [], {
connectionTimeout: 4000,
maxRetries: Infinity,
Expand Down
20 changes: 0 additions & 20 deletions frontend/src/Pages/TeamBuilder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,6 @@ const TeamBuilder: React.FC = () => {
</div>

{/* Team Matchmaking */}
<<<<<<< HEAD
<div className="mt-4">
<TeamMatchmaking
team={team}
Expand All @@ -645,20 +644,6 @@ const TeamBuilder: React.FC = () => {
}
/>
</div>
=======
{user && user.id && (
<div className="mt-4">
<TeamMatchmaking
team={team}
user={{
id: user.id,
email: user.email ?? "",
displayName: user.displayName ?? user.email ?? "",
}}
/>
</div>
)}
>>>>>>> main

<div className="flex flex-wrap gap-2">
{(team.members || []).map((member: TeamMember) => (
Expand Down Expand Up @@ -837,12 +822,7 @@ const TeamBuilder: React.FC = () => {
<div className="space-y-4">
{availableTeams.map((team) => {
const memberCount = team.members?.length || 0;
<<<<<<< HEAD
const capacity = team.maxSize || 4;
=======
const capacity =
team.maxSize && team.maxSize > 0 ? team.maxSize : 4;
>>>>>>> main
const isFull = memberCount >= capacity;

return (
Expand Down
Loading