Buckets:
| import { DataProvider } from "@opencode-ai/ui/context" | |
| import { showToast } from "@/utils/toast" | |
| import { base64Encode } from "@opencode-ai/core/util/encode" | |
| import { useLocation, useNavigate, useParams } from "@solidjs/router" | |
| import { createEffect, createMemo, createResource, type ParentProps, Show } from "solid-js" | |
| import { useLanguage } from "@/context/language" | |
| import { LocalProvider } from "@/context/local" | |
| import { SDKProvider } from "@/context/sdk" | |
| import { useSync } from "@/context/sync" | |
| import { decode64 } from "@/utils/base64" | |
| import { Schema } from "effect" | |
| export function DirectoryDataProvider(props: ParentProps<{ directory: string; draftID?: string }>) { | |
| const location = useLocation() | |
| const navigate = useNavigate() | |
| const params = useParams() | |
| const sync = useSync() | |
| const slug = createMemo(() => base64Encode(props.directory)) | |
| createEffect(() => { | |
| // A draft lives at /new-session?draftId=… and has no directory segment to normalize. | |
| if (props.draftID) return | |
| const next = sync.data.path.directory | |
| if (!next || next === props.directory) return | |
| const path = location.pathname.slice(slug().length + 1) | |
| navigate(`/${base64Encode(next)}${path}${location.search}${location.hash}`, { replace: true }) | |
| }) | |
| createResource( | |
| () => params.id, | |
| (id) => sync.session.sync(id).catch(() => {}), | |
| ) | |
| return ( | |
| <DataProvider | |
| data={sync.data} | |
| directory={props.directory} | |
| onNavigateToSession={(sessionID: string) => navigate(`/${slug()}/session/${sessionID}`)} | |
| onSessionHref={(sessionID: string) => `/${slug()}/session/${sessionID}`} | |
| > | |
| <LocalProvider>{props.children}</LocalProvider> | |
| </DataProvider> | |
| ) | |
| } | |
| export const ProjectDirString = Schema.String.pipe(Schema.brand("ProjectDirString")) | |
| export type ProjectDirString = Schema.Schema.Type<typeof ProjectDirString> | |
| export function decodeDirectory(dir: string): ProjectDirString | undefined { | |
| const decoded = decode64(dir) | |
| if (!decoded) return | |
| return ProjectDirString.make(decoded) | |
| } | |
| export default function Layout(props: ParentProps) { | |
| const params = useParams() | |
| const language = useLanguage() | |
| const navigate = useNavigate() | |
| let invalid = "" | |
| const resolved = createMemo(() => { | |
| if (!params.dir) return "" | |
| return decodeDirectory(params.dir) ?? "" | |
| }) | |
| createEffect(() => { | |
| const dir = params.dir | |
| if (!dir) return | |
| if (resolved()) { | |
| invalid = "" | |
| return | |
| } | |
| if (invalid === dir) return | |
| invalid = dir | |
| showToast({ | |
| variant: "error", | |
| title: language.t("common.requestFailed"), | |
| description: language.t("directory.error.invalidUrl"), | |
| }) | |
| navigate("/", { replace: true }) | |
| }) | |
| return ( | |
| <Show when={resolved()} keyed> | |
| {(resolved) => ( | |
| <SDKProvider directory={resolved}> | |
| <DirectoryDataProvider directory={resolved}>{props.children}</DirectoryDataProvider> | |
| </SDKProvider> | |
| )} | |
| </Show> | |
| ) | |
| } | |
Xet Storage Details
- Size:
- 2.97 kB
- Xet hash:
- 20d241e45df41362b4d513df655e3ba9cdf9cc88e362fafeb5d42fa09587e054
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.