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/project/edit.tsx
Views: 687
1
/*
2
Edit some very basic configuration of a project, mainly that is relevant for sharing for now,
3
but maybe later everything.
4
*/
5
6
import { useState } from "react";
7
import { useRouter } from "next/router";
8
import { Button, Input, Space } from "antd";
9
import { Icon } from "@cocalc/frontend/components/icon";
10
import EditRow from "components/misc/edit-row";
11
import SaveButton from "components/misc/save-button";
12
13
interface Props {
14
title: string;
15
description: string;
16
name: string;
17
project_id: string;
18
}
19
20
export default function Edit(props: Props) {
21
const router = useRouter();
22
const [expanded, setExpanded] = useState<boolean>(!!router.query.edit);
23
24
return (
25
<div style={{ marginBottom: "15px" }}>
26
<Button
27
disabled={expanded}
28
onClick={(e) => {
29
e.preventDefault();
30
setExpanded(true);
31
}}
32
key="edit"
33
size="small"
34
>
35
<Icon name="pencil" /> Edit...
36
</Button>
37
{expanded && (
38
<EditFields
39
info={props}
40
onClose={() => {
41
setExpanded(false);
42
// This reloads the page, but with no flicker, so user sees new information reflected.
43
router.push({ pathname: router.asPath.split("?")[0] });
44
}}
45
/>
46
)}
47
</div>
48
);
49
}
50
51
interface Info {
52
project_id: string;
53
name: string;
54
title: string;
55
description: string;
56
}
57
58
function EditFields({
59
info,
60
onClose,
61
}: {
62
info: Info;
63
onClose: () => void;
64
}) {
65
const [edited, setEdited] = useState<Info>(info);
66
const [original, setOriginal] = useState<Info>(info);
67
return (
68
<div
69
style={{
70
width: "100%",
71
border: "1px solid #eee",
72
padding: "15px",
73
marginTop: "15px",
74
}}
75
>
76
<div>
77
<Space style={{ float: "right" }}>
78
<SaveButton edited={edited} original={original} setOriginal={setOriginal} table="projects"
79
/>
80
<Button style={{ float: "right" }} onClick={onClose}>
81
Close
82
</Button>
83
</Space>
84
</div>
85
<br />
86
<EditRow label="Title">
87
<Input
88
value={edited.title}
89
onChange={(e) => setEdited({ ...edited, title: e.target.value })}
90
/>
91
</EditRow>
92
<EditRow label="Description">
93
<Input.TextArea
94
value={edited.description}
95
onChange={(e) =>
96
setEdited({ ...edited, description: e.target.value })
97
}
98
autoSize={{ minRows: 2 }}
99
/>
100
</EditRow>
101
<EditRow label="Name (for nicer URLs)">
102
<Input
103
value={edited.name}
104
onChange={(e) => setEdited({ ...edited, name: e.target.value })}
105
/>
106
</EditRow>
107
</div>
108
);
109
}
110
111