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/next/components/project/edit.tsx
Views: 687
/*1Edit some very basic configuration of a project, mainly that is relevant for sharing for now,2but maybe later everything.3*/45import { useState } from "react";6import { useRouter } from "next/router";7import { Button, Input, Space } from "antd";8import { Icon } from "@cocalc/frontend/components/icon";9import EditRow from "components/misc/edit-row";10import SaveButton from "components/misc/save-button";1112interface Props {13title: string;14description: string;15name: string;16project_id: string;17}1819export default function Edit(props: Props) {20const router = useRouter();21const [expanded, setExpanded] = useState<boolean>(!!router.query.edit);2223return (24<div style={{ marginBottom: "15px" }}>25<Button26disabled={expanded}27onClick={(e) => {28e.preventDefault();29setExpanded(true);30}}31key="edit"32size="small"33>34<Icon name="pencil" /> Edit...35</Button>36{expanded && (37<EditFields38info={props}39onClose={() => {40setExpanded(false);41// This reloads the page, but with no flicker, so user sees new information reflected.42router.push({ pathname: router.asPath.split("?")[0] });43}}44/>45)}46</div>47);48}4950interface Info {51project_id: string;52name: string;53title: string;54description: string;55}5657function EditFields({58info,59onClose,60}: {61info: Info;62onClose: () => void;63}) {64const [edited, setEdited] = useState<Info>(info);65const [original, setOriginal] = useState<Info>(info);66return (67<div68style={{69width: "100%",70border: "1px solid #eee",71padding: "15px",72marginTop: "15px",73}}74>75<div>76<Space style={{ float: "right" }}>77<SaveButton edited={edited} original={original} setOriginal={setOriginal} table="projects"78/>79<Button style={{ float: "right" }} onClick={onClose}>80Close81</Button>82</Space>83</div>84<br />85<EditRow label="Title">86<Input87value={edited.title}88onChange={(e) => setEdited({ ...edited, title: e.target.value })}89/>90</EditRow>91<EditRow label="Description">92<Input.TextArea93value={edited.description}94onChange={(e) =>95setEdited({ ...edited, description: e.target.value })96}97autoSize={{ minRows: 2 }}98/>99</EditRow>100<EditRow label="Name (for nicer URLs)">101<Input102value={edited.name}103onChange={(e) => setEdited({ ...edited, name: e.target.value })}104/>105</EditRow>106</div>107);108}109110111