|
4 | 4 | */
|
5 | 5 |
|
6 | 6 | import { Button, Input, Modal, Space } from "antd";
|
7 |
| -import { useState } from "react"; |
8 |
| - |
| 7 | +import { useEffect, useRef, useState } from "react"; |
9 | 8 | import { default_filename } from "@cocalc/frontend/account";
|
10 | 9 | import { Alert, Col, Row } from "@cocalc/frontend/antd-bootstrap";
|
11 | 10 | import {
|
@@ -41,6 +40,25 @@ interface Props {
|
41 | 40 | }
|
42 | 41 |
|
43 | 42 | export default function NewFilePage(props: Props) {
|
| 43 | + const [createFolderModal, setCreateFolderModal] = useState<boolean>(false); |
| 44 | + const createFolderModalRef = useRef<any>(null); |
| 45 | + useEffect(() => { |
| 46 | + setTimeout(() => { |
| 47 | + if (createFolderModal && createFolderModalRef.current) { |
| 48 | + createFolderModalRef.current.focus(); |
| 49 | + createFolderModalRef.current.select(); |
| 50 | + } |
| 51 | + }, 1); |
| 52 | + }, [createFolderModal]); |
| 53 | + const inputRef = useRef<any>(null); |
| 54 | + useEffect(() => { |
| 55 | + setTimeout(() => { |
| 56 | + if (inputRef.current) { |
| 57 | + inputRef.current.focus(); |
| 58 | + inputRef.current.select(); |
| 59 | + } |
| 60 | + }, 1); |
| 61 | + }, []); |
44 | 62 | const { project_id } = props;
|
45 | 63 | const compute_server_id = useTypedRedux({ project_id }, "compute_server_id");
|
46 | 64 | const actions = useActions({ project_id });
|
@@ -273,7 +291,42 @@ export default function NewFilePage(props: Props) {
|
273 | 291 | path={current_path}
|
274 | 292 | onUpload={() => getActions().fetch_directory_listing()}
|
275 | 293 | />{" "}
|
276 |
| - New File or Folder |
| 294 | + New File or{" "} |
| 295 | + <a |
| 296 | + onClick={() => { |
| 297 | + setCreateFolderModal(true); |
| 298 | + }} |
| 299 | + > |
| 300 | + Folder |
| 301 | + </a> |
| 302 | + <Modal |
| 303 | + open={createFolderModal} |
| 304 | + title={"Create New Folder"} |
| 305 | + onCancel={() => setCreateFolderModal(false)} |
| 306 | + onOk={() => { |
| 307 | + setCreateFolderModal(false); |
| 308 | + if (filename) { |
| 309 | + createFolder(); |
| 310 | + } |
| 311 | + }} |
| 312 | + > |
| 313 | + <div style={{ textAlign: "center" }}> |
| 314 | + <Input |
| 315 | + ref={createFolderModalRef} |
| 316 | + style={{ margin: "15px 0" }} |
| 317 | + autoFocus |
| 318 | + size="large" |
| 319 | + value={filename} |
| 320 | + onChange={(e) => setFilename(e.target.value)} |
| 321 | + onPressEnter={() => { |
| 322 | + setCreateFolderModal(false); |
| 323 | + if (filename) { |
| 324 | + createFolder(); |
| 325 | + } |
| 326 | + }} |
| 327 | + /> |
| 328 | + </div> |
| 329 | + </Modal> |
277 | 330 | </>
|
278 | 331 | }
|
279 | 332 | subtitle={
|
@@ -330,6 +383,7 @@ export default function NewFilePage(props: Props) {
|
330 | 383 | >
|
331 | 384 | <Input
|
332 | 385 | size="large"
|
| 386 | + ref={inputRef} |
333 | 387 | autoFocus
|
334 | 388 | value={filename}
|
335 | 389 | disabled={extensionWarning}
|
|
0 commit comments