Skip to content

Commit

Permalink
feat: Replace ViewerSnackbarProvider by AlertProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
Merkur39 committed Mar 11, 2024
1 parent 723a627 commit 374537a
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 106 deletions.
21 changes: 14 additions & 7 deletions react/Viewer/Panel/ActionMenuWrapper.jsx
Expand Up @@ -5,7 +5,7 @@ import { useAppLinkWithStoreFallback, useClient } from 'cozy-client'

import useBreakpoints from '../../providers/Breakpoints'
import { useI18n } from '../../providers/I18n'
import useViewerSnackbar from '../providers/ViewerSnackbarProvider'
import { useAlert } from '../../providers/Alert'
import {
buildEditAttributePath,
isEditableAttribute,
Expand All @@ -22,7 +22,7 @@ const ActionMenuWrapper = forwardRef(({ onClose, file, optionFile }, ref) => {
const editPathByModelProps = useActionMenuContext()
const { isMobile } = useBreakpoints()
const { t } = useI18n()
const { showViewerSnackbar } = useViewerSnackbar()
const { showAlert } = useAlert()
const client = useClient()

const currentModel = getCurrentModel(name)
Expand All @@ -42,12 +42,19 @@ const ActionMenuWrapper = forwardRef(({ onClose, file, optionFile }, ref) => {
const handleCopy = async () => {
try {
await navigator.clipboard.writeText(value)
showViewerSnackbar(
'success',
t(`Viewer.snackbar.copiedToClipboard.success`)
)
showAlert({
message: t(`Viewer.snackbar.copiedToClipboard.success`),
severity: 'success',
variant: 'filled',
icon: false
})
} catch (error) {
showViewerSnackbar('error', t(`Viewer.snackbar.copiedToClipboard.error`))
showAlert({
message: t(`Viewer.snackbar.copiedToClipboard.error`),
severity: 'error',
variant: 'filled',
icon: false
})
}
onClose()
}
Expand Down
8 changes: 3 additions & 5 deletions react/Viewer/ViewerContainer.jsx
Expand Up @@ -12,8 +12,7 @@ import { isValidForPanel } from './helpers'
import Viewer from './Viewer'
import ViewerInformationsWrapper from './ViewerInformationsWrapper'
import EncryptedProvider from './providers/EncryptedProvider'
import { ViewerSnackbarProvider } from './providers/ViewerSnackbarProvider'
import ViewerSnackbar from './snackbar/ViewerSnackbar'
import AlertProvider from '../providers/Alert'
import { ActionMenuProvider } from './providers/ActionMenuProvider'

import styles from './styles.styl'
Expand Down Expand Up @@ -49,7 +48,7 @@ const ViewerContainer = props => {
}

return (
<ViewerSnackbarProvider>
<AlertProvider>
<ActionMenuProvider editPathByModelProps={editPathByModelProps}>
<div
id="viewer-wrapper"
Expand All @@ -76,9 +75,8 @@ const ViewerContainer = props => {
{children}
</ViewerInformationsWrapper>
</div>
<ViewerSnackbar />
</ActionMenuProvider>
</ViewerSnackbarProvider>
</AlertProvider>
)
}

Expand Down
1 change: 1 addition & 0 deletions react/Viewer/ViewersByFile/PdfMobileViewer.jsx
Expand Up @@ -39,6 +39,7 @@ export const PdfMobileViewer = ({ file, url, t, gestures }) => {
showAlert({
message: t('Viewer.error.generic'),
severity: 'error',
variant: 'filled',
icon: false
})
}
Expand Down
64 changes: 0 additions & 64 deletions react/Viewer/providers/ViewerSnackbarProvider.jsx

This file was deleted.

30 changes: 0 additions & 30 deletions react/Viewer/snackbar/ViewerSnackbar.jsx

This file was deleted.

0 comments on commit 374537a

Please sign in to comment.