Skip to content

Commit

Permalink
fix: chatgpt layout
Browse files Browse the repository at this point in the history
  • Loading branch information
drl990114 committed Jan 1, 2025
1 parent c4b8824 commit e3b6545
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 9 deletions.
2 changes: 2 additions & 0 deletions apps/desktop/src/components/SideBar/RightBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Container as SideBarContainer, SideBarHeader } from './styles'
import { RIGHTBARITEMKEYS } from '@/constants'
import { Tooltip } from 'zens'
import { TableOfContent } from '@/extensions/table-of-content'
import chatgpt from '@/extensions/chatgpt'

function RightBar() {
const [activeRightBarItemKey, setActiveRightBarItemKey] = useState<RIGHTBARITEMKEYS>(
Expand All @@ -13,6 +14,7 @@ function RightBar() {
const rightBarDataSource: RightBarItem[] = useMemo(() => {
return [
TableOfContent,
chatgpt,
]
}, [])

Expand Down
2 changes: 0 additions & 2 deletions apps/desktop/src/components/SideBar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { memo, useMemo, useState } from 'react'
import { Container as SideBarContainer, SideBarHeader } from './styles'
import { Explorer } from '@/components'
import { RIGHTBARITEMKEYS } from '@/constants'
import chatgpt from '@/extensions/chatgpt'
import BookMarks from '@/extensions/bookmarks'
import { Search } from '@/extensions/search'
import { Tooltip } from 'zens'
Expand All @@ -23,7 +22,6 @@ function SideBar() {
},
Search,
BookMarks,
chatgpt,
]
}, [])

Expand Down
24 changes: 19 additions & 5 deletions apps/desktop/src/extensions/chatgpt/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,42 @@ import SideBarHeader from '@/components/SideBar/SideBarHeader'
import useThemeStore from '@/stores/useThemeStore'
import useAppSettingStore from '@/stores/useAppSettingStore'
import { addNewMarkdownFileEdit } from '@/services/editor-file'
import { useTranslation } from 'react-i18next'
import { toast } from 'zens'

const ChatList: React.FC<ChatListProps> = (props) => {
const { chatList, curGptModelIndex, gptModels, setCurGptModelIndex, addChat, delChat, setModels } =
useChatGPTStore()
const {
chatList,
curGptModelIndex,
gptModels,
setCurGptModelIndex,
addChat,
delChat,
setModels,
} = useChatGPTStore()
const { settingData } = useAppSettingStore()
const { curTheme } = useThemeStore()
const apiBase = settingData[SettingKeys.chatgpt_url]
const apiKey = settingData[SettingKeys.chatgpt]
const [askInput, setAskInput] = useState('')
const listRef = useRef<HTMLDivElement>(null)
const { t } = useTranslation()

useEffect(() => {
if (listRef.current) {
listRef.current.scrollTop = listRef.current.scrollHeight
}

const newModels = settingData[SettingKeys.chatgpt_models].split(',').map((model: string) => model.trim())
const newModels = settingData[SettingKeys.chatgpt_models]
.split(',')
.map((model: string) => model.trim())
setModels(newModels)
}, [chatList.length])

const handleSubmit = useCallback(() => {
if (!apiKey) return
if (!apiKey) {
return toast.error('Please set your ChatGPT API Key first')
}

addChat(askInput, apiBase, apiKey)
setAskInput('')
Expand Down Expand Up @@ -170,7 +184,7 @@ const ChatList: React.FC<ChatListProps> = (props) => {
onChange={handleChange}
/>
<Button className='submit' btnType='primary' size='small' onClick={handleSubmit}>
submit
{t('common.submit')}
</Button>
</BottomBar>
</Container>
Expand Down
3 changes: 2 additions & 1 deletion locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"delete": "delete",
"file": "file",
"folder": "folder",
"fetching": "Loading..."
"fetching": "Loading...",
"submit": "submit"
},
"view": {
"label": "View",
Expand Down
3 changes: 2 additions & 1 deletion locales/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"delete": "删除",
"file": "文件",
"folder": "文件夹",
"fetching": "加载中..."
"fetching": "加载中...",
"submit": "提交"
},
"view": {
"label": "视图",
Expand Down

0 comments on commit e3b6545

Please sign in to comment.