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