Files
radicle-explorer/src/views/projects/Tree.svelte
T
Thomas Scholtes 283b665b31 Switch to flat project route type
We switch to a project route type that is just a union. This has the
following advantages

* It’s much easier to construct project routes. Fewer properties are
  needed and there are no nested objects.
* We eliminate the implicitly shared properties `path`, `peer`,
  `revision` and `route` which only belonged to the tree route.
* The structure of the project route is more regular and thus easier to
  understand.

Signed-off-by: Thomas Scholtes <geigerzaehler@axiom.fm>
2023-07-17 11:27:57 +02:00

51 lines
1.3 KiB
Svelte

<script lang="ts" strictEvents>
import type { BaseUrl, Tree } from "@httpd-client";
import { createEventDispatcher } from "svelte";
import File from "./Tree/File.svelte";
import Folder from "./Tree/Folder.svelte";
import Link from "@app/components/Link.svelte";
export let baseUrl: BaseUrl;
export let fetchTree: (path: string) => Promise<Tree | undefined>;
export let path: string;
export let peer: string | undefined;
export let projectId: string;
export let revision: string;
export let tree: Tree;
const dispatch = createEventDispatcher<{ select: string }>();
const onSelect = ({ detail: path }: { detail: string }): void => {
dispatch("select", path);
};
</script>
{#each tree.entries as entry (entry.path)}
{#if entry.kind === "tree"}
<Folder
currentPath={path}
name={entry.name}
on:select={onSelect}
prefix={`${entry.path}/`}
{baseUrl}
{fetchTree}
{peer}
{projectId}
{revision} />
{:else}
<Link
route={{
resource: "project.tree",
project: projectId,
seed: baseUrl,
path: entry.path,
peer,
revision,
}}
on:afterNavigate={() => onSelect({ detail: entry.path })}>
<File active={entry.path === path} name={entry.name} />
</Link>
{/if}
{/each}