wraith/frontend/stores/session.store.ts
Vantz Stockwell c8868258d5 feat: Phase 2 — SSH terminal + SFTP sidebar in browser
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-12 17:21:11 -04:00

37 lines
978 B
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
}
},
setActive(id: string) {
this.activeSessionId = id
},
},
})