refactor: optimize chat window size in compact mode (#964)

This commit is contained in:
ayangweb
2025-11-04 20:03:53 +08:00
committed by GitHub
parent b5d3ce9910
commit 50518b6c21
4 changed files with 36 additions and 12 deletions

View File

@@ -120,6 +120,12 @@ const ChatAI = memo(
activeChatProp && setActiveChat(activeChatProp); activeChatProp && setActiveChat(activeChatProp);
}, [activeChatProp]); }, [activeChatProp]);
useEffect(() => {
const { setHasActiveChat } = useChatStore.getState();
setHasActiveChat(Boolean(activeChat));
}, [activeChat]);
useEffect(() => { useEffect(() => {
if (!isTauri) return; if (!isTauri) return;
@@ -198,7 +204,7 @@ const ChatAI = memo(
isMCPActive, isMCPActive,
changeInput, changeInput,
showChatHistory, showChatHistory,
getChatHistoryChatPage, getChatHistoryChatPage
); );
const { dealMsg } = useMessageHandler( const { dealMsg } = useMessageHandler(

View File

@@ -130,6 +130,12 @@ export default function ChatInput({
// console.log("handleSubmit", trimmedValue, disabled); // console.log("handleSubmit", trimmedValue, disabled);
if ((trimmedValue || !isEmpty(uploadAttachments)) && !disabled) { if ((trimmedValue || !isEmpty(uploadAttachments)) && !disabled) {
const { setHasActiveChat } = useChatStore.getState();
if (isChatMode) {
setHasActiveChat(true);
}
changeInput(""); changeInput("");
onSend({ onSend({
message: trimmedValue, message: trimmedValue,

View File

@@ -35,6 +35,8 @@ import {
} from "@/utils"; } from "@/utils";
import { useTauriFocus } from "@/hooks/useTauriFocus"; import { useTauriFocus } from "@/hooks/useTauriFocus";
import { POPOVER_PANEL_SELECTOR } from "@/constants"; import { POPOVER_PANEL_SELECTOR } from "@/constants";
import { useChatStore } from "@/stores/chatStore";
import { debounce } from "lodash-es";
interface SearchChatProps { interface SearchChatProps {
isTauri?: boolean; isTauri?: boolean;
@@ -109,12 +111,18 @@ function SearchChat({
const updateAppDialog = document.querySelector("#update-app-dialog"); const updateAppDialog = document.querySelector("#update-app-dialog");
const popoverPanelEl = document.querySelector(POPOVER_PANEL_SELECTOR); const popoverPanelEl = document.querySelector(POPOVER_PANEL_SELECTOR);
const { hasActiveChat } = useChatStore.getState();
if ( if (
!updateAppDialog && updateAppDialog ||
!canNavigateBack() && canNavigateBack() ||
!inputRef.current && inputRef.current ||
!popoverPanelEl popoverPanelEl ||
(isChatModeRef.current && hasActiveChat)
) { ) {
setHideMiddleBorder(false);
setSuppressErrors(false);
} else {
const { windowMode } = useAppearanceStore.getState(); const { windowMode } = useAppearanceStore.getState();
if (windowMode === "compact") { if (windowMode === "compact") {
@@ -123,15 +131,14 @@ function SearchChat({
setHideMiddleBorder(height < 590); setHideMiddleBorder(height < 590);
setSuppressErrors(height < 590); setSuppressErrors(height < 590);
} else {
setHideMiddleBorder(false);
setSuppressErrors(false);
} }
platformAdapter.setWindowSize(width, height); platformAdapter.setWindowSize(width, height);
}, []); }, []);
useMutationObserver(setWindowSize, document.body, { const debouncedSetWindowSize = debounce(setWindowSize, 50);
useMutationObserver(debouncedSetWindowSize, document.body, {
subtree: true, subtree: true,
childList: true, childList: true,
}); });
@@ -140,11 +147,11 @@ function SearchChat({
inputRef.current = input; inputRef.current = input;
isChatModeRef.current = isChatMode; isChatModeRef.current = isChatMode;
setWindowSize(); debouncedSetWindowSize();
}, [input, isChatMode]); }, [input, isChatMode]);
useTauriFocus({ useTauriFocus({
onFocus: setWindowSize, onFocus: debouncedSetWindowSize,
}); });
useEffect(() => { useEffect(() => {

View File

@@ -33,6 +33,8 @@ export type IChatStore = {
setUploadAttachments: (value: UploadAttachments[]) => void; setUploadAttachments: (value: UploadAttachments[]) => void;
synthesizeItem?: SynthesizeItem; synthesizeItem?: SynthesizeItem;
setSynthesizeItem: (synthesizeItem?: SynthesizeItem) => void; setSynthesizeItem: (synthesizeItem?: SynthesizeItem) => void;
hasActiveChat?: boolean;
setHasActiveChat: (hasActiveChat?: boolean) => void;
}; };
export const useChatStore = create<IChatStore>()( export const useChatStore = create<IChatStore>()(
@@ -53,9 +55,12 @@ export const useChatStore = create<IChatStore>()(
setUploadAttachments: (uploadAttachments: UploadAttachments[]) => { setUploadAttachments: (uploadAttachments: UploadAttachments[]) => {
return set(() => ({ uploadAttachments })); return set(() => ({ uploadAttachments }));
}, },
setSynthesizeItem(synthesizeItem?: SynthesizeItem) { setSynthesizeItem: (synthesizeItem?: SynthesizeItem) => {
return set(() => ({ synthesizeItem })); return set(() => ({ synthesizeItem }));
}, },
setHasActiveChat(hasActiveChat) {
return set(() => ({ hasActiveChat }));
},
}), }),
{ {
name: "chat-state", name: "chat-state",