Root cause: TerminalInstance.onMounted() called sessions.removeSession() on the pending session, dropping sessions.length to 0. SessionContainer's v-if="hasSessions" went false, unmounting the entire terminal UI before the WebSocket could establish and add the real session. Fix: Added replaceSession() to session store. TerminalInstance no longer removes the pending session — instead passes its ID to connectToHost(), which swaps it in-place when the backend responds with the real session ID. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
46 lines
1.2 KiB
TypeScript
46 lines
1.2 KiB
TypeScript
import { defineStore } from 'pinia'
|
|
|
|
interface Session {
|
|
id: string // uuid from backend
|
|
hostId: number
|
|
hostName: string
|
|
protocol: 'ssh' | 'rdp'
|
|
color: string | null
|
|
active: boolean
|
|
}
|
|
|
|
export const useSessionStore = defineStore('sessions', {
|
|
state: () => ({
|
|
sessions: [] as Session[],
|
|
activeSessionId: null as string | null,
|
|
}),
|
|
getters: {
|
|
activeSession: (state) => state.sessions.find(s => s.id === state.activeSessionId),
|
|
hasSessions: (state) => state.sessions.length > 0,
|
|
},
|
|
actions: {
|
|
addSession(session: Session) {
|
|
this.sessions.push(session)
|
|
this.activeSessionId = session.id
|
|
},
|
|
removeSession(id: string) {
|
|
this.sessions = this.sessions.filter(s => s.id !== id)
|
|
if (this.activeSessionId === id) {
|
|
this.activeSessionId = this.sessions.length ? this.sessions[this.sessions.length - 1].id : null
|
|
}
|
|
},
|
|
replaceSession(oldId: string, newSession: Session) {
|
|
const idx = this.sessions.findIndex(s => s.id === oldId)
|
|
if (idx !== -1) {
|
|
this.sessions[idx] = newSession
|
|
} else {
|
|
this.sessions.push(newSession)
|
|
}
|
|
this.activeSessionId = newSession.id
|
|
},
|
|
setActive(id: string) {
|
|
this.activeSessionId = id
|
|
},
|
|
},
|
|
})
|