mirror of
https://github.com/yuruotong1/autoMate.git
synced 2025-12-26 05:16:21 +08:00
输入框输入内容,直接跳转到聊天窗口;增加llm配置检测
This commit is contained in:
parent
695ae105e6
commit
dbd7505e83
@ -3,19 +3,24 @@ import useChat from '@renderer/hooks/useChat';
|
||||
import { useStore } from '@renderer/store/useStore';
|
||||
import { useTheme } from 'antd-style';
|
||||
import { useEffect, useRef } from 'react';
|
||||
export default function Chat(props: {id: number, revalidator: () => void}) {
|
||||
const {id, revalidator} = props;
|
||||
export default function Chat(props: {id: number, revalidator: () => void, search: string}) {
|
||||
const {id, revalidator, search} = props;
|
||||
const {getResponse} = useChat()
|
||||
const theme = useTheme();
|
||||
const chatMessages = useStore(state=>state.chatMessages)
|
||||
const setMessages = useStore(state=>state.setChatMessage)
|
||||
const proChatRef = useRef<ProChatInstance>();
|
||||
const sendChatWithSearch = useStore(state=>state.sendChatWithSearch)
|
||||
// 确保 useeffect 只执行一次
|
||||
const effectRan = useRef(false);
|
||||
|
||||
useEffect(()=>{
|
||||
if (sendChatWithSearch) {
|
||||
proChatRef.current?.sendMessage(sendChatWithSearch)
|
||||
if (effectRan.current === false) {
|
||||
if (search) {
|
||||
proChatRef.current?.sendMessage(search)
|
||||
}
|
||||
}, [sendChatWithSearch])
|
||||
effectRan.current = true;
|
||||
}
|
||||
}, [])
|
||||
return (
|
||||
<ProChat
|
||||
chats={chatMessages}
|
||||
|
||||
@ -5,17 +5,23 @@ import { QuestionCircleOutlined } from '@ant-design/icons';
|
||||
import Chat from '@renderer/components/Chat';
|
||||
import "./codeEditor.scss"
|
||||
import { useStore } from '@renderer/store/useStore';
|
||||
import { useEffect } from 'react';
|
||||
interface CodeEditorProps {
|
||||
id: number;
|
||||
defaultValue: string;
|
||||
revalidator: () => void;
|
||||
open: boolean;
|
||||
setOpen: (open: boolean) => void;
|
||||
|
||||
search: string;
|
||||
}
|
||||
export default function CodeEditor(props: CodeEditorProps) {
|
||||
const { id, defaultValue, revalidator, open, setOpen} = props;
|
||||
const { id, defaultValue, revalidator, open, setOpen, search} = props;
|
||||
const isCodeLoading = useStore(state => state.isCodeLoading)
|
||||
useEffect(()=>{
|
||||
if (search) {
|
||||
setOpen(true)
|
||||
}
|
||||
}, [])
|
||||
return (
|
||||
<div>
|
||||
<FloatButton icon={<QuestionCircleOutlined />} type="primary" onClick={() => {
|
||||
@ -32,7 +38,7 @@ export default function CodeEditor(props: CodeEditorProps) {
|
||||
padding: 0,
|
||||
},
|
||||
}}>
|
||||
<Chat id={id} revalidator={revalidator}/>
|
||||
<Chat id={id} revalidator={revalidator} search={search}/>
|
||||
</Drawer>
|
||||
<Spin spinning={isCodeLoading} tip="根据自动化方案生成代码中,请稍等...">
|
||||
<CodeMirror
|
||||
|
||||
@ -1,8 +1,10 @@
|
||||
import useSearch from "@renderer/hooks/useSearch"
|
||||
import { SettingOne } from "@icon-park/react"
|
||||
import { Input } from "antd"
|
||||
import { useStore } from "@renderer/store/useStore"
|
||||
export default function Search(): JSX.Element {
|
||||
const {handleSearch} = useSearch()
|
||||
const search = useStore((state)=>state.search)
|
||||
return (
|
||||
<main className="bg-slate-50 p-3 rounded-lg drag" >
|
||||
<div className="bg-slate-200 p-3 rounded-l flex items-center gap-1 no-drag">
|
||||
@ -16,6 +18,7 @@ export default function Search(): JSX.Element {
|
||||
}
|
||||
/>
|
||||
<Input
|
||||
value={search}
|
||||
placeholder="请输入常用的action名字以快速调用"
|
||||
onChange={handleSearch}
|
||||
autoFocus
|
||||
|
||||
@ -7,9 +7,9 @@ export default() => {
|
||||
})
|
||||
|
||||
document.body.addEventListener('mouseover', (e: MouseEvent)=>{
|
||||
if (e.target === document.body) {
|
||||
window.api.setIgnoreMouseEvents(true, {forward: true})
|
||||
}
|
||||
// if (e.target === document.body) {
|
||||
// window.api.setIgnoreMouseEvents(true, {forward: true})
|
||||
// }
|
||||
})
|
||||
}
|
||||
return {setIgnoreMouseEvents}
|
||||
|
||||
@ -5,7 +5,6 @@ export default()=>{
|
||||
const setData = useStore((state)=>state.setData)
|
||||
const search = useStore((state)=>state.search)
|
||||
const setSearch = useStore((state)=>state.setSearch)
|
||||
const setSendChatWithSearch = useStore((state)=>state.setSendChatWithSearch)
|
||||
const selectId = useStore((state)=>state.selectId)
|
||||
const setSelectId = useStore((state)=>state.setSelectId)
|
||||
const handleKeyEvent = useCallback((e: KeyboardEvent) => {
|
||||
@ -47,8 +46,8 @@ export default()=>{
|
||||
const new_id = await window.api.sql(
|
||||
`insert into contents (title, content, category_id, created_at) values ('${search}', '', 0, datetime())`,
|
||||
"create")
|
||||
window.api.openWindow('code', `/0/content/${new_id}`)
|
||||
setSendChatWithSearch(search)
|
||||
window.api.openWindow('code', `/0/content/${new_id}/${search}`)
|
||||
setSearch("")
|
||||
return
|
||||
}
|
||||
setData([])
|
||||
@ -56,7 +55,7 @@ export default()=>{
|
||||
// if (content) await navigator.clipboard.writeText(content)
|
||||
window.api.closeWindow('search')
|
||||
const category_id = data.find((item)=>item.id == id)?.category_id
|
||||
window.api.openWindow('code', `/${category_id}/content/${id}`)
|
||||
window.api.openWindow('code', `/${category_id}/content/${id}/${search}`)
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
import React from 'react'
|
||||
import ReactDOM from 'react-dom/client'
|
||||
import '@renderer/assets/tailwind.css'
|
||||
import '@renderer/assets/global.scss'
|
||||
@ -6,9 +5,7 @@ import { RouterProvider } from 'react-router-dom'
|
||||
import router from './router'
|
||||
|
||||
ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render(
|
||||
<React.StrictMode>
|
||||
|
||||
<RouterProvider router={router} />
|
||||
|
||||
</React.StrictMode>
|
||||
)
|
||||
|
||||
@ -7,9 +7,10 @@ import { useState } from "react"
|
||||
import { useStore } from "@renderer/store/useStore"
|
||||
|
||||
export const Content = () => {
|
||||
const { content, categories } = useLoaderData() as {
|
||||
const { content, categories, search } = useLoaderData() as {
|
||||
content: ContentType
|
||||
categories: CategoryType[]
|
||||
search: string
|
||||
}
|
||||
const revalidator = useRevalidator();
|
||||
const submit = useSubmit()
|
||||
@ -56,6 +57,7 @@ export const Content = () => {
|
||||
id={content.id}
|
||||
defaultValue={content.content}
|
||||
revalidator={() => revalidator.revalidate()}
|
||||
search={search}
|
||||
/>
|
||||
</main>
|
||||
</Form>
|
||||
|
||||
@ -3,6 +3,7 @@ export default async({params}) => {
|
||||
const categories = await window.api.sql(`select * from categories order by id desc`, "findAll")
|
||||
return {
|
||||
content,
|
||||
categories
|
||||
categories,
|
||||
search: params.search
|
||||
}
|
||||
}
|
||||
|
||||
@ -49,7 +49,7 @@ const router = createHashRouter([
|
||||
element: <Welcome />
|
||||
},
|
||||
{
|
||||
path: "content/:id",
|
||||
path: "content/:id/:search?",
|
||||
loader: ContentLoader,
|
||||
action: ContentAction,
|
||||
element: <Content />
|
||||
|
||||
@ -14,9 +14,7 @@ interface StateProps{
|
||||
chatMessages: ChatMessage<Record<string, any>>[],
|
||||
setChatMessage: (chatMessage: ChatMessage<Record<string, any>>[]) => void,
|
||||
isCodeLoading: boolean,
|
||||
setIsCodeLoading: (isCodeLoading: boolean) => void,
|
||||
sendChatWithSearch: string,
|
||||
setSendChatWithSearch: (sendChatWithSearch: string) => void
|
||||
setIsCodeLoading: (isCodeLoading: boolean) => void
|
||||
}
|
||||
export const useStore = create<StateProps>((set) => ({
|
||||
data: [],
|
||||
@ -32,9 +30,7 @@ export const useStore = create<StateProps>((set) => ({
|
||||
chatMessages: [],
|
||||
setChatMessage: (chatMessages) => set({chatMessages}),
|
||||
isCodeLoading: false,
|
||||
setIsCodeLoading: (isCodeLoading) => set({isCodeLoading}),
|
||||
sendChatWithSearch: '',
|
||||
setSendChatWithSearch: (sendChatWithSearch) => set({sendChatWithSearch})
|
||||
setIsCodeLoading: (isCodeLoading) => set({isCodeLoading})
|
||||
}))
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user