Fix: webapp color theme (#6908)

This commit is contained in:
KVOJJJin 2024-08-02 15:08:14 +08:00 committed by GitHub
parent e683461416
commit 62cc4077bb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 11 additions and 2 deletions

View File

@ -30,6 +30,7 @@ const ChatWrapper = () => {
handleFeedback, handleFeedback,
currentChatInstanceRef, currentChatInstanceRef,
appData, appData,
themeBuilder,
} = useChatWithHistoryContext() } = useChatWithHistoryContext()
const appConfig = useMemo(() => { const appConfig = useMemo(() => {
const config = appParams || {} const config = appParams || {}
@ -143,6 +144,7 @@ const ChatWrapper = () => {
onFeedback={handleFeedback} onFeedback={handleFeedback}
suggestedQuestions={suggestedQuestions} suggestedQuestions={suggestedQuestions}
hideProcessDetail hideProcessDetail
themeBuilder={themeBuilder}
/> />
) )
} }

View File

@ -8,6 +8,7 @@ import type {
ChatItem, ChatItem,
Feedback, Feedback,
} from '../types' } from '../types'
import type { ThemeBuilder } from '../embedded-chatbot/theme/theme-context'
import type { import type {
AppConversationData, AppConversationData,
AppData, AppData,
@ -46,6 +47,7 @@ export type ChatWithHistoryContextValue = {
appId?: string appId?: string
handleFeedback: (messageId: string, feedback: Feedback) => void handleFeedback: (messageId: string, feedback: Feedback) => void
currentChatInstanceRef: RefObject<{ handleStop: () => void }> currentChatInstanceRef: RefObject<{ handleStop: () => void }>
themeBuilder?: ThemeBuilder
} }
export const ChatWithHistoryContext = createContext<ChatWithHistoryContextValue>({ export const ChatWithHistoryContext = createContext<ChatWithHistoryContextValue>({

View File

@ -4,6 +4,7 @@ import {
useState, useState,
} from 'react' } from 'react'
import { useAsyncEffect } from 'ahooks' import { useAsyncEffect } from 'ahooks'
import { useThemeContext } from '../embedded-chatbot/theme/theme-context'
import { import {
ChatWithHistoryContext, ChatWithHistoryContext,
useChatWithHistoryContext, useChatWithHistoryContext,
@ -34,6 +35,7 @@ const ChatWithHistory: FC<ChatWithHistoryProps> = ({
appChatListDataLoading, appChatListDataLoading,
chatShouldReloadKey, chatShouldReloadKey,
isMobile, isMobile,
themeBuilder,
} = useChatWithHistoryContext() } = useChatWithHistoryContext()
const chatReady = (!showConfigPanelBeforeChat || !!appPrevChatList.length) const chatReady = (!showConfigPanelBeforeChat || !!appPrevChatList.length)
@ -41,13 +43,14 @@ const ChatWithHistory: FC<ChatWithHistoryProps> = ({
const site = appData?.site const site = appData?.site
useEffect(() => { useEffect(() => {
themeBuilder?.buildTheme(site?.chat_color_theme, site?.chat_color_theme_inverted)
if (site) { if (site) {
if (customConfig) if (customConfig)
document.title = `${site.title}` document.title = `${site.title}`
else else
document.title = `${site.title} - Powered by Dify` document.title = `${site.title} - Powered by Dify`
} }
}, [site, customConfig]) }, [site, customConfig, themeBuilder])
if (appInfoLoading) { if (appInfoLoading) {
return ( return (
@ -106,6 +109,7 @@ const ChatWithHistoryWrap: FC<ChatWithHistoryWrapProps> = ({
}) => { }) => {
const media = useBreakpoints() const media = useBreakpoints()
const isMobile = media === MediaType.mobile const isMobile = media === MediaType.mobile
const themeBuilder = useThemeContext()
const { const {
appInfoError, appInfoError,
@ -171,6 +175,7 @@ const ChatWithHistoryWrap: FC<ChatWithHistoryWrapProps> = ({
appId, appId,
handleFeedback, handleFeedback,
currentChatInstanceRef, currentChatInstanceRef,
themeBuilder,
}}> }}>
<ChatWithHistory className={className} /> <ChatWithHistory className={className} />
</ChatWithHistoryContext.Provider> </ChatWithHistoryContext.Provider>

View File

@ -51,7 +51,7 @@ const Chatbot = () => {
else else
document.title = `${site.title} - Powered by Dify` document.title = `${site.title} - Powered by Dify`
} }
}, [site, customConfig]) }, [site, customConfig, themeBuilder])
if (appInfoLoading) { if (appInfoLoading) {
return ( return (