feat(chat): add main layout focus modes
这个提交存在于:
父节点
e0b48c0a5c
当前提交
9f235a34e2
共有 3 个文件被更改,包括 750 次插入 和 663 次删除
51
src/App.tsx
51
src/App.tsx
|
|
@ -20,6 +20,9 @@ export function App() {
|
|||
const isBubbleView = view === "bubble";
|
||||
const [status, setStatus] = useState(initialStatus);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [chatLayout, setChatLayout] = useState<
|
||||
"single" | "focus-companion" | "focus-operations"
|
||||
>("single");
|
||||
|
||||
const refreshStatus = useCallback(async () => {
|
||||
try {
|
||||
|
|
@ -84,7 +87,53 @@ export function App() {
|
|||
打开快速聊天
|
||||
</button>
|
||||
</div>
|
||||
<ChatPanel />
|
||||
<section className="chat-workspace" aria-label="???????">
|
||||
<div className="chat-workspace-toolbar">
|
||||
<strong>????</strong>
|
||||
<button
|
||||
className={
|
||||
chatLayout === "single"
|
||||
? "button-secondary active"
|
||||
: "button-secondary"
|
||||
}
|
||||
type="button"
|
||||
onClick={() => setChatLayout("single")}
|
||||
>
|
||||
???
|
||||
</button>
|
||||
<button
|
||||
className={
|
||||
chatLayout === "focus-companion"
|
||||
? "button-secondary active"
|
||||
: "button-secondary"
|
||||
}
|
||||
type="button"
|
||||
onClick={() => setChatLayout("focus-companion")}
|
||||
>
|
||||
????
|
||||
</button>
|
||||
<button
|
||||
className={
|
||||
chatLayout === "focus-operations"
|
||||
? "button-secondary active"
|
||||
: "button-secondary"
|
||||
}
|
||||
type="button"
|
||||
onClick={() => setChatLayout("focus-operations")}
|
||||
>
|
||||
????
|
||||
</button>
|
||||
</div>
|
||||
<ChatPanel
|
||||
fixedSlot={
|
||||
chatLayout === "focus-companion"
|
||||
? "companion"
|
||||
: chatLayout === "focus-operations"
|
||||
? "operations"
|
||||
: undefined
|
||||
}
|
||||
/>
|
||||
</section>
|
||||
<ProfileManager />
|
||||
|
||||
<button type="button" onClick={() => void refreshStatus()}>
|
||||
|
|
|
|||
|
|
@ -26,10 +26,17 @@ function payloadString(
|
|||
return typeof value === "string" ? value : undefined;
|
||||
}
|
||||
|
||||
export function ChatPanel() {
|
||||
export interface ChatPanelProps {
|
||||
fixedSlot?: ChatSlot;
|
||||
}
|
||||
|
||||
export function ChatPanel({ fixedSlot }: ChatPanelProps) {
|
||||
const [status, setStatus] = useState(emptyStatus);
|
||||
const [messages, setMessages] = useState<ChatMessage[]>([]);
|
||||
const [activeSlot, setActiveSlot] = useState<ChatSlot>("companion");
|
||||
const [activeSlot, setActiveSlot] = useState<ChatSlot>(
|
||||
fixedSlot ?? "companion",
|
||||
);
|
||||
const selectedSlot = fixedSlot ?? activeSlot;
|
||||
const [draft, setDraft] = useState("");
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [unreadCounts, setUnreadCounts] = useState<Record<ChatSlot, number>>({
|
||||
|
|
@ -37,8 +44,8 @@ export function ChatPanel() {
|
|||
operations: 0,
|
||||
});
|
||||
const activeMessages = useMemo(
|
||||
() => messages.filter((item) => item.slot === activeSlot),
|
||||
[messages, activeSlot],
|
||||
() => messages.filter((item) => item.slot === selectedSlot),
|
||||
[messages, selectedSlot],
|
||||
);
|
||||
|
||||
const refresh = useCallback(async () => {
|
||||
|
|
@ -67,7 +74,7 @@ export function ChatPanel() {
|
|||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
const snapshot = status[activeSlot];
|
||||
const snapshot = status[selectedSlot];
|
||||
if (!snapshot.profileId || !snapshot.serverInstanceId) return;
|
||||
let cancelled = false;
|
||||
void invoke<unknown>("list_chat_sessions", {
|
||||
|
|
@ -81,7 +88,7 @@ export function ChatPanel() {
|
|||
const sessions = chatSessionSchema.array().parse(result);
|
||||
setUnreadCounts((current) => ({
|
||||
...current,
|
||||
[activeSlot]: sessions.reduce(
|
||||
[selectedSlot]: sessions.reduce(
|
||||
(total, session) => total + session.unreadCount,
|
||||
0,
|
||||
),
|
||||
|
|
@ -91,10 +98,10 @@ export function ChatPanel() {
|
|||
return () => {
|
||||
cancelled = true;
|
||||
};
|
||||
}, [activeSlot, status]);
|
||||
}, [selectedSlot, status]);
|
||||
|
||||
useEffect(() => {
|
||||
const snapshot = status[activeSlot];
|
||||
const snapshot = status[selectedSlot];
|
||||
if (
|
||||
!snapshot.profileId ||
|
||||
!snapshot.serverInstanceId ||
|
||||
|
|
@ -108,11 +115,11 @@ export function ChatPanel() {
|
|||
sessionId: snapshot.activeSessionId,
|
||||
},
|
||||
}).catch(() => undefined);
|
||||
setUnreadCounts((current) => ({ ...current, [activeSlot]: 0 }));
|
||||
}, [activeSlot, status]);
|
||||
setUnreadCounts((current) => ({ ...current, [selectedSlot]: 0 }));
|
||||
}, [selectedSlot, status]);
|
||||
|
||||
useEffect(() => {
|
||||
const snapshot = status[activeSlot];
|
||||
const snapshot = status[selectedSlot];
|
||||
if (
|
||||
!snapshot.profileId ||
|
||||
!snapshot.serverInstanceId ||
|
||||
|
|
@ -132,7 +139,9 @@ export function ChatPanel() {
|
|||
if (cancelled) return;
|
||||
const records = storedChatMessageSchema.array().parse(result);
|
||||
setMessages((current) => {
|
||||
const otherSlots = current.filter((item) => item.slot !== activeSlot);
|
||||
const otherSlots = current.filter(
|
||||
(item) => item.slot !== selectedSlot,
|
||||
);
|
||||
const restored = records.map((record) => ({
|
||||
id: record.messageId,
|
||||
slot: record.slot,
|
||||
|
|
@ -148,7 +157,7 @@ export function ChatPanel() {
|
|||
return () => {
|
||||
cancelled = true;
|
||||
};
|
||||
}, [activeSlot, status]);
|
||||
}, [selectedSlot, status]);
|
||||
|
||||
useEffect(() => {
|
||||
let timer: number | undefined;
|
||||
|
|
@ -170,11 +179,16 @@ export function ChatPanel() {
|
|||
const id = "local-" + Date.now();
|
||||
setDraft("");
|
||||
setMessages((current) =>
|
||||
current.concat({ id, slot: activeSlot, role: "user", content: message }),
|
||||
current.concat({
|
||||
id,
|
||||
slot: selectedSlot,
|
||||
role: "user",
|
||||
content: message,
|
||||
}),
|
||||
);
|
||||
try {
|
||||
await invoke("send_connection_slot_message", {
|
||||
request: { slot: activeSlot, message },
|
||||
request: { slot: selectedSlot, message },
|
||||
});
|
||||
setError(null);
|
||||
} catch (reason) {
|
||||
|
|
@ -197,17 +211,18 @@ export function ChatPanel() {
|
|||
主页面、快速聊天和气泡共享同一套消息状态。
|
||||
</p>
|
||||
</div>
|
||||
<div className="chat-slot-tabs" role="tablist" aria-label="聊天槽位">
|
||||
<div className="chat-slot-tabs" role="tablist" aria-label="????">
|
||||
{(["companion", "operations"] as const).map((slot) => (
|
||||
<button
|
||||
className={activeSlot === slot ? "chat-slot active" : "chat-slot"}
|
||||
key={slot}
|
||||
disabled={Boolean(fixedSlot)}
|
||||
onClick={() => setActiveSlot(slot)}
|
||||
role="tab"
|
||||
aria-selected={activeSlot === slot}
|
||||
type="button"
|
||||
>
|
||||
{slot === "companion" ? "陪伴" : "运维"}
|
||||
{slot === "companion" ? "??" : "??"}
|
||||
{unreadCounts[slot] > 0 ? (
|
||||
<strong>{unreadCounts[slot]}</strong>
|
||||
) : null}
|
||||
|
|
@ -217,9 +232,9 @@ export function ChatPanel() {
|
|||
</div>
|
||||
</div>
|
||||
<div className="chat-runtime-strip">
|
||||
<span>Profile:{status[activeSlot].profileId ?? "未连接"}</span>
|
||||
<span>Session:{status[activeSlot].activeSessionId ?? "未建立"}</span>
|
||||
<span>状态:{connectionStateLabel(status[activeSlot].state)}</span>
|
||||
<span>Profile:{status[selectedSlot].profileId ?? "未连接"}</span>
|
||||
<span>Session:{status[selectedSlot].activeSessionId ?? "未建立"}</span>
|
||||
<span>状态:{connectionStateLabel(status[selectedSlot].state)}</span>
|
||||
</div>
|
||||
<div className="chat-message-list" aria-live="polite">
|
||||
{activeMessages.length === 0 ? (
|
||||
|
|
|
|||
1307
src/styles.css
1307
src/styles.css
文件差异内容过多而无法显示
加载差异
正在加载…
添加表格
在新工单中引用