Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions packages/app/src/context/local.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -364,9 +364,7 @@ export const { use: useLocal, provider: LocalProvider } = createSimpleContext({
const fetch = async (path: string) => {
const relativePath = relative(path)
const parent = relativePath.split("/").slice(0, -1).join("/")
if (parent) {
await list(parent)
}
await list(parent)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: verify list("") handles empty path correctly for root-level files

Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/app/src/context/local.tsx
Line: 367:367

Comment:
**style:** verify `list("")` handles empty path correctly for root-level files

How can I resolve this? If you propose a fix, please make it concise.

}

const init = async (path: string) => {
Expand Down Expand Up @@ -397,8 +395,9 @@ export const { use: useLocal, provider: LocalProvider } = createSimpleContext({
}

const list = async (path: string) => {
const listPath = path ? path + "/" : ""
return sdk.client.file
.list({ path: path + "/" })
.list({ path: listPath })
.then((x) => {
setStore(
"node",
Expand Down
96 changes: 71 additions & 25 deletions packages/app/src/pages/session.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
createResource,
createMemo,
createEffect,
createSignal,
on,
createRenderEffect,
batch,
Expand All @@ -20,6 +21,7 @@ import { PromptInput } from "@/components/prompt-input"
import { DateTime } from "luxon"
import { FileIcon } from "@opencode-ai/ui/file-icon"
import { IconButton } from "@opencode-ai/ui/icon-button"
import { Button } from "@opencode-ai/ui/button"
import { Icon } from "@opencode-ai/ui/icon"
import { Tooltip } from "@opencode-ai/ui/tooltip"
import { DiffChanges } from "@opencode-ai/ui/diff-changes"
Expand Down Expand Up @@ -579,6 +581,71 @@ export default function Page() {
)
}

const FileTabContent = (props: { path: string; codeComponent: typeof codeComponent }): JSX.Element => {
const [file] = createResource(
() => props.path,
async (path) => local.file.node(path),
)
const content = createMemo(() => file()?.content)
const isImage = createMemo(
() => content()?.encoding === "base64" && content()?.mimeType?.startsWith("image/"),
)
const isSvg = createMemo(() => content()?.mimeType === "image/svg+xml")
const [showCode, setShowCode] = createSignal(false)
const decodedContent = createMemo(() => {
const c = content()
if (c?.encoding === "base64" && c.content) {
return atob(c.content)
}
return c?.content ?? ""
})
return (
<Switch>
<Match when={isImage() && !showCode() && file()}>
{(f) => (
<div class="flex flex-col h-full">
<Show when={isSvg()}>
<div class="flex justify-end p-2 border-b border-border-base">
<Button size="small" icon="code" onClick={() => setShowCode(true)}>
View code
</Button>
</div>
</Show>
<div class="flex items-center justify-center flex-1 p-4">
<img
src={`data:${f().content!.mimeType};base64,${f().content!.content}`}
alt={f().path}
class="max-w-full max-h-[80vh] object-contain"
/>
</div>
</div>
)}
</Match>
<Match when={content()?.content != null}>
<div class="flex flex-col h-full">
<Show when={isSvg()}>
<div class="flex justify-end p-2 border-b border-border-base">
<Button size="small" icon="photo" onClick={() => setShowCode(false)}>
View image
</Button>
</div>
</Show>
<Dynamic
component={props.codeComponent}
file={{
name: file()?.path ?? props.path,
contents: decodedContent(),
cacheKey: checksum(decodedContent()),
}}
overflow="scroll"
class="select-text pb-40"
/>
</div>
</Match>
</Switch>
)
}

const SortableTab = (props: {
tab: string
onTabClick: (tab: string) => void
Expand Down Expand Up @@ -874,33 +941,12 @@ export default function Page() {
</Show>
<For each={tabs().all()}>
{(tab) => {
const [file] = createResource(
() => tab,
async (tab) => {
if (tab.startsWith("file://")) {
return local.file.node(tab.replace("file://", ""))
}
return undefined
},
)
const path = tab.startsWith("file://") ? tab.replace("file://", "") : undefined
return (
<Tabs.Content value={tab} class="mt-3">
<Switch>
<Match when={file()}>
{(f) => (
<Dynamic
component={codeComponent}
file={{
name: f().path,
contents: f().content?.content ?? "",
cacheKey: checksum(f().content?.content ?? ""),
}}
overflow="scroll"
class="select-text pb-40"
/>
)}
</Match>
</Switch>
<Show when={path}>
<FileTabContent path={path!} codeComponent={codeComponent} />
</Show>
</Tabs.Content>
)
}}
Expand Down