Skip to content

Commit

Permalink
refactor(DownloadButtonItem): Remove redux implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Merkur39 committed Nov 27, 2024
1 parent 15e1668 commit ebca3c1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 22 deletions.
32 changes: 11 additions & 21 deletions src/modules/drive/Toolbar/components/DownloadButtonItem.jsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
import compose from 'lodash/flowRight'
import React from 'react'
import { connect } from 'react-redux'

import { withClient } from 'cozy-client'
import { useClient } from 'cozy-client'
import ActionsMenuItem from 'cozy-ui/transpiled/react/ActionsMenu/ActionsMenuItem'
import Icon from 'cozy-ui/transpiled/react/Icon'
import DownloadIcon from 'cozy-ui/transpiled/react/Icons/Download'
import ListItemIcon from 'cozy-ui/transpiled/react/ListItemIcon'
import ListItemText from 'cozy-ui/transpiled/react/ListItemText'
import { useAlert } from 'cozy-ui/transpiled/react/providers/Alert'
import { translate } from 'cozy-ui/transpiled/react/providers/I18n'
import { useI18n } from 'cozy-ui/transpiled/react/providers/I18n'

import { downloadFiles } from 'modules/actions/utils'

const DownloadButtonItem = ({ t, downloadAll, displayedFolder }) => {
const DownloadButtonItem = ({ files }) => {
const { showAlert } = useAlert()
const { t } = useI18n()
const client = useClient()

const handleClick = () => {
downloadFiles(client, files, { showAlert, t })
}

return (
<ActionsMenuItem
isListItem
onClick={() => downloadAll([displayedFolder], showAlert, t)}
>
<ActionsMenuItem isListItem onClick={handleClick}>
<ListItemIcon>
<Icon icon={DownloadIcon} />
</ListItemIcon>
Expand All @@ -29,15 +30,4 @@ const DownloadButtonItem = ({ t, downloadAll, displayedFolder }) => {
)
}

const mapDispatchToProps = (dispatch, ownProps) => ({
downloadAll: (folder, showAlert, t) => {
const client = ownProps.client
return downloadFiles(client, folder, { showAlert, t })
}
})

export default compose(
withClient,
translate(),
connect(null, mapDispatchToProps)
)(DownloadButtonItem)
export default DownloadButtonItem
2 changes: 1 addition & 1 deletion src/modules/drive/Toolbar/components/MoreMenu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ const MoreMenu = ({
displayedFolder={displayedFolder}
folderId={folderId}
>
<DownloadButtonItem displayedFolder={displayedFolder} />
<DownloadButtonItem files={[displayedFolder]} />
</InsideRegularFolder>
{isMobile && hasWriteAccess && <AddMenuItem />}
<SelectableItem onClick={showSelectionBar} />
Expand Down

0 comments on commit ebca3c1

Please sign in to comment.