Skip to content

Commit 742cf10

Browse files
committed
fix(desktop): removed projects
1 parent 7664453 commit 742cf10

4 files changed

Lines changed: 16 additions & 11 deletions

File tree

‎packages/desktop/src/context/layout.tsx‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,21 +61,22 @@ export const { use: useLayout, provider: LayoutProvider } = createSimpleContext(
6161

6262
function enrich(project: { worktree: string; expanded: boolean }) {
6363
const metadata = globalSync.data.project.find((x) => x.worktree === project.worktree)
64-
if (!metadata) return []
6564
return [
6665
{
6766
...project,
68-
...metadata,
67+
...(metadata ?? {}),
6968
},
7069
]
7170
}
7271

73-
function colorize(project: Project & { expanded: boolean }) {
72+
function colorize(project: Partial<Project> & { worktree: string; expanded: boolean }) {
7473
if (project.icon?.color) return project
7574
const color = pickAvailableColor()
7675
usedColors.add(color)
7776
project.icon = { ...project.icon, color }
78-
globalSdk.client.project.update({ projectID: project.id, icon: { color } })
77+
if (project.id) {
78+
globalSdk.client.project.update({ projectID: project.id, icon: { color } })
79+
}
7980
return project
8081
}
8182

@@ -95,7 +96,9 @@ export const { use: useLayout, provider: LayoutProvider } = createSimpleContext(
9596
projects: {
9697
list,
9798
open(directory: string) {
98-
if (store.projects.find((x) => x.worktree === directory)) return
99+
if (store.projects.find((x) => x.worktree === directory)) {
100+
return
101+
}
99102
globalSync.project.loadSessions(directory)
100103
setStore("projects", (x) => [{ worktree: directory, expanded: true }, ...x])
101104
},

‎packages/desktop/src/context/local.tsx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,7 @@ export const { use: useLocal, provider: LocalProvider } = createSimpleContext({
337337
const load = async (path: string) => {
338338
const relativePath = relative(path)
339339
await sdk.client.file.read({ path: relativePath }).then((x) => {
340+
if (!store.node[relativePath]) return
340341
setStore(
341342
"node",
342343
relativePath,
@@ -425,7 +426,7 @@ export const { use: useLocal, provider: LocalProvider } = createSimpleContext({
425426
init,
426427
expand(path: string) {
427428
setStore("node", path, "expanded", true)
428-
if (store.node[path].loaded) return
429+
if (store.node[path]?.loaded) return
429430
setStore("node", path, "loaded", true)
430431
list(path)
431432
},

‎packages/desktop/src/pages/layout.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ export default function Layout(props: ParentProps) {
517517
)
518518
}
519519

520-
const SortableProject = (props: { project: Project & { expanded: boolean } }): JSX.Element => {
520+
const SortableProject = (props: { project: Project & { worktree: string; expanded: boolean } }): JSX.Element => {
521521
const sortable = createSortable(props.project.worktree)
522522
const slug = createMemo(() => base64Encode(props.project.worktree))
523523
const name = createMemo(() => getFilename(props.project.worktree))

‎packages/opencode/src/file/index.ts‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { BusEvent } from "@/bus/bus-event"
2-
import { Bus } from "@/bus"
32
import z from "zod"
43
import { $ } from "bun"
54
import type { BunFile } from "bun"
@@ -290,9 +289,11 @@ export namespace File {
290289
}
291290
const resolved = dir ? path.join(Instance.directory, dir) : Instance.directory
292291
const nodes: Node[] = []
293-
for (const entry of await fs.promises.readdir(resolved, {
294-
withFileTypes: true,
295-
})) {
292+
for (const entry of await fs.promises
293+
.readdir(resolved, {
294+
withFileTypes: true,
295+
})
296+
.catch(() => [])) {
296297
if (exclude.includes(entry.name)) continue
297298
const fullPath = path.join(resolved, entry.name)
298299
const relativePath = path.relative(Instance.directory, fullPath)

0 commit comments

Comments
 (0)