From b6db26acb46df7d4b17b2ad69b68006948f47184 Mon Sep 17 00:00:00 2001 From: Chris Heo Date: Mon, 30 Dec 2024 09:16:34 -0800 Subject: [PATCH 1/3] add useConnectionHandler --- src/hooks/useConnectionHandler.ts | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/hooks/useConnectionHandler.ts diff --git a/src/hooks/useConnectionHandler.ts b/src/hooks/useConnectionHandler.ts new file mode 100644 index 000000000..4718db26d --- /dev/null +++ b/src/hooks/useConnectionHandler.ts @@ -0,0 +1,21 @@ + +import { useState } from 'react'; +import { ConnectionHandler, ConnectionState } from '@sendbird/chat'; +import useSendbirdStateContext from './useSendbirdStateContext' +import uuidv4 from '../utils/uuid'; + +export const useConnectionState = (): ConnectionState => { + const { stores } = useSendbirdStateContext(); + const { sdkStore } = stores; + const { sdk } = sdkStore; + + const [connectionState, setConnectionState] = useState(sdk.connectionState) + sdk.addConnectionHandler(uuidv4(), new ConnectionHandler({ + onConnected: () => setConnectionState(ConnectionState.OPEN), + onDisconnected: () => setConnectionState(ConnectionState.CLOSED), + onReconnectStarted: () => setConnectionState(ConnectionState.CONNECTING), + onReconnectSucceeded: () => setConnectionState(ConnectionState.OPEN), + onReconnectFailed: () => setConnectionState(ConnectionState.CLOSED), + })) + return connectionState +} \ No newline at end of file From 7ddff95d4e81b5070bc87bee416048acc7b92813 Mon Sep 17 00:00:00 2001 From: Chris Heo Date: Thu, 2 Jan 2025 21:19:26 -0800 Subject: [PATCH 2/3] review fix --- ...useConnectionHandler.ts => useConnectionState.ts} | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) rename src/hooks/{useConnectionHandler.ts => useConnectionState.ts} (82%) diff --git a/src/hooks/useConnectionHandler.ts b/src/hooks/useConnectionState.ts similarity index 82% rename from src/hooks/useConnectionHandler.ts rename to src/hooks/useConnectionState.ts index 4718db26d..697fb74c3 100644 --- a/src/hooks/useConnectionHandler.ts +++ b/src/hooks/useConnectionState.ts @@ -1,6 +1,8 @@ import { useState } from 'react'; -import { ConnectionHandler, ConnectionState } from '@sendbird/chat'; +import { ConnectionState } from '@sendbird/chat'; + +import ConnectionHandler from '../lib/handlers/ConnectionHandler'; import useSendbirdStateContext from './useSendbirdStateContext' import uuidv4 from '../utils/uuid'; @@ -9,13 +11,13 @@ export const useConnectionState = (): ConnectionState => { const { sdkStore } = stores; const { sdk } = sdkStore; - const [connectionState, setConnectionState] = useState(sdk.connectionState) + const [connectionState, setConnectionState] = useState(sdk.connectionState); sdk.addConnectionHandler(uuidv4(), new ConnectionHandler({ onConnected: () => setConnectionState(ConnectionState.OPEN), onDisconnected: () => setConnectionState(ConnectionState.CLOSED), onReconnectStarted: () => setConnectionState(ConnectionState.CONNECTING), onReconnectSucceeded: () => setConnectionState(ConnectionState.OPEN), onReconnectFailed: () => setConnectionState(ConnectionState.CLOSED), - })) - return connectionState -} \ No newline at end of file + })); + return connectionState; +}; \ No newline at end of file From 080f4568e367b4f75a8a6a7d58acfc17c72b405d Mon Sep 17 00:00:00 2001 From: HoonBaek Date: Mon, 6 Jan 2025 17:14:32 +0900 Subject: [PATCH 3/3] fix lint --- src/hooks/useConnectionState.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/hooks/useConnectionState.ts b/src/hooks/useConnectionState.ts index 697fb74c3..d5f43bf23 100644 --- a/src/hooks/useConnectionState.ts +++ b/src/hooks/useConnectionState.ts @@ -1,9 +1,8 @@ - import { useState } from 'react'; import { ConnectionState } from '@sendbird/chat'; import ConnectionHandler from '../lib/handlers/ConnectionHandler'; -import useSendbirdStateContext from './useSendbirdStateContext' +import useSendbirdStateContext from './useSendbirdStateContext'; import uuidv4 from '../utils/uuid'; export const useConnectionState = (): ConnectionState => { @@ -20,4 +19,4 @@ export const useConnectionState = (): ConnectionState => { onReconnectFailed: () => setConnectionState(ConnectionState.CLOSED), })); return connectionState; -}; \ No newline at end of file +};