fix: backgroud-image & stop chat (#21)

This commit is contained in:
BiggerRain
2024-11-27 08:54:18 +08:00
committed by GitHub
parent 94b6255969
commit e50c595195
6 changed files with 23 additions and 16 deletions

View File

@@ -30,7 +30,7 @@ const ChatAI = forwardRef<ChatAIRef, ChatAIProps>(
init: init, init: init,
})); }));
const { curChatEnd, setCurChatEnd } = useChatStore(); const { curChatEnd, setCurChatEnd, stopChat } = useChatStore();
const [activeChat, setActiveChat] = useState<Chat>(); const [activeChat, setActiveChat] = useState<Chat>();
const [isTyping, setIsTyping] = useState(false); const [isTyping, setIsTyping] = useState(false);
@@ -69,7 +69,7 @@ const ChatAI = forwardRef<ChatAIRef, ChatAIProps>(
// websocket // websocket
useEffect(() => { useEffect(() => {
if (messages.length === 0 || !activeChat?._id) return; if (messages.length === 0 || !activeChat?._id || stopChat) return;
const simulateAssistantResponse = () => { const simulateAssistantResponse = () => {
console.log("messages", messages); console.log("messages", messages);
@@ -94,7 +94,7 @@ const ChatAI = forwardRef<ChatAIRef, ChatAIProps>(
if (curChatEnd) { if (curChatEnd) {
simulateAssistantResponse(); simulateAssistantResponse();
} }
}, [messages, curChatEnd]); }, [messages, curChatEnd, stopChat]);
const scrollToBottom = () => { const scrollToBottom = () => {
messagesEndRef.current?.scrollIntoView({ messagesEndRef.current?.scrollIntoView({

View File

@@ -40,7 +40,7 @@ export function Sidebar({
New Chat New Chat
</button> </button>
</div> </div>
<div className="flex-1 overflow-y-auto px-3 pb-3 space-y-1"> <div className="flex-1 overflow-y-auto px-3 pb-3 space-y-1 custom-scrollbar">
{chats.map((chat) => ( {chats.map((chat) => (
<div <div
key={chat._id} key={chat._id}

View File

@@ -33,10 +33,11 @@ export default function ChatInput({
}: ChatInputProps) { }: ChatInputProps) {
const inputRef = useRef<HTMLInputElement>(null); const inputRef = useRef<HTMLInputElement>(null);
const { curChatEnd, setCurChatEnd } = useChatStore(); const { stopChat, setStopChat } = useChatStore();
const handleSubmit = () => { const handleSubmit = () => {
if (inputValue.trim() && !disabled) { if (inputValue.trim() && !disabled) {
setStopChat(false);
onSend(inputValue.trim()); onSend(inputValue.trim());
} }
}; };
@@ -89,7 +90,7 @@ export default function ChatInput({
<Mic className="w-4 h-4 text-[#999] dark:text-[#999]" /> <Mic className="w-4 h-4 text-[#999] dark:text-[#999]" />
</button> </button>
) : null} ) : null}
{isChatMode && curChatEnd ? ( {isChatMode && stopChat ? (
<button <button
className={`ml-1 p-1 ${ className={`ml-1 p-1 ${
inputValue ? "bg-[#0072FF]" : "bg-[#E4E5F0]" inputValue ? "bg-[#0072FF]" : "bg-[#E4E5F0]"
@@ -100,11 +101,11 @@ export default function ChatInput({
<Send className="w-4 h-4 text-white hover:text-[#999]" /> <Send className="w-4 h-4 text-white hover:text-[#999]" />
</button> </button>
) : null} ) : null}
{isChatMode && !curChatEnd ? ( {isChatMode && !stopChat ? (
<button <button
className={`ml-1 p-1 bg-[#0072FF] rounded-full transition-colors`} className={`ml-1 p-1 bg-[#0072FF] rounded-full transition-colors`}
type="submit" type="submit"
onClick={() => setCurChatEnd(true)} onClick={() => setStopChat(true)}
> >
<CircleStop className="w-4 h-4 text-white hover:text-[#999]" /> <CircleStop className="w-4 h-4 text-white hover:text-[#999]" />
</button> </button>
@@ -146,6 +147,7 @@ export default function ChatInput({
<ChatSwitch <ChatSwitch
isChatMode={isChatMode} isChatMode={isChatMode}
onChange={(value) => { onChange={(value) => {
setStopChat(!value);
changeMode(value); changeMode(value);
}} }}
/> />

View File

@@ -88,7 +88,7 @@ export default function SearchChat() {
/> />
</div> </div>
{isChatMode ? null : ( {isChatMode || !input ? null : (
<Search <Search
key="Search" key="Search"
input={input} input={input}

View File

@@ -7,6 +7,8 @@ import {
export type IChatStore = { export type IChatStore = {
curChatEnd: boolean; curChatEnd: boolean;
setCurChatEnd: (value: boolean) => void; setCurChatEnd: (value: boolean) => void;
stopChat: boolean;
setStopChat: (value: boolean) => void;
}; };
export const useChatStore = create<IChatStore>()( export const useChatStore = create<IChatStore>()(
@@ -14,6 +16,8 @@ export const useChatStore = create<IChatStore>()(
(set) => ({ (set) => ({
curChatEnd: true, curChatEnd: true,
setCurChatEnd: (value: boolean) => set(() => ({ curChatEnd: value })), setCurChatEnd: (value: boolean) => set(() => ({ curChatEnd: value })),
stopChat: false,
setStopChat: (value: boolean) => set(() => ({ stopChat: value })),
}), }),
{ {
name: "chat-state", name: "chat-state",

View File

@@ -11,12 +11,12 @@ export default {
separator: "rgb(var(--color-separator) / <alpha-value>)", separator: "rgb(var(--color-separator) / <alpha-value>)",
}, },
backgroundImage: { backgroundImage: {
chat_bg_light: "url('/chat_bg_light.png')", chat_bg_light: "url('/public/chat_bg_light.png')",
chat_bg_dark: "url('/chat_bg_dark.png')", chat_bg_dark: "url('/public/chat_bg_dark.png')",
search_bg_light: "url('/search_bg_light.png')", search_bg_light: "url('/public/search_bg_light.png')",
search_bg_dark: "url('/search_bg_dark.png')", search_bg_dark: "url('/public/search_bg_dark.png')",
inputbox_bg_light: "url('/inputbox_bg_light.png')", inputbox_bg_light: "url('/public/inputbox_bg_light.png')",
inputbox_bg_dark: "url('/inputbox_bg_dark.png')", inputbox_bg_dark: "url('/public/inputbox_bg_dark.png')",
}, },
textColor: { textColor: {
primary: "rgb(var(--color-foreground) / <alpha-value>)", primary: "rgb(var(--color-foreground) / <alpha-value>)",
@@ -31,7 +31,8 @@ export default {
}, },
}, },
boxShadow: { boxShadow: {
'window-custom': '0 1px 5px 0 rgba(0, 0, 0, 0.15), 0 1px 5px -1px rgba(0, 0, 0, 0.1), 0 2px 5px rgba(0, 0, 0, 0.1)', "window-custom":
"0 1px 5px 0 rgba(0, 0, 0, 0.15), 0 1px 5px -1px rgba(0, 0, 0, 0.1), 0 2px 5px rgba(0, 0, 0, 0.1)",
}, },
}, },
}, },