Browse Source

tui: hide favorite keybind in model dialog when disconnected to prevent errors

Dax Raad 3 months ago
parent
commit
a0b689c140

+ 3 - 2
packages/opencode/src/cli/cmd/tui/component/dialog-model.tsx

@@ -21,7 +21,7 @@ export function DialogModel() {
 
 
   const options = createMemo(() => {
   const options = createMemo(() => {
     const query = ref()?.filter
     const query = ref()?.filter
-    const favorites = local.model.favorite()
+    const favorites = connected() ? local.model.favorite() : []
     const recents = local.model.recent()
     const recents = local.model.recent()
     const currentModel = local.model.current()
     const currentModel = local.model.current()
 
 
@@ -67,7 +67,7 @@ export function DialogModel() {
                   modelID: model.id,
                   modelID: model.id,
                 },
                 },
                 title: model.name ?? item.modelID,
                 title: model.name ?? item.modelID,
-                description: `${provider.name} ★`,
+                description: provider.name,
                 category: "Favorites",
                 category: "Favorites",
                 disabled: provider.id === "opencode" && model.id.includes("-nano"),
                 disabled: provider.id === "opencode" && model.id.includes("-nano"),
                 footer: model.cost?.input === 0 && provider.id === "opencode" ? "Free" : undefined,
                 footer: model.cost?.input === 0 && provider.id === "opencode" ? "Free" : undefined,
@@ -204,6 +204,7 @@ export function DialogModel() {
         {
         {
           keybind: Keybind.parse("ctrl+f")[0],
           keybind: Keybind.parse("ctrl+f")[0],
           title: "Favorite",
           title: "Favorite",
+          disabled: !connected(),
           onTrigger: (option) => {
           onTrigger: (option) => {
             local.model.toggleFavorite(option.value as { providerID: string; modelID: string })
             local.model.toggleFavorite(option.value as { providerID: string; modelID: string })
           },
           },

+ 3 - 1
packages/opencode/src/cli/cmd/tui/ui/dialog-select.tsx

@@ -21,6 +21,7 @@ export interface DialogSelectProps<T> {
   keybind?: {
   keybind?: {
     keybind: Keybind.Info
     keybind: Keybind.Info
     title: string
     title: string
+    disabled?: boolean
     onTrigger: (option: DialogSelectOption<T>) => void
     onTrigger: (option: DialogSelectOption<T>) => void
   }[]
   }[]
   current?: T
   current?: T
@@ -150,6 +151,7 @@ export function DialogSelect<T>(props: DialogSelectProps<T>) {
     }
     }
 
 
     for (const item of props.keybind ?? []) {
     for (const item of props.keybind ?? []) {
+      if (item.disabled) continue
       if (Keybind.match(item.keybind, keybind.parse(evt))) {
       if (Keybind.match(item.keybind, keybind.parse(evt))) {
         const s = selected()
         const s = selected()
         if (s) {
         if (s) {
@@ -254,7 +256,7 @@ export function DialogSelect<T>(props: DialogSelectProps<T>) {
         </For>
         </For>
       </scrollbox>
       </scrollbox>
       <box paddingRight={2} paddingLeft={4} flexDirection="row" paddingBottom={1} gap={2}>
       <box paddingRight={2} paddingLeft={4} flexDirection="row" paddingBottom={1} gap={2}>
-        <For each={props.keybind ?? []}>
+        <For each={(props.keybind ?? []).filter((x) => !x.disabled)}>
           {(item) => (
           {(item) => (
             <text>
             <text>
               <span style={{ fg: theme.text }}>
               <span style={{ fg: theme.text }}>