Skip to content

Commit

Permalink
feat: Set busy button after emptying a folder / trash
Browse files Browse the repository at this point in the history
  • Loading branch information
Crash-- committed Oct 2, 2023
1 parent 72866c0 commit 47f850d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
6 changes: 5 additions & 1 deletion src/drive/web/modules/trash/components/DestroyConfirm.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react'
import React, { useState } from 'react'

import { useClient } from 'cozy-client'
import { ConfirmDialog } from 'cozy-ui/transpiled/react/CozyDialogs'
Expand All @@ -11,6 +11,7 @@ import { deleteFilesPermanently } from 'drive/web/modules/actions/utils'
import { Message } from 'drive/web/modules/confirm/Message'
const DestroyConfirm = ({ t, files, onClose }) => {
const client = useClient()
const [isLoading, setIsLoading] = useState(false)
return (
<ConfirmDialog
open={true}
Expand Down Expand Up @@ -38,12 +39,15 @@ const DestroyConfirm = ({ t, files, onClose }) => {
<Button
theme="danger"
label={t('destroyconfirmation.delete')}
busy={isLoading}
onClick={async () => {
try {
setIsLoading(true)
await deleteFilesPermanently(client, files)
} catch {
// eslint-disable-next-line
} finally {
setIsLoading(false)
onClose()
}
}}
Expand Down
15 changes: 12 additions & 3 deletions src/drive/web/modules/trash/components/EmptyTrashConfirm.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react'
import React, { useState } from 'react'

import { ConfirmDialog } from 'cozy-ui/transpiled/react/CozyDialogs'
import Button from 'cozy-ui/transpiled/react/deprecated/Button'
Expand All @@ -7,6 +7,7 @@ import Stack from 'cozy-ui/transpiled/react/Stack'

import { Message } from 'drive/web/modules/confirm/Message'
const EmptyTrashConfirm = ({ t, onConfirm, onClose }) => {
const [isLoading, setIsLoading] = useState(false)
return (
<ConfirmDialog
open={true}
Expand All @@ -31,9 +32,17 @@ const EmptyTrashConfirm = ({ t, onConfirm, onClose }) => {
<Button
theme="danger"
label={t('emptytrashconfirmation.delete')}
busy={isLoading}
onClick={async () => {
await onConfirm()
onClose()
try {
setIsLoading(true)
await onConfirm()
} catch {
// eslint-disable-next-line
} finally {
setIsLoading(false)
onClose()
}
}}
/>
</>
Expand Down

0 comments on commit 47f850d

Please sign in to comment.