CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/next/components/share/edit/edit-options.tsx
Views: 687
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 { useState } from "react";
7
import { join } from "path";
8
import { Button, Card, Checkbox, Tooltip } from "antd";
9
import { Icon } from "@cocalc/frontend/components/icon";
10
import useCustomize from "lib/use-customize";
11
import OpenDirectly from "./open-directly";
12
import OpenAnonymously from "./open-anonymously";
13
import ChooseProject from "./choose-project";
14
import { Props } from "./index";
15
import InPlaceSignInOrUp from "components/auth/in-place-sign-in-or-up";
16
import { trunc_middle } from "@cocalc/util/misc";
17
18
interface EditOptionsProps extends Props {
19
onClose: () => void;
20
}
21
22
export default function EditOptions({
23
id,
24
path,
25
url,
26
relativePath,
27
project_id,
28
image,
29
onClose,
30
description,
31
has_site_license,
32
}: EditOptionsProps) {
33
const { isCollaborator } = useCustomize();
34
const [everything, setEverything] = useState<boolean>(true);
35
const [copied, setCopied] = useState<boolean>(false);
36
const { account } = useCustomize();
37
return (
38
<Card
39
style={{ margin: "30px 0" }}
40
title={
41
<>
42
<div style={{ float: "right", display: "flex" }}>
43
{!(!url && isCollaborator) && (
44
<div>
45
<Tooltip title="When checked, additional files may be copied to your project, which uses more spaces but ensures everything works.">
46
<Checkbox
47
disabled={copied}
48
checked={everything}
49
onChange={(e) => setEverything(e.target.checked)}
50
>
51
Copy Everything
52
</Checkbox>
53
</Tooltip>
54
</div>
55
)}
56
<Button
57
type="text"
58
onClick={onClose}
59
style={{ marginLeft: "30px" }}
60
>
61
<Icon name="times" />
62
</Button>
63
</div>
64
<Icon style={{ marginRight: "10px" }} name="pencil" /> Edit{" "}
65
<b>{trunc_middle(join(path, relativePath), 60)}</b>
66
</>
67
}
68
>
69
{account?.account_id != null && (
70
<SignedInOptions
71
id={id}
72
path={path}
73
url={url}
74
relativePath={relativePath}
75
everything={everything}
76
project_id={project_id}
77
image={image}
78
description={description}
79
isCollaborator={isCollaborator}
80
onCopied={() => setCopied(true)}
81
/>
82
)}
83
{account?.account_id == null && (
84
<NotSignedInOptions
85
path={path}
86
has_site_license={has_site_license}
87
id={id}
88
/>
89
)}
90
<br />
91
</Card>
92
);
93
}
94
95
function SignedInOptions({
96
id,
97
path,
98
url,
99
relativePath,
100
project_id,
101
image,
102
description,
103
everything,
104
isCollaborator,
105
onCopied,
106
}) {
107
return !url && isCollaborator ? (
108
<OpenDirectly
109
id={id}
110
project_id={project_id}
111
path={path}
112
relativePath={relativePath}
113
/>
114
) : (
115
<ChooseProject
116
id={id}
117
src_project_id={project_id}
118
path={path}
119
url={url}
120
relativePath={relativePath}
121
everything={everything}
122
image={image}
123
description={description ? description : path ? path : relativePath}
124
onCopied={onCopied}
125
/>
126
);
127
}
128
129
function NotSignedInOptions({ path, has_site_license, id }) {
130
const { anonymousSignup, anonymousSignupLicensedShares } = useCustomize();
131
return (
132
<div>
133
<InPlaceSignInOrUp
134
title="Choose Project"
135
why={`to edit in one of your own ${
136
has_site_license ? "licensed" : ""
137
} projects using a full collaborative ${
138
path?.endsWith("ipynb") ? "Jupyter notebook" : "editor"
139
}`}
140
publicPathId={has_site_license ? id : undefined}
141
/>
142
{anonymousSignup && <OpenAnonymously />}
143
{!anonymousSignup &&
144
anonymousSignupLicensedShares &&
145
has_site_license && <OpenAnonymously publicPathId={id} />}
146
</div>
147
);
148
}
149
150