Skip to content

Commit

Permalink
polish
Browse files Browse the repository at this point in the history
  • Loading branch information
dromerolovo committed Jun 24, 2024
1 parent af4be6b commit 4f6f2f1
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 24 deletions.
2 changes: 1 addition & 1 deletion web/app/components/app/overview/embedded/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ const Embedded = ({ siteInfo, isShow, onClose, appBaseUrl, accessToken, classNam

const { langeniusVersionInfo } = useAppContext()
const themeBuilder = useThemeContext()
themeBuilder.buildTheme(siteInfo?.chat_color_theme ?? '#1C64F2', siteInfo?.chat_color_theme_inverted ?? false)
themeBuilder.buildTheme(siteInfo?.chat_color_theme ?? null, siteInfo?.chat_color_theme_inverted ?? false)
const isTestEnv = langeniusVersionInfo.current_env === 'TESTING' || langeniusVersionInfo.current_env === 'DEVELOPMENT'
const onClickCopy = () => {
if (option === 'chromePlugin') {
Expand Down
12 changes: 6 additions & 6 deletions web/app/components/base/chat/chat/chat-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,20 @@ import {
useDraggableUploader,
useImageFiles,
} from '@/app/components/base/image-uploader/hooks'
import { ThemeBuilder } from '../embedded-chatbot/theme/theme-context'
import { Theme } from '../embedded-chatbot/theme/theme-context'
import { CssTransform } from '../embedded-chatbot/theme/utils'

type ChatInputProps = {
visionConfig?: VisionConfig
speechToTextConfig?: EnableType
onSend?: OnSend
themeBuilder: ThemeBuilder | null
theme?: Theme | null
}
const ChatInput: FC<ChatInputProps> = ({
visionConfig,
speechToTextConfig,
onSend,
themeBuilder,
theme,
}) => {
const { appData } = useChatWithHistoryContext()
const { t } = useTranslation()
Expand Down Expand Up @@ -120,9 +120,9 @@ const ChatInput: FC<ChatInputProps> = ({

const media = useBreakpoints()
const isMobile = media === MediaType.mobile
const sendIconThemeStyle = themeBuilder?.theme
const sendIconThemeStyle = theme
? {
color: (isActiveIconFocused || query || (query.trim() !== '')) ? themeBuilder.theme.primaryColor : '#d1d5db',
color: (isActiveIconFocused || query || (query.trim() !== '')) ? theme.primaryColor : '#d1d5db',
}
: {}
const sendBtn = (
Expand All @@ -131,7 +131,7 @@ const ChatInput: FC<ChatInputProps> = ({
onMouseEnter={() => setActiveIconFocused(true)}
onMouseLeave={() => setActiveIconFocused(false)}
onClick={handleSend}
style={isActiveIconFocused ? CssTransform(themeBuilder?.theme?.chatBubbleColorStyle ?? '') : {}}
style={isActiveIconFocused ? CssTransform(theme?.chatBubbleColorStyle ?? '') : {}}
>
<Send03
style={sendIconThemeStyle}
Expand Down
5 changes: 3 additions & 2 deletions web/app/components/base/chat/chat/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@ export type ChatProps = {
chatAnswerContainerInner?: string
hideProcessDetail?: boolean
hideLogModal?: boolean
themeBuilder: ThemeBuilder | null
themeBuilder?: ThemeBuilder
}

const Chat: FC<ChatProps> = ({
appData,
config,
Expand Down Expand Up @@ -266,7 +267,7 @@ const Chat: FC<ChatProps> = ({
visionConfig={config?.file_upload?.image}
speechToTextConfig={config?.speech_to_text}
onSend={onSend}
themeBuilder={themeBuilder}
theme={themeBuilder?.theme}
/>
)
}
Expand Down
3 changes: 1 addition & 2 deletions web/app/components/base/chat/embedded-chatbot/context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export type EmbeddedChatbotContextValue = {
appId?: string
handleFeedback: (messageId: string, feedback: Feedback) => void
currentChatInstanceRef: RefObject<{ handleStop: () => void }>
themeBuilder: ThemeBuilder | null
themeBuilder?: ThemeBuilder
}

export const EmbeddedChatbotContext = createContext<EmbeddedChatbotContextValue>({
Expand All @@ -62,6 +62,5 @@ export const EmbeddedChatbotContext = createContext<EmbeddedChatbotContextValue>
isInstalledApp: false,
handleFeedback: () => {},
currentChatInstanceRef: { current: { handleStop: () => {} } },
themeBuilder: null,
})
export const useEmbeddedChatbotContext = () => useContext(EmbeddedChatbotContext)
16 changes: 11 additions & 5 deletions web/app/components/base/chat/embedded-chatbot/header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,29 @@ import React from 'react'
import { RiRefreshLine } from '@remixicon/react'
import { useTranslation } from 'react-i18next'
import Tooltip from '@/app/components/base/tooltip'
import { useThemeContext } from './theme/theme-context'
import { Theme } from './theme/theme-context'
import { CssTransform } from './theme/utils'


export type IHeaderProps = {
isMobile?: boolean
customerIcon?: React.ReactNode
title: string
theme?: Theme
// icon: string
// icon_background: string
onCreateNewChat?: () => void
}
const Header: FC<IHeaderProps> = ({
isMobile,
customerIcon,
title,
theme,
// icon,
// icon_background,
onCreateNewChat,
}) => {
const { t } = useTranslation()
const themeBuilder = useThemeContext()
if (!isMobile)
return null

Expand All @@ -28,13 +34,13 @@ const Header: FC<IHeaderProps> = ({
className={`
shrink-0 flex items-center justify-between h-14 px-4
`}
style={Object.assign({}, CssTransform(themeBuilder.theme?.backgroundHeaderColorStyle ?? ''), CssTransform(themeBuilder.theme?.headerBorderBottomStyle ?? '')) }
style={Object.assign({}, CssTransform(theme?.backgroundHeaderColorStyle ?? ''), CssTransform(theme?.headerBorderBottomStyle ?? '')) }
>
<div className="flex items-center space-x-2">
{customerIcon}
<div
className={'text-sm font-bold text-white'}
style={CssTransform(themeBuilder.theme?.colorFontOnHeaderStyle ?? '')}
style={CssTransform(theme?.colorFontOnHeaderStyle ?? '')}
>
{title}
</div>
Expand All @@ -47,7 +53,7 @@ const Header: FC<IHeaderProps> = ({
<div className='flex cursor-pointer hover:rounded-lg hover:bg-black/5 w-8 h-8 items-center justify-center' onClick={() => {
onCreateNewChat?.()
}}>
<RiRefreshLine className="h-4 w-4 text-sm font-bold text-white" color={themeBuilder.theme?.colorPathOnHeader}/>
<RiRefreshLine className="h-4 w-4 text-sm font-bold text-white" color={theme?.colorPathOnHeader}/>
</div>
</Tooltip>
</div>
Expand Down
6 changes: 3 additions & 3 deletions web/app/components/base/chat/embedded-chatbot/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,18 @@ const Chatbot = () => {
showConfigPanelBeforeChat,
appChatListDataLoading,
handleNewConversation,
themeBuilder,
} = useEmbeddedChatbotContext()

const chatReady = (!showConfigPanelBeforeChat || !!appPrevChatList.length)
const customConfig = appData?.custom_config
const site = appData?.site

const themeBuilder = useThemeContext()

const difyIcon = <LogoHeader />

useEffect(() => {
themeBuilder?.buildTheme(site?.chat_color_theme, site?.chat_color_theme_inverted)
if (site) {
themeBuilder.buildTheme(site.chat_color_theme, site.chat_color_theme_inverted)
if (customConfig)
document.title = `${site.title}`
else
Expand All @@ -67,6 +66,7 @@ const Chatbot = () => {
isMobile={isMobile}
title={site?.title || ''}
customerIcon={isDify() ? difyIcon : ''}
theme={themeBuilder?.theme}
onCreateNewChat={handleNewConversation}
/>
<div className='flex bg-white overflow-hidden'>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,24 @@ export class Theme {
}

export class ThemeBuilder {
public theme: Theme | null = null
private _theme?: Theme
private buildChecker = false

public get theme() {
if (this._theme === undefined)
throw new Error('The theme should be built first and then accessed')
else
return this._theme
}

public buildTheme(chatColorTheme: string | null = null, chatColorThemeInverted = false) {
if (!this.buildChecker) {
this.theme = new Theme(chatColorTheme, chatColorThemeInverted)
this._theme = new Theme(chatColorTheme, chatColorThemeInverted)
this.buildChecker = true
}
else {
if (this.theme?.chatColorTheme !== chatColorTheme || this.theme?.chatColorThemeInverted !== chatColorThemeInverted) {
this.theme = new Theme(chatColorTheme, chatColorThemeInverted)
this._theme = new Theme(chatColorTheme, chatColorThemeInverted)
this.buildChecker = true
}
}
Expand Down
4 changes: 2 additions & 2 deletions web/models/share.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ export type ConversationItem = {

export type SiteInfo = {
title: string
chat_color_theme: string
chat_color_theme_inverted: boolean
chat_color_theme?: string
chat_color_theme_inverted?: boolean
icon?: string
icon_background?: string
description?: string
Expand Down

0 comments on commit 4f6f2f1

Please sign in to comment.