From c7599c74722864d54c96a3f3d52e28290abb9eac Mon Sep 17 00:00:00 2001
From: nsfisis <nsfisis@gmail.com>
Date: Sun, 11 Aug 2024 22:51:03 +0900
Subject: refactor(frontend): add stronger typing to useWebSocket()

---
 frontend/app/components/GolfWatchApp.client.tsx | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

(limited to 'frontend/app/components/GolfWatchApp.client.tsx')

diff --git a/frontend/app/components/GolfWatchApp.client.tsx b/frontend/app/components/GolfWatchApp.client.tsx
index a9c9989..cef6f9a 100644
--- a/frontend/app/components/GolfWatchApp.client.tsx
+++ b/frontend/app/components/GolfWatchApp.client.tsx
@@ -1,6 +1,6 @@
 import { useEffect, useState } from "react";
-import useWebSocket, { ReadyState } from "react-use-websocket";
 import type { components } from "../.server/api/schema";
+import useWebSocket, { ReadyState } from "../hooks/useWebSocket";
 import GolfWatchAppConnecting from "./GolfWatchApps/GolfWatchAppConnecting";
 import GolfWatchAppFinished from "./GolfWatchApps/GolfWatchAppFinished";
 import GolfWatchAppGaming, {
@@ -9,7 +9,8 @@ import GolfWatchAppGaming, {
 import GolfWatchAppStarting from "./GolfWatchApps/GolfWatchAppStarting";
 import GolfWatchAppWaiting from "./GolfWatchApps/GolfWatchAppWaiting";
 
-type WebSocketMessage = components["schemas"]["GameWatcherMessageS2C"];
+type GameWatcherMessageS2C = components["schemas"]["GameWatcherMessageS2C"];
+type GameWatcherMessageC2S = never;
 
 type Game = components["schemas"]["Game"];
 
@@ -27,10 +28,10 @@ export default function GolfWatchApp({
 			? `ws://localhost:8002/iosdc-japan/2024/code-battle/sock/golf/${game.game_id}/watch?token=${sockToken}`
 			: `wss://t.nil.ninja/iosdc-japan/2024/code-battle/sock/golf/${game.game_id}/watch?token=${sockToken}`;
 
-	const { lastJsonMessage, readyState } = useWebSocket<WebSocketMessage>(
-		socketUrl,
-		{},
-	);
+	const { lastJsonMessage, readyState } = useWebSocket<
+		GameWatcherMessageS2C,
+		GameWatcherMessageC2S
+	>(socketUrl);
 
 	const [gameState, setGameState] = useState<GameState>("connecting");
 
-- 
cgit v1.3.1

