diff --git a/src/devtools/App.tsx b/src/devtools/App.tsx index 3e4a871a..77062e67 100644 --- a/src/devtools/App.tsx +++ b/src/devtools/App.tsx @@ -14,6 +14,7 @@ import AddCircleOutlineIcon from '@mui/icons-material/AddCircleOutline'; import ChatIcon from '@mui/icons-material/Chat'; import useStore, { openLink } from './store' import SettingWindow from './SettingWindow' +import ChatConfigWindow from './ChatConfigWindow' import ChatBubbleOutlineOutlinedIcon from '@mui/icons-material/ChatBubbleOutlineOutlined'; import SettingsIcon from '@mui/icons-material/Settings'; import AddIcon from '@mui/icons-material/Add'; @@ -41,6 +42,8 @@ function App() { } }, [store.needSetting]) + const [configureChatConfig, setConfigureChatConfig] = React.useState(null); + const generate = async (msgs: Message[]) => { const msg = createMessage('assistant', '...') const newMessages = [...msgs, msg] @@ -142,7 +145,7 @@ function App() { newSession.messages = session.messages store.createChatSession(newSession, ix) }} - updateMe={(updated) => store.updateChatSession(updated)} + editMe={() => setConfigureChatConfig(session)} /> )) } @@ -308,6 +311,18 @@ function App() { }} close={() => setOpenSettingWindow(false)} /> + { + configureChatConfig !== null && ( + { + store.updateChatSession(session) + setConfigureChatConfig(null) + }} + close={() => setConfigureChatConfig(null)} + /> + ) + } ); diff --git a/src/devtools/ChatConfigWindow.tsx b/src/devtools/ChatConfigWindow.tsx new file mode 100644 index 00000000..f2e6f402 --- /dev/null +++ b/src/devtools/ChatConfigWindow.tsx @@ -0,0 +1,60 @@ +import React from 'react'; +import './App.css'; +import { + Button, Dialog, DialogContent, DialogActions, DialogTitle, DialogContentText, TextField, +} from '@mui/material'; +import { Session } from './types' + +const { useEffect } = React + +interface Props { + open: boolean + session: Session + save(session: Session): void + close(): void +} + +export default function ChatConfigWindow(props: Props) { + const [dataEdit, setDataEdit] = React.useState(props.session); + + useEffect(() => { + setDataEdit(props.session) + }, [props.session]) + + const onCancel = () => { + props.close() + setDataEdit(props.session) + } + + const onSave = () => { + if (dataEdit.name === '') { + dataEdit.name = props.session.name + } + props.save(dataEdit) + props.close() + } + + return ( + + Chat Config + + + + setDataEdit({ ...dataEdit, name: e.target.value.trim() })} + /> + + + + + + + ); +} diff --git a/src/devtools/SessionItem.tsx b/src/devtools/SessionItem.tsx index 26f6a689..ebcadfc2 100644 --- a/src/devtools/SessionItem.tsx +++ b/src/devtools/SessionItem.tsx @@ -23,13 +23,11 @@ export interface Props { switchMe: () => void deleteMe: () => void copyMe: () => void - updateMe: (session: Session) => void + editMe: () => void } export default function SessionItem(props: Props) { - const { session, selected, switchMe, deleteMe, copyMe, updateMe } = props - const [editMode, setEditMode] = useState(false) - const [nameEdit, setNameEdit] = useState(session.name) + const { session, selected, switchMe, deleteMe, copyMe, editMe } = props const [anchorEl, setAnchorEl] = React.useState(null); const open = Boolean(anchorEl); const handleClick = (event: React.MouseEvent) => { @@ -39,108 +37,61 @@ export default function SessionItem(props: Props) { const handleClose = () => { setAnchorEl(null); }; - const saveNameEdit = () => { - handleClose() - updateMe({ ...session, name: nameEdit }) - setEditMode(false) - } - - const inputEl = useRef(null) - useEffect(() => { - if (editMode) { - inputEl.current.focus() - } - }, [editMode]) return ( { - if (!editMode) { - switchMe() - } - }} + onClick={() => switchMe()} > - { - - editMode ? ( -
{ - event.preventDefault() - saveNameEdit() - }}> - { - e.preventDefault() - setNameEdit(e.target.value) - }} - /> - - ) : ( - - {session.name} - - ) - } + + {session.name} +
- { - editMode ? ( - <> - - - - - ) : ( - <> - - - - - { - setEditMode(true) - }} disableRipple - > - - Rename - + + + + + { + editMe() + handleClose() + }} disableRipple> + + Rename + - { - copyMe() - }} disableRipple - > - - Copy - + { + copyMe() + handleClose() + }} disableRipple> + + Copy + - + - { - setAnchorEl(null) - handleClose() - deleteMe() - }} disableRipple - > - - Delete - + { + setAnchorEl(null) + handleClose() + deleteMe() + }} disableRipple + > + + Delete + - - - ) - } +
) }