Add backend theme selection based on URL parameter for embedded chat
This commit is contained in:
parent
96905a8933
commit
0b27022931
4 changed files with 23 additions and 0 deletions
|
|
@ -29,6 +29,7 @@ export const useGetSharedChatSearchParams = () => {
|
||||||
from: searchParams.get('from') as SharedFrom,
|
from: searchParams.get('from') as SharedFrom,
|
||||||
sharedId: searchParams.get('shared_id'),
|
sharedId: searchParams.get('shared_id'),
|
||||||
locale: searchParams.get('locale'),
|
locale: searchParams.get('locale'),
|
||||||
|
theme: searchParams.get('theme'),
|
||||||
data: data,
|
data: data,
|
||||||
visibleAvatar: searchParams.get('visible_avatar')
|
visibleAvatar: searchParams.get('visible_avatar')
|
||||||
? searchParams.get('visible_avatar') !== '1'
|
? searchParams.get('visible_avatar') !== '1'
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,9 @@ import { NextMessageInput } from '@/components/message-input/next';
|
||||||
import MessageItem from '@/components/next-message-item';
|
import MessageItem from '@/components/next-message-item';
|
||||||
import PdfDrawer from '@/components/pdf-drawer';
|
import PdfDrawer from '@/components/pdf-drawer';
|
||||||
import { useClickDrawer } from '@/components/pdf-drawer/hooks';
|
import { useClickDrawer } from '@/components/pdf-drawer/hooks';
|
||||||
|
import { useTheme } from '@/components/theme-provider';
|
||||||
import { MessageType } from '@/constants/chat';
|
import { MessageType } from '@/constants/chat';
|
||||||
|
import { ThemeEnum } from '@/constants/common';
|
||||||
import { useUploadCanvasFileWithProgress } from '@/hooks/use-agent-request';
|
import { useUploadCanvasFileWithProgress } from '@/hooks/use-agent-request';
|
||||||
import { cn } from '@/lib/utils';
|
import { cn } from '@/lib/utils';
|
||||||
import i18n from '@/locales/config';
|
import i18n from '@/locales/config';
|
||||||
|
|
@ -25,8 +27,10 @@ const ChatContainer = () => {
|
||||||
const {
|
const {
|
||||||
sharedId: conversationId,
|
sharedId: conversationId,
|
||||||
locale,
|
locale,
|
||||||
|
theme,
|
||||||
visibleAvatar,
|
visibleAvatar,
|
||||||
} = useGetSharedChatSearchParams();
|
} = useGetSharedChatSearchParams();
|
||||||
|
const { setTheme } = useTheme();
|
||||||
const { visible, hideModal, documentId, selectedChunk, clickDocumentButton } =
|
const { visible, hideModal, documentId, selectedChunk, clickDocumentButton } =
|
||||||
useClickDrawer();
|
useClickDrawer();
|
||||||
|
|
||||||
|
|
@ -89,6 +93,12 @@ const ChatContainer = () => {
|
||||||
}
|
}
|
||||||
}, [locale, visibleAvatar]);
|
}, [locale, visibleAvatar]);
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
if (theme && (theme === ThemeEnum.Light || theme === ThemeEnum.Dark)) {
|
||||||
|
setTheme(theme as ThemeEnum);
|
||||||
|
}
|
||||||
|
}, [theme, setTheme]);
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
if (!isTaskMode && inputsData.prologue) {
|
if (!isTaskMode && inputsData.prologue) {
|
||||||
addNewestOneAnswer({
|
addNewestOneAnswer({
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,7 @@ export const useGetSharedChatSearchParams = () => {
|
||||||
from: searchParams.get('from') as SharedFrom,
|
from: searchParams.get('from') as SharedFrom,
|
||||||
sharedId: searchParams.get('shared_id'),
|
sharedId: searchParams.get('shared_id'),
|
||||||
locale: searchParams.get('locale'),
|
locale: searchParams.get('locale'),
|
||||||
|
theme: searchParams.get('theme'),
|
||||||
data: data,
|
data: data,
|
||||||
visibleAvatar: searchParams.get('visible_avatar')
|
visibleAvatar: searchParams.get('visible_avatar')
|
||||||
? searchParams.get('visible_avatar') !== '1'
|
? searchParams.get('visible_avatar') !== '1'
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,9 @@ import { NextMessageInput } from '@/components/message-input/next';
|
||||||
import MessageItem from '@/components/message-item';
|
import MessageItem from '@/components/message-item';
|
||||||
import PdfDrawer from '@/components/pdf-drawer';
|
import PdfDrawer from '@/components/pdf-drawer';
|
||||||
import { useClickDrawer } from '@/components/pdf-drawer/hooks';
|
import { useClickDrawer } from '@/components/pdf-drawer/hooks';
|
||||||
|
import { useTheme } from '@/components/theme-provider';
|
||||||
import { MessageType, SharedFrom } from '@/constants/chat';
|
import { MessageType, SharedFrom } from '@/constants/chat';
|
||||||
|
import { ThemeEnum } from '@/constants/common';
|
||||||
import { useFetchNextConversationSSE } from '@/hooks/chat-hooks';
|
import { useFetchNextConversationSSE } from '@/hooks/chat-hooks';
|
||||||
import { useFetchFlowSSE } from '@/hooks/flow-hooks';
|
import { useFetchFlowSSE } from '@/hooks/flow-hooks';
|
||||||
import { useFetchExternalChatInfo } from '@/hooks/use-chat-request';
|
import { useFetchExternalChatInfo } from '@/hooks/use-chat-request';
|
||||||
|
|
@ -22,8 +24,10 @@ const ChatContainer = () => {
|
||||||
sharedId: conversationId,
|
sharedId: conversationId,
|
||||||
from,
|
from,
|
||||||
locale,
|
locale,
|
||||||
|
theme,
|
||||||
visibleAvatar,
|
visibleAvatar,
|
||||||
} = useGetSharedChatSearchParams();
|
} = useGetSharedChatSearchParams();
|
||||||
|
const { setTheme } = useTheme();
|
||||||
const { visible, hideModal, documentId, selectedChunk, clickDocumentButton } =
|
const { visible, hideModal, documentId, selectedChunk, clickDocumentButton } =
|
||||||
useClickDrawer();
|
useClickDrawer();
|
||||||
|
|
||||||
|
|
@ -52,6 +56,13 @@ const ChatContainer = () => {
|
||||||
i18n.changeLanguage(locale);
|
i18n.changeLanguage(locale);
|
||||||
}
|
}
|
||||||
}, [locale, visibleAvatar]);
|
}, [locale, visibleAvatar]);
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
if (theme && (theme === ThemeEnum.Light || theme === ThemeEnum.Dark)) {
|
||||||
|
setTheme(theme as ThemeEnum);
|
||||||
|
}
|
||||||
|
}, [theme, setTheme]);
|
||||||
|
|
||||||
const { data: avatarData } = useFetchAvatar();
|
const { data: avatarData } = useFetchAvatar();
|
||||||
|
|
||||||
if (!conversationId) {
|
if (!conversationId) {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue