Skip to content

Commit 1057445

Browse files
fix: handle enableOfflineSupport prop as part of useAppSettings hook
1 parent 74052d8 commit 1057445

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

package/src/components/Chat/Chat.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ const ChatWithContext = <
196196

197197
const setActiveChannel = (newChannel?: Channel<StreamChatGenerics>) => setChannel(newChannel);
198198

199-
const appSettings = useAppSettings(client, isOnline);
199+
const appSettings = useAppSettings(client, isOnline, enableOfflineSupport);
200200

201201
const chatContext = useCreateChatContext({
202202
appSettings,

package/src/components/Chat/hooks/useAppSettings.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export const useAppSettings = <
99
>(
1010
client: StreamChat<StreamChatGenerics>,
1111
isOnline: boolean | null,
12+
enableOfflineSupport: boolean,
1213
): AppSettingsAPIResponse | null => {
1314
const [appSettings, setAppSettings] = useState<AppSettingsAPIResponse | null>(null);
1415
const isMounted = useRef(true);
@@ -17,7 +18,7 @@ export const useAppSettings = <
1718
async function enforeAppSettings() {
1819
if (!client.userID) return;
1920

20-
if (!isOnline) {
21+
if (!isOnline && enableOfflineSupport) {
2122
const appSettings = dbApi.getAppSettings({ currentUserId: client.userID });
2223
setAppSettings(appSettings);
2324
return;
@@ -27,10 +28,11 @@ export const useAppSettings = <
2728
const appSettings = await client.getAppSettings();
2829
if (isMounted.current) {
2930
setAppSettings(appSettings);
30-
dbApi.upsertAppSettings({
31-
appSettings,
32-
currentUserId: client.userID as string,
33-
});
31+
enableOfflineSupport &&
32+
dbApi.upsertAppSettings({
33+
appSettings,
34+
currentUserId: client.userID as string,
35+
});
3436
}
3537
} catch (error: unknown) {
3638
if (error instanceof Error) {

0 commit comments

Comments
 (0)