Skip to content

armgit / orca

Public Imported from GitHub
0

Orca is the place for working with a fleet of agents (e.g. Grok Bot, Claude Code). Run any coding agent with your own subscription. Available on desktop, mobile and remote runtime.

1.3 KB
Raw Blame
import { useEffect, useRef } from 'react'
import type { MobileSessionAttachmentsModel } from './use-mobile-session-attachments'

export function useMobileTerminalCreateRouteOwner(
  scope: Pick<
    MobileSessionAttachmentsModel,
    'hostId' | 'worktreeId' | 'client' | 'sessionTabsRef' | 'creatingTerminalRef' | 'setCreating'
  >
) {
  const { hostId, worktreeId, client, sessionTabsRef, creatingTerminalRef, setCreating } = scope
  const activationRef = useRef<symbol | null>(null)
  useEffect(() => {
    const activation = Symbol('session-create-route')
    activationRef.current = activation
    return () => {
      if (activationRef.current === activation) {
        activationRef.current = null
        creatingTerminalRef.current = null
        setCreating(false)
      }
    }
  }, [hostId, worktreeId, client, creatingTerminalRef, setCreating])

  return (sourceSessionId?: string) => {
    const activation = activationRef.current
    const isRouteCurrent = () => activation !== null && activationRef.current === activation
    const isCurrent = () =>
      isRouteCurrent() &&
      (!sourceSessionId ||
        sessionTabsRef.current.some(
          (tab) => tab.type === 'agent-session' && tab.sessionId === sourceSessionId
        ))
    return { isRouteCurrent, isCurrent }
  }
}