✨ feat(vscode): 会话 tab 可交接对话给同事
This commit is contained in:
1 parent
5ee8226167
commit
77037924ef
20 files changed
+938
-26
No files matched your search
@@ -8,6 +8,7 @@
|
||||
* 都把动作委托给主进程,列表由后续 `managed-sessions/show` 更新
|
||||
*/
|
||||
|
||||
import type { SessionHandoffPendingItem } from '../lib/messages'
|
||||
import type { ManagedSessionsData } from '../types'
|
||||
import { useCallback, useEffect, useState } from 'react'
|
||||
import { onMessage, postMessage } from '../lib/vscode'
|
||||
@@ -29,12 +30,20 @@ export interface UseManagedSessionsResult {
|
||||
importNamedSession: (sessionId: string, name: string) => void
|
||||
importableSessions: ImportableNamedSession[]
|
||||
importableLoading: boolean
|
||||
pendingHandoffs: SessionHandoffPendingItem[]
|
||||
sessionHandoffUsers: string[] | null
|
||||
startSessionHandoff: (sessionId: string) => void
|
||||
submitSessionHandoff: (sessionId: string, to: string) => void
|
||||
acceptSessionHandoff: (attachmentId: number) => void
|
||||
refreshSessionHandoffs: () => void
|
||||
}
|
||||
|
||||
export function useManagedSessions(): UseManagedSessionsResult {
|
||||
const [managedSessions, setManagedSessions] = useState<ManagedSessionsData>({ sessions: [] })
|
||||
const [importableSessions, setImportableSessions] = useState<ImportableNamedSession[]>([])
|
||||
const [importableLoading, setImportableLoading] = useState(false)
|
||||
const [pendingHandoffs, setPendingHandoffs] = useState<SessionHandoffPendingItem[]>([])
|
||||
const [sessionHandoffUsers, setSessionHandoffUsers] = useState<string[] | null>(null)
|
||||
|
||||
useEffect(() => {
|
||||
const cleanup = onMessage((msg) => {
|
||||
@@ -44,8 +53,13 @@ export function useManagedSessions(): UseManagedSessionsResult {
|
||||
setImportableSessions(msg.sessions)
|
||||
setImportableLoading(false)
|
||||
}
|
||||
if (msg.type === 'session-handoff/pending')
|
||||
setPendingHandoffs(msg.items)
|
||||
if (msg.type === 'session-handoff/users-result')
|
||||
setSessionHandoffUsers(msg.users)
|
||||
})
|
||||
postMessage({ type: 'managed-sessions/get' })
|
||||
postMessage({ type: 'session-handoff/refresh' })
|
||||
return cleanup
|
||||
}, [])
|
||||
|
||||
@@ -79,6 +93,23 @@ export function useManagedSessions(): UseManagedSessionsResult {
|
||||
postMessage({ type: 'managed-sessions/import', sessionId, name })
|
||||
}, [])
|
||||
|
||||
const startSessionHandoff = useCallback((_sessionId: string): void => {
|
||||
setSessionHandoffUsers(null)
|
||||
postMessage({ type: 'session-handoff/users' })
|
||||
}, [])
|
||||
|
||||
const submitSessionHandoff = useCallback((sessionId: string, to: string): void => {
|
||||
postMessage({ type: 'session-handoff/start', sessionId, to })
|
||||
}, [])
|
||||
|
||||
const acceptSessionHandoff = useCallback((attachmentId: number): void => {
|
||||
postMessage({ type: 'session-handoff/accept', attachmentId })
|
||||
}, [])
|
||||
|
||||
const refreshSessionHandoffs = useCallback((): void => {
|
||||
postMessage({ type: 'session-handoff/refresh' })
|
||||
}, [])
|
||||
|
||||
return {
|
||||
managedSessions,
|
||||
createManagedSession,
|
||||
@@ -90,5 +121,11 @@ export function useManagedSessions(): UseManagedSessionsResult {
|
||||
importNamedSession,
|
||||
importableSessions,
|
||||
importableLoading,
|
||||
pendingHandoffs,
|
||||
sessionHandoffUsers,
|
||||
startSessionHandoff,
|
||||
submitSessionHandoff,
|
||||
acceptSessionHandoff,
|
||||
refreshSessionHandoffs,
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user