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/project.tsx
Views: 687
1
/*
2
* This file is part of CoCalc: Copyright © 2021 Sagemath, Inc.
3
* License: MS-RSL – see LICENSE.md for details
4
*/
5
6
/*
7
Page for a given project
8
9
Show all the public paths in a given project, and maybe other information about the project?
10
*/
11
12
import { useEffect } from "react";
13
import { useRouter } from "next/router";
14
import PublicPaths from "components/share/public-paths";
15
import Collaborators from "components/share/collaborators";
16
import Loading from "components/share/loading";
17
import { Layout } from "components/share/layout";
18
import A from "components/misc/A";
19
import { Customize } from "lib/share/customize";
20
import { ProjectCollaborator } from "lib/api/schema/projects/collaborators/list";
21
import Edit from "./edit";
22
import editURL from "lib/share/edit-url";
23
import Markdown from "@cocalc/frontend/editors/slate/static-markdown";
24
import { Avatar } from "antd";
25
26
export default function Project({
27
project_id,
28
publicPaths,
29
collaborators,
30
title,
31
description,
32
name,
33
customize,
34
avatar_image_full,
35
redirect,
36
}) {
37
const router = useRouter();
38
useEffect(() => {
39
if (redirect) {
40
router.push(redirect);
41
}
42
}, [redirect]);
43
44
if (publicPaths == null || collaborators == null || title == null) {
45
return <Loading style={{ fontSize: "30px" }} />;
46
}
47
48
const collab = isCollaborator(customize.account, collaborators);
49
return (
50
<Customize value={customize}>
51
<Layout title={title}>
52
<h1>
53
{avatar_image_full && (
54
<Avatar
55
icon={<img src={avatar_image_full} />}
56
size={160}
57
shape="square"
58
style={{ float: "right" }}
59
/>
60
)}
61
Project:{" "}
62
{collab ? (
63
<A href={editURL({ project_id, type: "collaborator" })} external>
64
{title}
65
</A>
66
) : (
67
title
68
)}
69
</h1>
70
<div style={{ color: "#666" }}>
71
<Markdown value={description} />
72
</div>
73
{collab && (
74
<Edit
75
project_id={project_id}
76
title={title}
77
description={description}
78
name={name}
79
/>
80
)}
81
{collaborators != null && collaborators.length > 0 && (
82
<>
83
<h2>Collaborators</h2>
84
<Collaborators collaborators={collaborators} />
85
<br /> <br />
86
</>
87
)}
88
<h2>Public Paths</h2>
89
{collab && (
90
<div style={{ marginBottom: "15px" }}>
91
You are a collaborator on this project, so unlisted and disabled
92
public paths are also listed here, so you can more easily edit them.
93
</div>
94
)}
95
{publicPaths != null && publicPaths.length == 0 ? (
96
<div>No public paths.</div>
97
) : (
98
<PublicPaths publicPaths={publicPaths} />
99
)}
100
</Layout>
101
</Customize>
102
);
103
}
104
105
function isCollaborator(
106
account: undefined | { account_id: string },
107
collaborators: ProjectCollaborator[],
108
): boolean {
109
const account_id = account?.account_id;
110
if (account_id == null) return false;
111
for (const user of collaborators) {
112
if (user.account_id == account_id) return true;
113
}
114
return false;
115
}
116
117