import { useEffect , useState } from 'react' ; import { useAttempt } from 'shared/hooks' ; import { Session } from 'teleport/services/ssh' ; import Ctx from 'teleport/teleportContext' ; export default function useSessions ( ctx , clusterId ) { const [ sessions , setSessions ] = useState < Session [ ] > ( [ ] ) ; const [ attempt , attemptActions ] = useAttempt ( { isProcessing : true } ) ; function onRefresh ( ) { return ctx . sshService . fetchSessions ( clusterId ) . then ( setSessions ) ; } useEffect ( ( ) => { attemptActions . do ( ( ) => onRefresh ( ) ) ; } , [ clusterId ] ) ; return { attempt , sessions , onRefresh , } ; }