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/index.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
/*
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
type="primary"
62
disabled={expanded}
63
onClick={(e) => {
64
e.preventDefault();
65
setExpanded(true);
66
}}
67
key="edit"
68
>
69
<Icon name="pencil" /> Edit your own copy...
70
</Button>
71
{expanded && (
72
<EditOptions
73
id={id}
74
path={path}
75
url={url}
76
relativePath={relativePath}
77
project_id={project_id}
78
image={image}
79
description={description}
80
has_site_license={has_site_license}
81
onClose={() => {
82
setExpanded(false);
83
}}
84
/>
85
)}
86
</span>
87
);
88
}
89
90