Skip to content

Commit

Permalink
perf: use hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
Chanzhaoyu committed Mar 10, 2023
1 parent 07b92d4 commit a2fcd31
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
21 changes: 21 additions & 0 deletions src/views/chat/hooks/useUsingContext.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { ref } from 'vue'
import { useMessage } from 'naive-ui'
import { t } from '@/locales'

export function useUsingContext() {
const ms = useMessage()
const usingContext = ref<boolean>(true)

function toggleUsingContext() {
usingContext.value = !usingContext.value
if (usingContext.value)
ms.success(t('chat.turnOnContext'))
else
ms.warning(t('chat.turnOffContext'))
}

return {
usingContext,
toggleUsingContext,
}
}
12 changes: 3 additions & 9 deletions src/views/chat/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Message } from './components'
import { useScroll } from './hooks/useScroll'
import { useChat } from './hooks/useChat'
import { useCopyCode } from './hooks/useCopyCode'
import { useUsingContext } from './hooks/useUsingContext'
import HeaderComponent from './components/Header/index.vue'
import { HoverButton, SvgIcon } from '@/components/common'
import { useBasicLayout } from '@/hooks/useBasicLayout'
Expand All @@ -25,9 +26,11 @@ const ms = useMessage()
const chatStore = useChatStore()
useCopyCode()
const { isMobile } = useBasicLayout()
const { addChat, updateChat, updateChatSome, getChatByUuidAndIndex } = useChat()
const { scrollRef, scrollToBottom } = useScroll()
const { usingContext, toggleUsingContext } = useUsingContext()
const { uuid } = route.params as { uuid: string }
Expand All @@ -36,7 +39,6 @@ const conversationList = computed(() => dataSources.value.filter(item => (!item.
const prompt = ref<string>('')
const loading = ref<boolean>(false)
const usingContext = ref<boolean>(true)
function handleSubmit() {
onConversation()
Expand Down Expand Up @@ -392,14 +394,6 @@ function handleStop() {
}
}
function toggleUsingContext() {
usingContext.value = !usingContext.value
if (usingContext.value)
ms.success(t('chat.turnOnContext'))
else
ms.warning(t('chat.turnOffContext'))
}
const placeholder = computed(() => {
if (isMobile.value)
return t('chat.placeholderMobile')
Expand Down

0 comments on commit a2fcd31

Please sign in to comment.