mirror of
https://github.com/aljazceru/opencode.git
synced 2025-12-23 10:44:21 +01:00
feat(sidebar): add expandable sections for sidebar (#4132)
Co-authored-by: GitHub Action <action@github.com>
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import { useSync } from "@tui/context/sync"
|
import { useSync } from "@tui/context/sync"
|
||||||
import { createMemo, For, Show, Switch, Match } from "solid-js"
|
import { createMemo, For, Show, Switch, Match, createSignal } from "solid-js"
|
||||||
import { useTheme } from "../../context/theme"
|
import { useTheme } from "../../context/theme"
|
||||||
import { Locale } from "@/util/locale"
|
import { Locale } from "@/util/locale"
|
||||||
import path from "path"
|
import path from "path"
|
||||||
@@ -13,6 +13,11 @@ export function Sidebar(props: { sessionID: string }) {
|
|||||||
const todo = createMemo(() => sync.data.todo[props.sessionID] ?? [])
|
const todo = createMemo(() => sync.data.todo[props.sessionID] ?? [])
|
||||||
const messages = createMemo(() => sync.data.message[props.sessionID] ?? [])
|
const messages = createMemo(() => sync.data.message[props.sessionID] ?? [])
|
||||||
|
|
||||||
|
const [mcpExpanded, setMcpExpanded] = createSignal(true)
|
||||||
|
const [diffExpanded, setDiffExpanded] = createSignal(true)
|
||||||
|
const [todoExpanded, setTodoExpanded] = createSignal(true)
|
||||||
|
const [lspExpanded, setLspExpanded] = createSignal(true)
|
||||||
|
|
||||||
const cost = createMemo(() => {
|
const cost = createMemo(() => {
|
||||||
const total = messages().reduce((sum, x) => sum + (x.role === "assistant" ? x.cost : 0), 0)
|
const total = messages().reduce((sum, x) => sum + (x.role === "assistant" ? x.cost : 0), 0)
|
||||||
return new Intl.NumberFormat("en-US", {
|
return new Intl.NumberFormat("en-US", {
|
||||||
@@ -55,9 +60,13 @@ export function Sidebar(props: { sessionID: string }) {
|
|||||||
</box>
|
</box>
|
||||||
<Show when={Object.keys(sync.data.mcp).length > 0}>
|
<Show when={Object.keys(sync.data.mcp).length > 0}>
|
||||||
<box>
|
<box>
|
||||||
|
<box flexDirection="row" gap={1} onMouseDown={() => setMcpExpanded(!mcpExpanded())}>
|
||||||
|
<text fg={theme.text}>{mcpExpanded() ? "▼" : "▶"}</text>
|
||||||
<text fg={theme.text}>
|
<text fg={theme.text}>
|
||||||
<b>MCP</b>
|
<b>MCP</b>
|
||||||
</text>
|
</text>
|
||||||
|
</box>
|
||||||
|
<Show when={mcpExpanded()}>
|
||||||
<For each={Object.entries(sync.data.mcp)}>
|
<For each={Object.entries(sync.data.mcp)}>
|
||||||
{([key, item]) => (
|
{([key, item]) => (
|
||||||
<box flexDirection="row" gap={1}>
|
<box flexDirection="row" gap={1}>
|
||||||
@@ -86,13 +95,18 @@ export function Sidebar(props: { sessionID: string }) {
|
|||||||
</box>
|
</box>
|
||||||
)}
|
)}
|
||||||
</For>
|
</For>
|
||||||
|
</Show>
|
||||||
</box>
|
</box>
|
||||||
</Show>
|
</Show>
|
||||||
<Show when={sync.data.lsp.length > 0}>
|
<Show when={sync.data.lsp.length > 0}>
|
||||||
<box>
|
<box>
|
||||||
|
<box flexDirection="row" gap={1} onMouseDown={() => setLspExpanded(!lspExpanded())}>
|
||||||
|
<text fg={theme.text}>{lspExpanded() ? "▼" : "▶"}</text>
|
||||||
<text fg={theme.text}>
|
<text fg={theme.text}>
|
||||||
<b>LSP</b>
|
<b>LSP</b>
|
||||||
</text>
|
</text>
|
||||||
|
</box>
|
||||||
|
<Show when={lspExpanded()}>
|
||||||
<For each={sync.data.lsp}>
|
<For each={sync.data.lsp}>
|
||||||
{(item) => (
|
{(item) => (
|
||||||
<box flexDirection="row" gap={1}>
|
<box flexDirection="row" gap={1}>
|
||||||
@@ -113,13 +127,18 @@ export function Sidebar(props: { sessionID: string }) {
|
|||||||
</box>
|
</box>
|
||||||
)}
|
)}
|
||||||
</For>
|
</For>
|
||||||
|
</Show>
|
||||||
</box>
|
</box>
|
||||||
</Show>
|
</Show>
|
||||||
<Show when={todo().length > 0}>
|
<Show when={todo().length > 0}>
|
||||||
<box>
|
<box>
|
||||||
|
<box flexDirection="row" gap={1} onMouseDown={() => setTodoExpanded(!todoExpanded())}>
|
||||||
|
<text fg={theme.text}>{todoExpanded() ? "▼" : "▶"}</text>
|
||||||
<text fg={theme.text}>
|
<text fg={theme.text}>
|
||||||
<b>Todo</b>
|
<b>Todo</b>
|
||||||
</text>
|
</text>
|
||||||
|
</box>
|
||||||
|
<Show when={todoExpanded()}>
|
||||||
<For each={todo()}>
|
<For each={todo()}>
|
||||||
{(todo) => (
|
{(todo) => (
|
||||||
<text style={{ fg: todo.status === "in_progress" ? theme.success : theme.textMuted }}>
|
<text style={{ fg: todo.status === "in_progress" ? theme.success : theme.textMuted }}>
|
||||||
@@ -127,13 +146,18 @@ export function Sidebar(props: { sessionID: string }) {
|
|||||||
</text>
|
</text>
|
||||||
)}
|
)}
|
||||||
</For>
|
</For>
|
||||||
|
</Show>
|
||||||
</box>
|
</box>
|
||||||
</Show>
|
</Show>
|
||||||
<Show when={diff().length > 0}>
|
<Show when={diff().length > 0}>
|
||||||
<box>
|
<box>
|
||||||
|
<box flexDirection="row" gap={1} onMouseDown={() => setDiffExpanded(!diffExpanded())}>
|
||||||
|
<text fg={theme.text}>{diffExpanded() ? "▼" : "▶"}</text>
|
||||||
<text fg={theme.text}>
|
<text fg={theme.text}>
|
||||||
<b>Modified Files</b>
|
<b>Modified Files</b>
|
||||||
</text>
|
</text>
|
||||||
|
</box>
|
||||||
|
<Show when={diffExpanded()}>
|
||||||
<For each={diff() || []}>
|
<For each={diff() || []}>
|
||||||
{(item) => {
|
{(item) => {
|
||||||
const file = createMemo(() => {
|
const file = createMemo(() => {
|
||||||
@@ -159,6 +183,7 @@ export function Sidebar(props: { sessionID: string }) {
|
|||||||
)
|
)
|
||||||
}}
|
}}
|
||||||
</For>
|
</For>
|
||||||
|
</Show>
|
||||||
</box>
|
</box>
|
||||||
</Show>
|
</Show>
|
||||||
</box>
|
</box>
|
||||||
|
|||||||
Reference in New Issue
Block a user