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/app/path.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
Edit a file using the CoCalc app.
8
*/
9
10
import { Alert } from "antd";
11
import { join } from "path";
12
import { CSSProperties } from "react";
13
14
import InPlaceSignInOrUp from "components/auth/in-place-sign-in-or-up";
15
import OpenAnonymously from "components/share/edit/open-anonymously";
16
import basePath from "lib/base-path";
17
import editURL from "lib/share/edit-url";
18
import useCustomize from "lib/use-customize";
19
import IFrame from "./iframe";
20
21
interface Props {
22
description?: string;
23
embed?: boolean;
24
fullscreen?: boolean;
25
path?: string;
26
project_id: string;
27
start?: boolean; // if true, immediately load editor rather than waiting for user to click a button.
28
style?: CSSProperties;
29
}
30
31
export default function Path(props: Props) {
32
const { project_id, path, style, fullscreen, embed, description, start } =
33
props;
34
35
const { account, anonymousSignup } = useCustomize();
36
37
if (!account) {
38
return (
39
<Alert
40
type="success"
41
style={style}
42
message={
43
<div>
44
<InPlaceSignInOrUp title={`To use ${description ?? "this"}...`} />
45
{anonymousSignup && <OpenAnonymously />}
46
</div>
47
}
48
/>
49
);
50
}
51
52
const appURL = editURL({ type: "collaborator", project_id, path });
53
54
const src = embed
55
? join(
56
basePath,
57
`static/embed.html?target=projects/${project_id}/files/${path ?? ""}`
58
)
59
: appURL + "?fullscreen=project&session=";
60
61
return (
62
<IFrame
63
src={src}
64
appURL={appURL}
65
path={path}
66
style={style}
67
fullscreen={fullscreen}
68
description={description}
69
start={start}
70
/>
71
);
72
}
73
74