mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-19 00:03:13 +03:00
refactor(tui): break composer import cycle (#50637)
Co-authored-by: jlongster <17031+jlongster@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
Unverified
parent
8864eb507e
commit
18eeb3201d
@@ -0,0 +1,25 @@
|
||||
import { createContext, useContext } from "solid-js"
|
||||
|
||||
export interface ComposerHint {
|
||||
label: string
|
||||
shortcut: string
|
||||
}
|
||||
|
||||
export interface ComposerTab {
|
||||
id: string
|
||||
label: string
|
||||
hints?: () => ComposerHint[]
|
||||
onClose?: () => void
|
||||
}
|
||||
|
||||
export const ComposerContext = createContext<{
|
||||
register: (tab: ComposerTab) => () => void
|
||||
active: (id: string) => boolean
|
||||
close: () => void
|
||||
}>()
|
||||
|
||||
export function useComposerTab() {
|
||||
const ctx = useContext(ComposerContext)
|
||||
if (!ctx) throw new Error("useComposerTab must be used within a Composer")
|
||||
return ctx
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import { createEffect, createMemo, For, onCleanup, Show, useContext, createContext } from "solid-js"
|
||||
import { createEffect, createMemo, For, onCleanup, Show } from "solid-js"
|
||||
import { createStore } from "solid-js/store"
|
||||
import { TextAttributes } from "@opentui/core"
|
||||
import { useTheme } from "../../../context/theme"
|
||||
@@ -8,30 +8,9 @@ import { SubagentsTab } from "./subagents-tab"
|
||||
import { ShellTab } from "./shell-tab"
|
||||
import { TerminalsTab } from "./terminals-tab"
|
||||
import { useConfig } from "../../../config"
|
||||
import { ComposerContext, type ComposerTab } from "./context"
|
||||
|
||||
export interface ComposerHint {
|
||||
label: string
|
||||
shortcut: string
|
||||
}
|
||||
|
||||
interface Tab {
|
||||
id: string
|
||||
label: string
|
||||
hints?: () => ComposerHint[]
|
||||
onClose?: () => void
|
||||
}
|
||||
|
||||
const ComposerContext = createContext<{
|
||||
register: (tab: Tab) => () => void
|
||||
active: (id: string) => boolean
|
||||
close: () => void
|
||||
}>()
|
||||
|
||||
export function useComposerTab() {
|
||||
const ctx = useContext(ComposerContext)
|
||||
if (!ctx) throw new Error("useComposerTab must be used within a Composer")
|
||||
return ctx
|
||||
}
|
||||
export { useComposerTab, type ComposerHint } from "./context"
|
||||
|
||||
export type ComposerProps = {
|
||||
sessionID: string
|
||||
@@ -46,7 +25,7 @@ export function Composer(props: ComposerProps) {
|
||||
const config = useConfig().data
|
||||
|
||||
const [store, setStore] = createStore({
|
||||
tabs: {} as Record<string, Tab>,
|
||||
tabs: {} as Record<string, ComposerTab>,
|
||||
active: "",
|
||||
})
|
||||
|
||||
@@ -70,7 +49,7 @@ export function Composer(props: ComposerProps) {
|
||||
}
|
||||
|
||||
const ctx = {
|
||||
register(tab: Tab) {
|
||||
register(tab: ComposerTab) {
|
||||
setStore("tabs", tab.id, tab)
|
||||
if (!store.active) setStore("active", tab.id)
|
||||
return () => setStore("tabs", tab.id, undefined!)
|
||||
|
||||
@@ -5,7 +5,7 @@ import { useData } from "../../../context/data"
|
||||
import { useClient } from "../../../context/client"
|
||||
import { useTheme } from "../../../context/theme"
|
||||
import { Keymap } from "../../../context/keymap"
|
||||
import { useComposerTab } from "./index"
|
||||
import { useComposerTab } from "./context"
|
||||
import { useDialog } from "../../../ui/dialog"
|
||||
import { DialogShellOutput } from "../../../component/dialog-shell-output"
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ import { useClient } from "../../../context/client"
|
||||
import { useTheme } from "../../../context/theme"
|
||||
import { Locale } from "../../../util/locale"
|
||||
import { Keymap } from "../../../context/keymap"
|
||||
import { useComposerTab } from "./index"
|
||||
import { useComposerTab } from "./context"
|
||||
import { withTimestampedFallback } from "@opencode/util/session-title-fallback"
|
||||
import { sessionFamily } from "../../../util/session"
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import { Keymap } from "../../../context/keymap"
|
||||
import { useSessionTerminals } from "../../../context/session-terminals"
|
||||
import { useTheme } from "../../../context/theme"
|
||||
import { useToast } from "../../../ui/toast"
|
||||
import { useComposerTab } from "./index"
|
||||
import { useComposerTab } from "./context"
|
||||
|
||||
export function TerminalsTab(props: { sessionID: string; visibleTerminalID?: string }) {
|
||||
const composer = useComposerTab()
|
||||
|
||||
Reference in New Issue
Block a user