Path: blob/master/src/packages/frontend/editors/archive/component.tsx
1691 views
/*1* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45import { Button, Card } from "antd";67import { useActions, useRedux } from "@cocalc/frontend/app-framework";8import { A, ErrorDisplay, Icon, Loading } from "@cocalc/frontend/components";9import { ArchiveActions } from "./actions";1011export const Archive: React.FC<{ project_id: string; path: string }> = ({12path,13project_id,14}) => {15const contents: string | undefined = useRedux(["contents"], project_id, path);16const type: string | undefined = useRedux(["type"], project_id, path);17const loading: boolean | undefined = useRedux(["loading"], project_id, path);18const command: string | undefined = useRedux(["command"], project_id, path);19const error: string | undefined = useRedux(["error"], project_id, path);20const extract_output: string | undefined = useRedux(21["extract_output"],22project_id,23path,24);2526const actions: ArchiveActions = useActions(project_id, path);2728function render_button_icon() {29if (loading) {30return <Icon name="cocalc-ring" spin={true} />;31} else {32return <Icon name="folder" />;33}34}3536function render_unsupported() {37return (38<span>39<b>WARNING:</b> Support for decompressing {type} archives is not yet40implemented (see{" "}41<A href="https://github.com/sagemathinc/cocalc/issues/1720">42https://github.com/sagemathinc/cocalc/issues/172043</A>44).45<br />46Despite that, you can open up a Terminal ("Files" → "Create" dropdown,47select "Terminal") and run the extraction command right there in the48Linux shell.49</span>50);51}5253function render_error() {54if (!error) return;55const error_component =56error == "unsupported" ? render_unsupported() : <pre>{error}</pre>;57return (58<div>59<br />60<ErrorDisplay61error_component={error_component}62style={{ maxWidth: "100%" }}63/>64</div>65);66}6768if (contents == null && error == null) {69return <Loading theme="medium" />;70}7172return (73<Card74title={75<div>76<Icon name="file-zip" /> {path}77</div>78}79style={{ overflow: "auto" }}80>81<Button82disabled={!!error || loading}83type="primary"84onClick={() => actions.extractArchiveFiles(type, contents)}85>86{render_button_icon()} Extract Files...87</Button>88<br />89<br />90{command && <pre style={{ marginTop: "15px" }}>{command}</pre>}91{extract_output && (92<pre style={{ marginTop: "15px" }}>{extract_output}</pre>93)}94{render_error()}95<pre>{contents}</pre>96</Card>97);98};99100101