Skip to content

Commit 6af2a26

Browse files
committed
make creating a folder much more discoverable in the +New page
1 parent 793fb71 commit 6af2a26

File tree

1 file changed

+57
-3
lines changed

1 file changed

+57
-3
lines changed

src/packages/frontend/project/new/new-file-page.tsx

Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
*/
55

66
import { Button, Input, Modal, Space } from "antd";
7-
import { useState } from "react";
8-
7+
import { useEffect, useRef, useState } from "react";
98
import { default_filename } from "@cocalc/frontend/account";
109
import { Alert, Col, Row } from "@cocalc/frontend/antd-bootstrap";
1110
import {
@@ -41,6 +40,25 @@ interface Props {
4140
}
4241

4342
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+
}, []);
4462
const { project_id } = props;
4563
const compute_server_id = useTypedRedux({ project_id }, "compute_server_id");
4664
const actions = useActions({ project_id });
@@ -273,7 +291,42 @@ export default function NewFilePage(props: Props) {
273291
path={current_path}
274292
onUpload={() => getActions().fetch_directory_listing()}
275293
/>{" "}
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>
277330
</>
278331
}
279332
subtitle={
@@ -330,6 +383,7 @@ export default function NewFilePage(props: Props) {
330383
>
331384
<Input
332385
size="large"
386+
ref={inputRef}
333387
autoFocus
334388
value={filename}
335389
disabled={extensionWarning}

0 commit comments

Comments
 (0)