mirror of
https://github.com/plankanban/planka.git
synced 2025-07-19 05:09:43 +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]);
|
}, [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(
|
const handleToggleCoverClick = useCallback(
|
||||||
(event) => {
|
(event) => {
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
|
@ -114,25 +127,31 @@ const ItemContent = React.forwardRef(({ id, onOpen }, ref) => {
|
||||||
<span className={styles.information}>
|
<span className={styles.information}>
|
||||||
<TimeAgo date={attachment.createdAt} />
|
<TimeAgo date={attachment.createdAt} />
|
||||||
</span>
|
</span>
|
||||||
{attachment.type === AttachmentTypes.FILE && attachment.data.image && canEdit && (
|
{attachment.type === AttachmentTypes.FILE && (
|
||||||
<span className={styles.options}>
|
<span className={styles.options}>
|
||||||
<button type="button" className={styles.option} onClick={handleToggleCoverClick}>
|
<button type="button" className={styles.option} onClick={handleDownloadClick}>
|
||||||
<Icon
|
<Icon name="download" size="small" className={styles.optionIcon} />
|
||||||
name="window maximize outline"
|
<span className={styles.optionText}>Download</span>
|
||||||
flipped="vertically"
|
|
||||||
size="small"
|
|
||||||
className={styles.optionIcon}
|
|
||||||
/>
|
|
||||||
<span className={styles.optionText}>
|
|
||||||
{isCover
|
|
||||||
? t('action.removeCover', {
|
|
||||||
context: 'title',
|
|
||||||
})
|
|
||||||
: t('action.makeCover', {
|
|
||||||
context: 'title',
|
|
||||||
})}
|
|
||||||
</span>
|
|
||||||
</button>
|
</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>
|
</span>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -52,6 +52,10 @@
|
||||||
outline: none;
|
outline: none;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
|
|
||||||
|
&:not(:last-child) {
|
||||||
|
margin-right: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
&:hover {
|
&:hover {
|
||||||
color: #172b4d;
|
color: #172b4d;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue