Skip to content

Commit 793fb71

Browse files
committed
add "Upload" link at top of +New page
1 parent 4a6da81 commit 793fb71

File tree

2 files changed

+43
-3
lines changed

2 files changed

+43
-3
lines changed

src/packages/frontend/file-upload.tsx

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ interface FileUploadProps {
101101
dropzone_handler?: DropzoneComponentHandlers;
102102
close_button_onclick?: (event) => void;
103103
show_header: boolean;
104+
config?: object; // All supported dropzone.js config options
104105
}
105106

106107
export const FileUpload: React.FC<FileUploadProps> = (props) => {
@@ -140,7 +141,10 @@ export const FileUpload: React.FC<FileUploadProps> = (props) => {
140141
{props.show_header ? <Header /> : undefined}
141142
<div style={DROPSTYLE}>
142143
<DropzoneComponent
143-
config={{ postUrl: postUrl(props.project_id, props.current_path) }}
144+
config={{
145+
postUrl: postUrl(props.project_id, props.current_path),
146+
...props.config,
147+
}}
144148
eventHandlers={props.dropzone_handler}
145149
djsConfig={{
146150
previewTemplate: ReactDOMServer.renderToStaticMarkup(
@@ -475,3 +479,29 @@ const DropzonePreview: React.FC<DropzonePreviewProps> = ({ project_id }) => {
475479
</div>
476480
);
477481
};
482+
483+
export function UploadLink({
484+
project_id,
485+
path,
486+
onUpload,
487+
style,
488+
}: {
489+
project_id: string;
490+
path: string;
491+
onUpload?: Function;
492+
style?;
493+
}) {
494+
return (
495+
<FileUploadWrapper
496+
project_id={project_id}
497+
dest_path={path}
498+
event_handlers={{ complete: onUpload }}
499+
config={{ clickable: ".cocalc-upload-link" }}
500+
style={{ display: "inline" }}
501+
>
502+
<a style={style} className="cocalc-upload-link">
503+
Upload
504+
</a>
505+
</FileUploadWrapper>
506+
);
507+
}

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import {
2424
Tip,
2525
} from "@cocalc/frontend/components";
2626
import FakeProgress from "@cocalc/frontend/components/fake-progress";
27-
import { FileUpload } from "@cocalc/frontend/file-upload";
27+
import { FileUpload, UploadLink } from "@cocalc/frontend/file-upload";
2828
import { special_filenames_with_no_extension } from "@cocalc/frontend/project-file";
2929
import { ProjectMap } from "@cocalc/frontend/todo-types";
3030
import { filename_extension, is_only_downloadable } from "@cocalc/util/misc";
@@ -265,7 +265,17 @@ export default function NewFilePage(props: Props) {
265265
<SettingBox
266266
show_header
267267
icon={"plus-circle"}
268-
title={<>Create or Upload New File or Folder</>}
268+
title={
269+
<>
270+
Create or{" "}
271+
<UploadLink
272+
project_id={project_id}
273+
path={current_path}
274+
onUpload={() => getActions().fetch_directory_listing()}
275+
/>{" "}
276+
New File or Folder
277+
</>
278+
}
269279
subtitle={
270280
<div>
271281
<PathNavigator

0 commit comments

Comments
 (0)