-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
308 additions
and
139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Third party libraries | ||
import { App, Button, Modal, Tooltip } from "antd"; | ||
import { FaTrash } from "react-icons/fa"; | ||
import { ExclamationCircleFilled } from "@ant-design/icons"; | ||
// Local imports | ||
import { useDeleteBookContentMutation } from "../../../features/api/booksSlice"; | ||
|
||
// ------------------------------------------------------ | ||
|
||
const { confirm } = Modal; | ||
|
||
// ------------------------------------------------------ | ||
export default function FileDeleteButton({ content, t, type }) { | ||
const { message } = App.useApp(); | ||
const [deleteBookContent, { isLoading: isDeleting }] = useDeleteBookContentMutation(); | ||
|
||
const showConfirm = () => { | ||
confirm({ | ||
title: t("book.actions.deleteFile.title"), | ||
icon: <ExclamationCircleFilled />, | ||
content: t("book.actions.deleteFile.message", { | ||
title: content.fileName, | ||
}), | ||
okButtonProps: { loading: isDeleting }, | ||
okType: "danger", | ||
cancelButtonProps: { disabled: isDeleting }, | ||
closable: { isDeleting }, | ||
onOk() { | ||
if (content && content.links && content.links.delete) { | ||
return deleteBookContent({ content }).unwrap() | ||
.then(() => message.success(t("chapter.actions.delete.success"))) | ||
.catch((_) => message.error(t("chapter.actions.delete.error")) | ||
); | ||
} | ||
} | ||
}); | ||
}; | ||
|
||
return ( | ||
<Tooltip title={t('actions.delete')}> | ||
<Button | ||
type={type} | ||
onClick={showConfirm} | ||
icon={<FaTrash />} | ||
/> | ||
</Tooltip> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import { Link } from "react-router-dom"; | ||
|
||
// 3rd Party Libraries | ||
import { Avatar, Button, List, Tooltip, Typography, Upload } from "antd"; | ||
import { FaFileDownload, FaFileUpload } from "react-icons/fa"; | ||
|
||
// Local Import | ||
import { useUpdateBookContentMutation } from "../../../features/api/booksSlice"; | ||
import FileDeleteButton from "./fileDeleteButton"; | ||
import FileTypeIcon from "./fileTypeIcon"; | ||
|
||
// ------------------------------------------------------ | ||
|
||
function FileListItem({ | ||
libraryId, | ||
bookId, | ||
content, | ||
t, | ||
message | ||
}) { | ||
const [updateBookContent, { isLoading: isUpdating }] = useUpdateBookContentMutation(); | ||
|
||
const title = (<Link | ||
to={`/libraries/${libraryId}/books/${bookId}/contents/${content.id}`} | ||
> | ||
<Typography.Text> | ||
{content.fileName} | ||
</Typography.Text> | ||
</Link>); | ||
|
||
const uploadFile = (file) => { | ||
const isAllowed = ["application/pdf", "application/msword", "application/vnd.openxmlformats-officedocument.wordprocessingml.document"].includes(file.type); | ||
if (!isAllowed) { | ||
message.error(t("errors.imageRequired")); | ||
return; | ||
} | ||
|
||
updateBookContent({ content: content, payload: file }).unwrap() | ||
.then(() => message.success(t("book.actions.addFile.success"))) | ||
.catch((_) => message.error(t("book.actions.addFile.error"))); | ||
} | ||
|
||
return (<List.Item | ||
actions={[ | ||
content && content.links.update && ( | ||
<Tooltip title={t('book.actions.addFile.title')}> | ||
<Upload beforeUpload={uploadFile} maxCount={1} showUploadList={false} > | ||
<Button icon={<FaFileUpload />} disabled={isUpdating} /> | ||
</Upload> | ||
</Tooltip> | ||
), | ||
content && content.links.download && ( | ||
<Tooltip title={t('book.actions.downloadFile.title')}> | ||
<a href={content.links.download} target="_blank" rel="noreferrer"> | ||
<Button icon={<FaFileDownload />} /> | ||
</a> | ||
</Tooltip> | ||
), | ||
content && content.links.delete && ( | ||
<FileDeleteButton | ||
content={content} | ||
t={t} | ||
type="text" | ||
/> | ||
), | ||
]} | ||
> | ||
<List.Item.Meta | ||
title={title} | ||
avatar={ | ||
<Avatar> | ||
<FileTypeIcon | ||
type={content.mimeType} | ||
/> | ||
</Avatar> | ||
} | ||
/> | ||
</List.Item> | ||
); | ||
} | ||
|
||
export default FileListItem; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { FileOutlined, FilePdfOutlined, FileWordOutlined } from "@ant-design/icons"; | ||
|
||
const FileTypeIcon = ({ type }) => { | ||
switch (type) { | ||
case 'application/pdf': | ||
return (<FilePdfOutlined />) | ||
case "application/msword": | ||
case "application/vnd.openxmlformats-officedocument.wordprocessingml.document": | ||
return (<FileWordOutlined />); | ||
default: | ||
return (<FileOutlined />) | ||
} | ||
}; | ||
|
||
export default FileTypeIcon; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,15 @@ | ||
import React from 'react'; | ||
|
||
// 3rd party | ||
import { Space } from 'antd'; | ||
import { Space, Typography } from 'antd'; | ||
|
||
// ------------------------------------------------ | ||
export function IconText({ icon, text, link = true ,onClick = () => {} }) { | ||
export function IconText({ icon, text, secondaryText = null, link = true ,onClick = () => {} }) { | ||
return ( | ||
<Space onClick={onClick} style={{ cursor : link ? 'pointer' : 'default' }}> | ||
{React.createElement(icon)} | ||
{text} | ||
{secondaryText && <Typography.Text type="secondary">{secondaryText}</Typography.Text>} | ||
</Space> | ||
); | ||
} |
Oops, something went wrong.