Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/frontend/editors/archive/component.tsx
1691 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
import { Button, Card } from "antd";
7
8
import { useActions, useRedux } from "@cocalc/frontend/app-framework";
9
import { A, ErrorDisplay, Icon, Loading } from "@cocalc/frontend/components";
10
import { ArchiveActions } from "./actions";
11
12
export const Archive: React.FC<{ project_id: string; path: string }> = ({
13
path,
14
project_id,
15
}) => {
16
const contents: string | undefined = useRedux(["contents"], project_id, path);
17
const type: string | undefined = useRedux(["type"], project_id, path);
18
const loading: boolean | undefined = useRedux(["loading"], project_id, path);
19
const command: string | undefined = useRedux(["command"], project_id, path);
20
const error: string | undefined = useRedux(["error"], project_id, path);
21
const extract_output: string | undefined = useRedux(
22
["extract_output"],
23
project_id,
24
path,
25
);
26
27
const actions: ArchiveActions = useActions(project_id, path);
28
29
function render_button_icon() {
30
if (loading) {
31
return <Icon name="cocalc-ring" spin={true} />;
32
} else {
33
return <Icon name="folder" />;
34
}
35
}
36
37
function render_unsupported() {
38
return (
39
<span>
40
<b>WARNING:</b> Support for decompressing {type} archives is not yet
41
implemented (see{" "}
42
<A href="https://github.com/sagemathinc/cocalc/issues/1720">
43
https://github.com/sagemathinc/cocalc/issues/1720
44
</A>
45
).
46
<br />
47
Despite that, you can open up a Terminal ("Files" → "Create" dropdown,
48
select "Terminal") and run the extraction command right there in the
49
Linux shell.
50
</span>
51
);
52
}
53
54
function render_error() {
55
if (!error) return;
56
const error_component =
57
error == "unsupported" ? render_unsupported() : <pre>{error}</pre>;
58
return (
59
<div>
60
<br />
61
<ErrorDisplay
62
error_component={error_component}
63
style={{ maxWidth: "100%" }}
64
/>
65
</div>
66
);
67
}
68
69
if (contents == null && error == null) {
70
return <Loading theme="medium" />;
71
}
72
73
return (
74
<Card
75
title={
76
<div>
77
<Icon name="file-zip" /> {path}
78
</div>
79
}
80
style={{ overflow: "auto" }}
81
>
82
<Button
83
disabled={!!error || loading}
84
type="primary"
85
onClick={() => actions.extractArchiveFiles(type, contents)}
86
>
87
{render_button_icon()} Extract Files...
88
</Button>
89
<br />
90
<br />
91
{command && <pre style={{ marginTop: "15px" }}>{command}</pre>}
92
{extract_output && (
93
<pre style={{ marginTop: "15px" }}>{extract_output}</pre>
94
)}
95
{render_error()}
96
<pre>{contents}</pre>
97
</Card>
98
);
99
};
100
101