Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/src/packages/frontend/account/public-paths/unpublish-everything.tsx
Views: 687
/*1* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45import { Alert, Button, Input } from "antd";6import { useIntl } from "react-intl";78import {9React,10useIsMountedRef,11useMemo,12useState,13} from "@cocalc/frontend/app-framework";14import { webapp_client } from "@cocalc/frontend/webapp-client";15import { PublicPath } from "@cocalc/util/db-schema/public-paths";16import { plural } from "@cocalc/util/misc";1718interface Props {19data?: PublicPath[];20refresh: Function;21}2223export const UnpublishEverything: React.FC<Props> = React.memo(24({ data, refresh }) => {25const intl = useIntl();26const [confirm, set_confirm] = useState<boolean>(false);27const [confirm_text, set_confirm_text] = useState<string>("");28const [counter, set_counter] = useState<number>(-1);29const isMountedRef = useIsMountedRef();3031const unpublishEverything = intl.formatMessage({32id: "account.public-path.unpublish.title",33defaultMessage: "Unpublish Everything",34});3536const num_published = useMemo(() => {37if (data == null) return -1;38let n = 0;39for (const x of data) {40if (!x.disabled) {41n += 1;42}43}44return n;45}, [data]);4647function render_confirm(): JSX.Element {48const goal = "YES, UNPUBLISH EVERYTHING!";49const body = (50<div>51<div style={{ fontSize: "12pt", margin: "auto", maxWidth: "800px" }}>52{`Are you sure you want to unpublish ALL ${num_published} listed and unlisted ${plural(53num_published,54"path",55)} published in all projects on which you collaborate and have been active? You cannot easily undo this operation, though you could tediously republish everything. To unpublish everything type "${goal}" below, then click the button.`}56</div>57<br />58<br />59<Input60size="large"61placeholder={goal}62value={confirm_text}63onChange={(e) => set_confirm_text(e.target.value)}64/>65<br />66<br />67<Button68disabled={confirm_text != goal}69onClick={() => {70set_confirm(false);71set_confirm_text("");72disable_all();73}}74>75{unpublishEverything}76</Button>77</div>78);79return (80<Alert81style={{ marginBottom: "20px" }}82message={<h3>{unpublishEverything}?</h3>}83description={body}84type="warning"85showIcon86closable87afterClose={() => {88set_confirm(false);89set_confirm_text("");90}}91/>92);93}9495async function disable_all(): Promise<void> {96if (data == null) return;97set_counter(0);98for (const x of data) {99if (x.disabled) continue;100if (!isMountedRef.current) return;101await webapp_client.async_query({102query: {103public_paths: {104id: x.id,105project_id: x.project_id,106path: x.path,107disabled: true,108},109},110});111set_counter(counter + 1);112}113refresh();114set_counter(-1);115}116117return (118<div>119{confirm && render_confirm()}120{counter >= 0 && num_published > 0 && (121<h1>122Unpublished: {counter}/{num_published}123</h1>124)}125<Button126onClick={() => set_confirm(true)}127disabled={num_published == 0 || confirm}128>129{unpublishEverything}...130</Button>131</div>132);133},134);135136137