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-14 22:14:29 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
65efd55d5e1481a4017f5ad77185bb7813d2481d
65efd55d
1 parent
c2c2de45
Implement file delete
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
81 additions
and
33 deletions
frontend/src/file/FileList.tsx
frontend/src/util/useApi.ts
frontend/src/file/FileList.tsx
View file @
65efd55
import React from "react";
import { Table } from "antd";
import React
, { useCallback }
from "react";
import { Table
, Popconfirm, message
} from "antd";
import { ColumnsType } from "antd/lib/table";
import filesize from "filesize";
import { useParams } from "react-router-dom";
import { useFileList, FileItem } from "./useFileList";
import { useApi } from "util/useApi";
import { FileListItem } from "./FileListItem";
import styles from "./FileList.module.scss";
const columns: ColumnsType<FileItem> = [
{
title: "파일명",
dataIndex: "name",
render: (_name: string, item) => <FileListItem item={item} />,
},
{
title: "크기",
dataIndex: "size",
width: 120,
render: (bytes: number, item) =>
item.is_folder ? "" : filesize(bytes, { round: 0 }),
},
{
title: "",
dataIndex: "",
width: 200,
render: (__: any, item) =>
item.is_folder ? null : (
<div className={styles.actions}>
<a>공유</a>
<a>이동</a>
<a>복사</a>
<a>삭제</a>
</div>
),
},
];
export function FileList() {
const id = useParams<{ id: string }>().id;
const { data } = useFileList(id);
const { data, reload } = useFileList(id);
const api = useApi();
const handleDelete = useCallback(
async (id: number) => {
await api.delete(`/items/${id}/`);
await reload();
message.info("삭제되었습니다");
},
[api, reload]
);
if (!data) {
return null;
...
...
@@ -62,7 +45,59 @@ export function FileList() {
return (
<div>
{data.parent !== null && <h3>{data.name}</h3>}
<Table columns={columns} dataSource={list} pagination={false} />
<Table
rowKey="id"
columns={getColumns({
handleDelete,
})}
dataSource={list}
pagination={false}
/>
</div>
);
}
type GetColumnsParams = {
handleDelete: (id: number) => void;
};
function getColumns({ handleDelete }: GetColumnsParams): ColumnsType<FileItem> {
return [
{
title: "파일명",
key: "name",
dataIndex: "name",
render: (_name: string, item) => <FileListItem item={item} />,
},
{
title: "크기",
key: "size",
dataIndex: "size",
width: 120,
render: (bytes: number, item) =>
item.is_folder ? "" : filesize(bytes, { round: 0 }),
},
{
title: "",
key: "action",
dataIndex: "",
width: 200,
render: (__: any, item) =>
item.is_folder ? null : (
<div className={styles.actions}>
<a>공유</a>
<a>이동</a>
<a>복사</a>
<Popconfirm
title="정말로 삭제하시겠습니까?"
onConfirm={() => handleDelete(item.id)}
okText="삭제"
cancelText="취소"
>
<a>삭제</a>
</Popconfirm>
</div>
),
},
];
}
...
...
frontend/src/util/useApi.ts
0 → 100644
View file @
65efd55
import
{
useMemo
}
from
"react"
;
import
ky
from
"ky"
;
// TODO: Implement Auth
export
function
useApi
()
{
return
useMemo
(()
=>
{
return
ky
.
extend
({
hooks
:
{
beforeRequest
:
[],
},
});
},
[]);
}
Please
register
or
login
to post a comment