feat(TUI): don't show /share hint if sharing is disabled (#3835)

This commit is contained in:
Timo Clasen
2025-11-03 22:30:55 +01:00
committed by GitHub
parent 9c82f1f5e9
commit 8e1010dc3f

View File

@@ -1,17 +1,38 @@
import { createMemo, Match, Show, Switch } from "solid-js" import { type Accessor, createMemo, Match, Show, Switch } from "solid-js"
import { useRouteData } from "@tui/context/route" import { useRouteData } from "@tui/context/route"
import { useSync } from "@tui/context/sync" import { useSync } from "@tui/context/sync"
import { pipe, sumBy } from "remeda" import { pipe, sumBy } from "remeda"
import { useTheme } from "@tui/context/theme" import { useTheme } from "@tui/context/theme"
import { SplitBorder } from "@tui/component/border" import { SplitBorder } from "@tui/component/border"
import type { AssistantMessage } from "@opencode-ai/sdk" import type { AssistantMessage, Session } from "@opencode-ai/sdk"
const Title = (props: { session: Accessor<Session> }) => {
const { theme } = useTheme()
return (
<text fg={theme.text}>
<span style={{ bold: true, fg: theme.accent }}>#</span>{" "}
<span style={{ bold: true }}>{props.session().title}</span>
</text>
)
}
const ContextInfo = (props: { context: Accessor<string | undefined>; cost: Accessor<string> }) => {
const { theme } = useTheme()
return (
<Show when={props.context()}>
<text fg={theme.textMuted} wrapMode="none" flexShrink={0}>
{props.context()} ({props.cost()})
</text>
</Show>
)
}
export function Header() { export function Header() {
const route = useRouteData("session") const route = useRouteData("session")
const sync = useSync() const sync = useSync()
const { theme } = useTheme()
const session = createMemo(() => sync.session.get(route.sessionID)!) const session = createMemo(() => sync.session.get(route.sessionID)!)
const messages = createMemo(() => sync.data.message[route.sessionID] ?? []) const messages = createMemo(() => sync.data.message[route.sessionID] ?? [])
const shareEnabled = createMemo(() => sync.data.config.share !== "disabled")
const cost = createMemo(() => { const cost = createMemo(() => {
const total = pipe( const total = pipe(
@@ -43,6 +64,8 @@ export function Header() {
return result return result
}) })
const { theme } = useTheme()
return ( return (
<box <box
paddingLeft={1} paddingLeft={1}
@@ -51,31 +74,34 @@ export function Header() {
borderColor={theme.backgroundElement} borderColor={theme.backgroundElement}
flexShrink={0} flexShrink={0}
> >
<text fg={theme.text}> <Show
<span style={{ bold: true, fg: theme.accent }}>#</span>{" "} when={shareEnabled()}
<span style={{ bold: true }}>{session().title}</span> fallback={
</text> <box flexDirection="row" justifyContent="space-between" gap={1}>
<box flexDirection="row" justifyContent="space-between" gap={1}> <Title session={session} />
<box flexGrow={1} flexShrink={1}> <ContextInfo context={context} cost={cost} />
<Switch> </box>
<Match when={session().share?.url}> }
<text fg={theme.textMuted} wrapMode="word"> >
{session().share!.url} <Title session={session} />
</text> <box flexDirection="row" justifyContent="space-between" gap={1}>
</Match> <box flexGrow={1} flexShrink={1}>
<Match when={true}> <Switch>
<text fg={theme.text} wrapMode="word"> <Match when={session().share?.url}>
/share <span style={{ fg: theme.textMuted }}>to create a shareable link</span> <text fg={theme.textMuted} wrapMode="word">
</text> {session().share!.url}
</Match> </text>
</Switch> </Match>
<Match when={true}>
<text fg={theme.text} wrapMode="word">
/share <span style={{ fg: theme.textMuted }}>to create a shareable link</span>
</text>
</Match>
</Switch>
</box>
<ContextInfo context={context} cost={cost} />
</box> </box>
<Show when={context()}> </Show>
<text fg={theme.textMuted} wrapMode="none" flexShrink={0}>
{context()} ({cost()})
</text>
</Show>
</box>
</box> </box>
) )
} }