Skip to content

Commit

Permalink
chore: rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
bang9 committed Sep 6, 2024
1 parent 3e0bd70 commit 225ed91
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 20 deletions.
11 changes: 11 additions & 0 deletions src/components/chat/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ import useSendbirdStateContext from '@uikit/hooks/useSendbirdStateContext';

import { ChatContainer } from './context/ChatProvider';
import { ChatUI } from './ui';
import { useConstantState } from '../../context/ConstantContext';
import { useWidgetSession, useWidgetSetting } from '../../context/WidgetSettingContext';
import { useAssignGlobalFunction } from '../../hooks/useAssignGlobalFunction';
import useAutoDismissMobileKeyboardHandler from '../../hooks/useAutoDismissMobileKeyboardHandler';
import { useResetHistoryOnConnected } from '../../hooks/useResetHistoryOnConnected';
import { useWidgetInactivityTimeout } from '../../hooks/useWidgetInactivityTimeout';

const Chat = ({ fullscreen = false }: { fullscreen?: boolean }) => {
const { stores } = useSendbirdStateContext();
const { locale } = useConstantState();
const widgetSetting = useWidgetSetting();
const widgetSession = useWidgetSession();

Expand All @@ -29,6 +32,13 @@ const Chat = ({ fullscreen = false }: { fullscreen?: boolean }) => {
stores.sdkStore.initialized,
]);

// Set locale for chatbot
useEffect(() => {
if (locale && stores.sdkStore.initialized && stores.sdkStore.sdk) {
stores.sdkStore.sdk.setLocaleForChatbot(locale);
}
}, [locale, stores.sdkStore.initialized, stores.sdkStore.sdk]);

return (
<ChatContainer
sdk={stores.sdkStore.sdk}
Expand All @@ -44,6 +54,7 @@ const Chat = ({ fullscreen = false }: { fullscreen?: boolean }) => {
};

const HeadlessForHooks = ({ fullscreen }: { fullscreen: boolean }) => {
useAssignGlobalFunction();
useResetHistoryOnConnected();
useWidgetInactivityTimeout(fullscreen);
useAutoDismissMobileKeyboardHandler();
Expand Down
22 changes: 2 additions & 20 deletions src/components/widget/ProviderContainer.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import { SendbirdErrorCode } from '@sendbird/chat';
import React, { PropsWithChildren, useEffect, useMemo } from 'react';
import React, { useMemo } from 'react';
import { StyleSheetManager, ThemeProvider } from 'styled-components';

import { useSendbirdStateContext } from '@uikit/index';
import SendbirdProvider from '@uikit/lib/Sendbird';

import { ChatAiWidgetProps } from './ChatAiWidget';
import { generateCSSVariables } from '../../colors';
import { ConstantStateProvider, useConstantState } from '../../context/ConstantContext';
import { useWidgetSession, useWidgetSetting, WidgetSettingProvider } from '../../context/WidgetSettingContext';
import { useWidgetState, WidgetStateProvider } from '../../context/WidgetStateContext';
import { useAssignGlobalFunction } from '../../hooks/useAssignGlobalFunction';
import { useStyledComponentsTarget } from '../../hooks/useStyledComponentsTarget';
import { getTheme } from '../../theme';
import { isDashboardPreview } from '../../utils';
Expand Down Expand Up @@ -136,25 +134,9 @@ export default function ProviderContainer(props: ProviderContainerProps) {
<ConstantStateProvider {...props}>
<WidgetSettingProvider>
<WidgetStateProvider>
<SBComponent>
<HeadlessComponent>{props.children}</HeadlessComponent>
</SBComponent>
<SBComponent>{props.children}</SBComponent>
</WidgetStateProvider>
</WidgetSettingProvider>
</ConstantStateProvider>
);
}

const HeadlessComponent = ({ children }: PropsWithChildren) => {
useAssignGlobalFunction();
const { locale } = useConstantState();
const { stores } = useSendbirdStateContext();

useEffect(() => {
if (locale && stores.sdkStore.initialized && stores.sdkStore.sdk) {
stores.sdkStore.sdk.setLocaleForChatbot(locale);
}
}, [locale, stores.sdkStore.initialized, stores.sdkStore.sdk]);

return <>{children}</>;
};

0 comments on commit 225ed91

Please sign in to comment.