Toggle navigation
Toggle navigation
This project
Loading...
Sign in
2020-1-CloudComputing
/
C_Team_KhuDrive
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Graphs
Network
Create a new issue
Commits
Issue Boards
Authored by
김재형
2020-06-17 15:52:57 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
4fce24c116a5deb7beb7e66309c21d3a06674a02
4fce24c1
1 parent
4a4f33a1
Implement folder creation
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
84 additions
and
4 deletions
frontend/src/file/CreateFolderPopover.tsx
frontend/src/file/FileList.tsx
frontend/src/file/CreateFolderPopover.tsx
0 → 100644
View file @
4fce24c
import React, { useState } from "react";
import { Button, Input } from "antd";
export type CreateFolderPopoverProps = {
onCreate: (name: string) => void;
onCancel?: () => void;
};
export function CreateFolderPopover({
onCreate,
onCancel,
}: CreateFolderPopoverProps) {
const [name, setName] = useState<string>("");
return (
<div>
<Input
value={name}
onChange={(event) => setName(event.target.value)}
placeholder="이름"
style={{ marginBottom: 10 }}
/>
<div className="ant-popover-buttons">
<Button size="small" onClick={onCancel}>
취소
</Button>
<Button type="primary" size="small" onClick={() => onCreate(name)}>
생성
</Button>
</div>
</div>
);
}
frontend/src/file/FileList.tsx
View file @
4fce24c
import React, { useCallback, useState } from "react";
import React, { useCallback, useState
, useContext
} from "react";
import { Table, message, Button, Popover } from "antd";
import { ColumnsType } from "antd/lib/table";
import filesize from "filesize";
...
...
@@ -11,14 +11,43 @@ import { FileItemActions } from "./FileItemActions";
import styles from "./FileList.module.scss";
import { FileUploadPopover } from "./FileUploadPopover";
import { CreateFolderPopover } from "./CreateFolderPopover";
import { TokenContext } from "auth/useAuth";
export function FileList() {
const id = useParams<{ id: string }>().id;
const { data, reload } = useFileList(id);
const [upload, setUpload] = useState<boolean>(false);
const [createFolder, setCreateFolder] = useState<boolean>(false);
const token = useContext(TokenContext);
const userId = token.user.id;
const api = useApi();
const handleCreateFolder = useCallback(
async (id: number, name: string) => {
try {
const body = new URLSearchParams();
body.set("name", name);
await api.post(`/items/${id}/children/`, {
searchParams: {
user_id: userId,
},
body,
});
await reload();
message.info("폴더가 생성되었습니다");
} catch {
message.error("폴더 생성에 실패했습니다");
}
},
[api, reload, userId]
);
const handleRename = useCallback(
async (id: number, name: string) => {
try {
...
...
@@ -115,9 +144,28 @@ export function FileList() {
파일 업로드
</Button>
</Popover>
<Button type="link" size="small">
새 폴더
</Button>
<Popover
title="폴더 이름을 입력하세요"
content={
<CreateFolderPopover
onCreate={(name: string) => {
if (!name) {
return message.error("폴더 이름을 입력하세요");
}
handleCreateFolder(data.id, name);
setCreateFolder(false);
}}
onCancel={() => setCreateFolder(false)}
/>
}
trigger="click"
visible={createFolder}
onVisibleChange={setCreateFolder}
>
<Button type="link" size="small">
새 폴더
</Button>
</Popover>
</div>
</div>
<Table
...
...
Please
register
or
login
to post a comment