Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/next/components/share/linked-path.tsx
1449 views
1
/*
2
* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.
3
* License: MS-RSL – see LICENSE.md for details
4
*/
5
6
import Link from "next/link";
7
8
import type { JSX } from "react";
9
10
interface Props {
11
id: string;
12
path: string;
13
relativePath: string;
14
isDir?: boolean;
15
}
16
17
export default function LinkedPath({ id, path, relativePath, isDir }: Props) {
18
let href = `/share/public_paths/${id}`;
19
const first = (
20
<Link href={href} key={href}>
21
{path}
22
</Link>
23
);
24
const slash = (key) => <span key={"slash" + key}> / </span>;
25
const segments: JSX.Element[] = [first, slash(href)];
26
for (const segment of relativePath.split("/")) {
27
if (!segment) continue;
28
href += `/${encodeURIComponent(segment)}`;
29
segments.push(
30
<Link href={href} key={href}>
31
{segment}
32
</Link>
33
);
34
segments.push(slash(href));
35
}
36
if (!isDir) {
37
segments.pop();
38
}
39
return <>{segments}</>;
40
}
41
42