diff --git a/package.json b/package.json index 228690c..f5657cd 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "talk-vite", "private": true, - "version": "2.1.0", + "version": "2.1.2", "type": "module", "scripts": { "dev": "vite", diff --git a/src/home/chat-window/attached/attached-preview.tsx b/src/home/chat-window/attached/attached-preview.tsx index f2dc815..a82ce41 100644 --- a/src/home/chat-window/attached/attached-preview.tsx +++ b/src/home/chat-window/attached/attached-preview.tsx @@ -9,7 +9,6 @@ import {findPrompt, Prompt, promptState} from "../../../state/promt-state.ts"; import {AttachedItem} from "./attached-item.tsx"; import {cx} from "../../../util/util.tsx"; import {PromptEditor} from "../prompt/prompt-editor.tsx"; -import {subscribe} from "valtio"; import {CloseIcon} from "../compnent/widget/icon.tsx"; type HPProps = { @@ -71,15 +70,6 @@ export const AttachedPreview: React.FC = ({chatProxy}) => { // eslint-disable-next-line react-hooks/exhaustive-deps }, [isPAPinning]); - useEffect(() => { - const scroll = () => { - if (scrollRef.current) { - scrollRef.current.scrollTop += layoutState.PAButtonWheelDeltaY - } - } - scroll() - return subscribe(layoutState, scroll) - }, []); return (
= ({promptProxy}) => { promptProxy.name = e.target.value} /> diff --git a/src/home/chat-window/chat-window.tsx b/src/home/chat-window/chat-window.tsx index 6e6bf7d..58c7614 100644 --- a/src/home/chat-window/chat-window.tsx +++ b/src/home/chat-window/chat-window.tsx @@ -1,21 +1,19 @@ import {appState, Chat, currentChatProxy} from "../../state/app-state.ts" import TextArea from "./text-area.tsx" import Recorder from "./recorder.tsx" -import React, {useEffect, useRef, useState} from "react" +import React, {useEffect, useState} from "react" import {subscribeKey} from "valtio/utils" import {MessageList} from "./message-list/message-list.tsx" import {PromptAttached} from "./prompt-attached.tsx" import {cx} from "../../util/util.tsx" import {useSnapshot} from "valtio/react" import {layoutState} from "../../state/layout-state.ts" -import {throttle} from "lodash" export const ChatWindow: React.FC = () => { const [chatProxy, setChatProxy] = useState(undefined) // console.info("ChatWindow rendered", new Date().toLocaleString()) - const buttonRef = useRef(null) const {isPAPinning} = useSnapshot(layoutState) const {showRecorder} = useSnapshot(appState.pref) @@ -31,17 +29,8 @@ export const ChatWindow: React.FC = () => { }, []) - const handleMouseMove = throttle((event: React.MouseEvent) => { - if (buttonRef.current) { - const rect = buttonRef.current.getBoundingClientRect() - const [x, y] = [(rect.left + 18), (rect.top + 18)] - layoutState.PAButtonDistance = Math.hypot(x - event.clientX, y - event.clientY) - } - }, 50) - return (
{
- <> -
- +
+ appState.pref.showSidebar = !appState.pref.showSidebar} > -

{chatProxy?.name}

-
layoutState.isPAPinning = true} - > -

P

-
+

{chatProxy?.name}

+
layoutState.isPAPinning = true} + > +

P

- +
+ +
@@ -86,7 +75,7 @@ export const ChatWindow: React.FC = () => { :
}
- +
} diff --git a/src/home/chat-window/prompt/prompt-editor-item.tsx b/src/home/chat-window/prompt/prompt-editor-item.tsx index 4dca452..4321f16 100644 --- a/src/home/chat-window/prompt/prompt-editor-item.tsx +++ b/src/home/chat-window/prompt/prompt-editor-item.tsx @@ -26,7 +26,7 @@ export const PromptEditorItem: React.FC = ({promptProxy, messageProxy, in e.preventDefault() const newIndex = e.shiftKey || e.altKey || e.ctrlKey || e.metaKey ? index : index + 1 // eslint-disable-next-line valtio/state-snapshot-rule - promptProxy.messages.splice(newIndex, 0, {role: "user", content: ""}) + promptProxy.messages.splice(newIndex, 0, {role: "system", content: ""}) }, [index, promptProxy.messages]); return ( diff --git a/src/home/chat-window/prompt/prompt-list.tsx b/src/home/chat-window/prompt/prompt-list.tsx index d0985d4..610b177 100644 --- a/src/home/chat-window/prompt/prompt-list.tsx +++ b/src/home/chat-window/prompt/prompt-list.tsx @@ -1,4 +1,4 @@ -import React, {useEffect, useRef, useState} from "react" +import React, {useCallback, useEffect, useRef, useState} from "react" import {Chat} from "../../../state/app-state.ts" import {useSnapshot} from "valtio/react" import {newPrompt, Prompt, promptState} from "../../../state/promt-state.ts" @@ -45,6 +45,15 @@ export const PromptList: React.FC = ({chatProxy}) => { setFilteredPrompts(ps) }, [searchText, prompts, setFilteredPrompts]) + const scrollToTop = useCallback(() => { + const ref = containerRef.current + ref?.scrollTo({ + left: 0, + top: 0, + behavior: 'instant' + }) + }, []); + // scroll to selected item useEffect(() => { if (isPAPinning && !isSearching && containerRef.current) { @@ -64,16 +73,8 @@ export const PromptList: React.FC = ({chatProxy}) => { } }) } - return () => { - const ref = containerRef.current - ref?.scrollTo({ - left: 0, - top: 0, - behavior: 'instant' - }) - - } - }, [isSearching, isPAPinning,selectedRef,containerRef]) + return scrollToTop + }, [isSearching, isPAPinning, selectedRef, containerRef, scrollToTop]) return (
@@ -130,7 +131,10 @@ export const PromptList: React.FC = ({chatProxy}) => {
{ + newPrompt() + scrollToTop() + }} >
diff --git a/src/state/layout-state.ts b/src/state/layout-state.ts index dd952b7..3861e93 100644 --- a/src/state/layout-state.ts +++ b/src/state/layout-state.ts @@ -6,8 +6,6 @@ export type Layout = { isMessageListOverflow: boolean isMessageListAtBottom: boolean isPAPinning: boolean - PAButtonDistance: number - PAButtonWheelDeltaY: number } export const layoutState = proxy({ @@ -15,6 +13,4 @@ export const layoutState = proxy({ isMessageListOverflow: false, isMessageListAtBottom: false, isPAPinning: false, - PAButtonDistance: 1000, - PAButtonWheelDeltaY:0, }) \ No newline at end of file diff --git a/src/state/promt-state.ts b/src/state/promt-state.ts index 8ecddef..8b414f0 100644 --- a/src/state/promt-state.ts +++ b/src/state/promt-state.ts @@ -62,7 +62,7 @@ export const newPrompt = (): string => { const newP: Prompt = { id: randomHash16Char(), name: "New Prompt", - messages: [{role: "user", content: ""}], + messages: [{role: "system", content: ""}], preset: false } promptState.prompts.unshift(newP)