mirror of
https://github.com/plankanban/planka.git
synced 2025-07-18 20:59:44 +02:00
feat: Add download button for file attachments
This commit is contained in:
parent
2f62d56242
commit
c4a48d510b
2 changed files with 40 additions and 17 deletions
|
@ -54,6 +54,19 @@ const ItemContent = React.forwardRef(({ id, onOpen }, ref) => {
|
|||
}
|
||||
}, [onOpen, attachment.data]);
|
||||
|
||||
const handleDownloadClick = useCallback(
|
||||
(event) => {
|
||||
event.stopPropagation();
|
||||
|
||||
const linkElement = document.createElement('a');
|
||||
linkElement.href = attachment.data.url;
|
||||
linkElement.download = attachment.data.filename;
|
||||
linkElement.target = '_blank';
|
||||
linkElement.click();
|
||||
},
|
||||
[attachment.data.url, attachment.data.filename],
|
||||
);
|
||||
|
||||
const handleToggleCoverClick = useCallback(
|
||||
(event) => {
|
||||
event.stopPropagation();
|
||||
|
@ -114,25 +127,31 @@ const ItemContent = React.forwardRef(({ id, onOpen }, ref) => {
|
|||
<span className={styles.information}>
|
||||
<TimeAgo date={attachment.createdAt} />
|
||||
</span>
|
||||
{attachment.type === AttachmentTypes.FILE && attachment.data.image && canEdit && (
|
||||
{attachment.type === AttachmentTypes.FILE && (
|
||||
<span className={styles.options}>
|
||||
<button type="button" className={styles.option} onClick={handleToggleCoverClick}>
|
||||
<Icon
|
||||
name="window maximize outline"
|
||||
flipped="vertically"
|
||||
size="small"
|
||||
className={styles.optionIcon}
|
||||
/>
|
||||
<span className={styles.optionText}>
|
||||
{isCover
|
||||
? t('action.removeCover', {
|
||||
context: 'title',
|
||||
})
|
||||
: t('action.makeCover', {
|
||||
context: 'title',
|
||||
})}
|
||||
</span>
|
||||
<button type="button" className={styles.option} onClick={handleDownloadClick}>
|
||||
<Icon name="download" size="small" className={styles.optionIcon} />
|
||||
<span className={styles.optionText}>Download</span>
|
||||
</button>
|
||||
{attachment.data.image && canEdit && (
|
||||
<button type="button" className={styles.option} onClick={handleToggleCoverClick}>
|
||||
<Icon
|
||||
name="window maximize outline"
|
||||
flipped="vertically"
|
||||
size="small"
|
||||
className={styles.optionIcon}
|
||||
/>
|
||||
<span className={styles.optionText}>
|
||||
{isCover
|
||||
? t('action.removeCover', {
|
||||
context: 'title',
|
||||
})
|
||||
: t('action.makeCover', {
|
||||
context: 'title',
|
||||
})}
|
||||
</span>
|
||||
</button>
|
||||
)}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
|
|
|
@ -52,6 +52,10 @@
|
|||
outline: none;
|
||||
padding: 0;
|
||||
|
||||
&:not(:last-child) {
|
||||
margin-right: 10px;
|
||||
}
|
||||
|
||||
&:hover {
|
||||
color: #172b4d;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue