Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/next/components/share/path-actions.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 { Icon } from "@cocalc/frontend/components/icon";
7
import Link from "next/link";
8
// import ExternalLink from "./external-link";
9
// import rawURL from "lib/share/raw-url";
10
import downloadURL from "lib/share/download-url";
11
import { r_join } from "@cocalc/frontend/components/r_join";
12
import SiteName from "./site-name";
13
import Edit from "./edit";
14
15
import type { JSX } from "react";
16
17
interface Props {
18
id: string;
19
path: string;
20
url?: string;
21
relativePath: string;
22
isDir?: boolean;
23
exclude?: Set<string>;
24
project_id: string;
25
image?: string;
26
description?: string;
27
has_site_license?: boolean;
28
}
29
30
export default function PathActions({
31
id,
32
path,
33
url,
34
relativePath,
35
isDir,
36
exclude,
37
project_id,
38
image,
39
description,
40
has_site_license,
41
}: Props) {
42
const include = (action: string) => !exclude?.has(action);
43
const v: JSX.Element[] = [];
44
if (include("edit")) {
45
if (url && isDir) {
46
// TODO!
47
// have to implement git clone...
48
} else {
49
v.push(
50
<Edit
51
key="edit"
52
id={id}
53
path={path}
54
url={url}
55
relativePath={relativePath}
56
image={image}
57
project_id={project_id}
58
description={description}
59
has_site_license={has_site_license}
60
/>,
61
);
62
}
63
}
64
if (!url && include("hosted")) {
65
v.push(
66
<Link
67
key="hosted"
68
href={`/share/public_paths/${id}`}
69
style={{ marginTop: "5px" }}
70
>
71
Hosted by <SiteName />
72
</Link>,
73
);
74
}
75
if (!url && !isDir && include("download")) {
76
v.push(
77
<a
78
key="download"
79
href={downloadURL(id, path, relativePath)}
80
style={{ marginTop: "5px" }}
81
>
82
<Icon name="cloud-download" /> Download
83
</a>,
84
);
85
}
86
/*
87
if (!url && include("raw")) {
88
v.push(
89
<ExternalLink key="raw" href={rawURL({ id, path, relativePath })}>
90
Raw
91
</ExternalLink>,
92
);
93
}
94
if (!url && include("embed")) {
95
v.push(
96
<Link
97
key="embed"
98
href={`/share/public_paths/embed/${id}${
99
relativePath ? "/" + relativePath : ""
100
}`}
101
>
102
Embed
103
</Link>,
104
);
105
}
106
*/
107
108
return (
109
<div style={{ display: "flex" }}>
110
{r_join(v, <div style={{ width: "10px" }} />)}
111
</div>
112
);
113
}
114
115