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:43:41 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
3554eabd40656fe46cf658770a735d29ff280af1
3554eabd
1 parent
9f4d15a0
Implement file download
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
8 deletions
frontend/src/file/FileListItem.tsx
frontend/src/file/useDownload.ts
frontend/src/file/FileListItem.tsx
View file @
3554eab
import React
, { Fragment }
from "react";
import React from "react";
import { FileItem } from "./useFileList";
import { Link } from "react-router-dom";
import { Button } from "antd";
import { FolderFilled, FileFilled } from "@ant-design/icons";
import { useDownload } from "./useDownload";
export function FileListItem({ item }: { item: FileItem }) {
const download = useDownload();
return item.is_folder ? (
<Fragment>
<Link to={`/folder/${item.id}`}>
<FolderFilled /> {item.name}
</Link>
</Fragment>
<Link to={`/folder/${item.id}`}>
<FolderFilled /> {item.name}
</Link>
) : (
<Fragment>
<Button
type="link"
size="small"
onClick={() => download(item.id)}
style={{ padding: 0 }}
>
<FileFilled /> {item.name}
</
Fragment
>
</
Button
>
);
}
...
...
frontend/src/file/useDownload.ts
0 → 100644
View file @
3554eab
import
{
useApi
}
from
"util/useApi"
;
import
{
useCallback
}
from
"react"
;
function
downloadURL
(
url
:
string
,
name
:
string
)
{
const
link
=
document
.
createElement
(
"a"
);
link
.
setAttribute
(
"download"
,
name
);
link
.
href
=
url
;
link
.
target
=
"_blank"
;
link
.
click
();
}
export
function
useDownload
()
{
const
api
=
useApi
();
const
download
=
useCallback
(
async
(
id
:
number
)
=>
{
const
response
=
await
api
.
get
(
`/items/
${
id
}
/`
).
json
<
any
>
();
const
{
signed_url
,
name
}
=
response
.
data
;
downloadURL
(
signed_url
,
name
);
},
[
api
]
);
return
download
;
}
Please
register
or
login
to post a comment