Skip to content

Commit 7957fe7

Browse files
committed
refactor: client for server side sandbox handling
1 parent 78d5a46 commit 7957fe7

5 files changed

Lines changed: 36 additions & 36 deletions

File tree

src/app/dashboard/[teamIdOrSlug]/sandboxes/[sandboxId]/inspect/page.tsx

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,38 @@
1-
'use client'
2-
3-
import { LOCAL_STORAGE_KEYS } from '@/configs/keys'
41
import { SandboxInspectProvider } from '@/features/dashboard/sandbox/inspect/context'
52
import SandboxInspectFilesystem from '@/features/dashboard/sandbox/inspect/filesystem'
63
import SandboxInspectHeader from '@/features/dashboard/sandbox/inspect/header'
7-
import { useLocalStorage } from 'usehooks-ts'
4+
import { resolveTeamIdInServerComponent } from '@/lib/utils/server'
5+
import { getSandboxRoot } from '@/server/sandboxes/get-sandbox-root'
6+
import { notFound } from 'next/navigation'
87

9-
export default function SandboxInspectPage() {
10-
const [rootPath, setRootPath] = useLocalStorage(
11-
LOCAL_STORAGE_KEYS.SANDBOX_INSPECT_ROOT_PATH,
12-
'/'
13-
)
8+
export default async function SandboxInspectPage({
9+
params,
10+
}: {
11+
params: Promise<{ teamIdOrSlug: string; sandboxId: string }>
12+
}) {
13+
const rootPath = '/home/user'
14+
15+
const { teamIdOrSlug, sandboxId } = await params
16+
17+
const teamId = await resolveTeamIdInServerComponent(teamIdOrSlug)
18+
19+
const res = await getSandboxRoot({
20+
teamId,
21+
sandboxId,
22+
rootPath,
23+
})
24+
25+
if (!res?.data) {
26+
throw notFound()
27+
}
1428

1529
return (
16-
<SandboxInspectProvider rootPath={rootPath}>
17-
<SandboxInspectHeader
18-
rootPath={rootPath}
19-
onRootPathChange={setRootPath}
20-
/>
30+
<SandboxInspectProvider
31+
teamId={teamId}
32+
rootPath={rootPath}
33+
seedEntries={res.data.entries}
34+
>
35+
<SandboxInspectHeader />
2136
<SandboxInspectFilesystem />
2237
</SandboxInspectProvider>
2338
)

src/features/dashboard/sandbox/inspect/dir.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import { FileType } from 'e2b'
21
import { FilesystemNode } from './filesystem/types'
3-
import { ChevronRight, FolderOpenIcon } from 'lucide-react'
2+
import { ChevronRight } from 'lucide-react'
43
import SandboxInspectNode from './node'
54
import { useDirectory } from './hooks/use-directory'
65
import { cn } from '@/lib/utils'
@@ -10,7 +9,7 @@ import { motion } from 'motion/react'
109

1110
interface SandboxInspectDirProps {
1211
dir: FilesystemNode & {
13-
type: FileType.DIR
12+
type: 'dir'
1413
}
1514
}
1615

src/features/dashboard/sandbox/inspect/file.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { DataTableRow } from '@/ui/data-table'
44

55
interface SandboxInspectFileProps {
66
file: FilesystemNode & {
7-
type: FileType.FILE
7+
type: 'file'
88
}
99
}
1010

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,9 @@
11
import { Input } from '@/ui/primitives/input'
22

3-
interface SandboxInspectHeaderProps {
4-
rootPath: string
5-
onRootPathChange: (path: string) => void
6-
}
7-
8-
export default function SandboxInspectHeader({
9-
rootPath,
10-
onRootPathChange,
11-
}: SandboxInspectHeaderProps) {
3+
export default function SandboxInspectHeader() {
124
return (
135
<div className="flex items-center gap-2 p-8">
14-
<Input
15-
className="w-55"
16-
placeholder="Root Path"
17-
value={rootPath}
18-
onChange={(e) => onRootPathChange(e.target.value)}
19-
/>
6+
<Input className="w-55" placeholder="Root Path" />
207
</div>
218
)
229
}

src/features/dashboard/sandbox/inspect/node.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { FileType } from 'e2b'
21
import SandboxInspectDir from './dir'
32
import { useFilesystemNode } from './hooks/use-node'
43
import SandboxInspectFile from './file'
@@ -11,9 +10,9 @@ export default function SandboxInspectNode({ path }: SandboxInspectDirProps) {
1110
const node = useFilesystemNode(path)!
1211

1312
switch (node.type) {
14-
case FileType.DIR:
13+
case 'dir':
1514
return <SandboxInspectDir dir={node} />
16-
case FileType.FILE:
15+
case 'file':
1716
return <SandboxInspectFile file={node} />
1817
}
1918
}

0 commit comments

Comments
 (0)