Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/next/components/share/edit/index.tsx
1544 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
/*
7
When you want to edit an existing public share, here's the flow of what happens.
8
9
- If you are a collaborator on the project with the shared document it shows a button to "Open the file in my project" (or something).
10
- If you are NOT a collaborator on the project there are various states:
11
- If you are NOT signed in it gives you the option to:
12
- Sign in, then start this flowchart over
13
- Sign up, then start this over
14
- Create a new anonymous project and anonymously edit this content.
15
- If you are signed in, it gives you these options:
16
- Create a new project and copy this content to that project (and it opens the project in a new tab).
17
- Copy this content to one of your existing projects.
18
- If you select this, then a select an existing projects, and maybe a directory in that project.
19
- Project starts and content gets copied
20
- Maybe when done get a link and can open that.
21
- In all cases above, if share comes with a license (i.e., the CUP situation), then that license gets applied to the relevant project... temporarily (?).
22
23
*/
24
25
import { Icon } from "@cocalc/frontend/components/icon";
26
import { Button } from "antd";
27
import { useRouter } from "next/router";
28
import { useEffect, useState } from "react";
29
import EditOptions from "./edit-options";
30
31
export interface Props {
32
id: string;
33
path: string;
34
url?: string;
35
relativePath: string;
36
project_id: string;
37
image?: string;
38
description?: string;
39
has_site_license?: boolean;
40
}
41
42
export default function Edit({
43
id,
44
path,
45
url,
46
relativePath,
47
project_id,
48
image,
49
description,
50
has_site_license,
51
}: Props) {
52
const router = useRouter();
53
const [expanded, setExpanded] = useState<boolean>(!!router.query.edit);
54
useEffect(() => {
55
setExpanded(!!router.query.edit);
56
}, [id, path, url, relativePath]);
57
58
return (
59
<span>
60
<Button
61
style={{ marginLeft: "-15px" }}
62
type="link"
63
disabled={expanded}
64
onClick={(e) => {
65
e.preventDefault();
66
setExpanded(true);
67
}}
68
key="edit"
69
>
70
<Icon name="pencil" /> Edit Copy
71
</Button>
72
{expanded && (
73
<EditOptions
74
id={id}
75
path={path}
76
url={url}
77
relativePath={relativePath}
78
project_id={project_id}
79
image={image}
80
description={description}
81
has_site_license={has_site_license}
82
onClose={() => {
83
setExpanded(false);
84
}}
85
/>
86
)}
87
</span>
88
);
89
}
90
91