From dd381f65a92a094dbadb25697b3a6cddf1d6abc0 Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Sat, 1 Aug 2020 20:06:17 -0700 Subject: [PATCH] Don't try to be fancy, just pain --- .../server/files/RenameFileModal.tsx | 13 ++++++----- resources/scripts/hoc/withFlash.tsx | 23 ------------------- 2 files changed, 7 insertions(+), 29 deletions(-) delete mode 100644 resources/scripts/hoc/withFlash.tsx diff --git a/resources/scripts/components/server/files/RenameFileModal.tsx b/resources/scripts/components/server/files/RenameFileModal.tsx index 8ecbc9d91..fb3c0620d 100644 --- a/resources/scripts/components/server/files/RenameFileModal.tsx +++ b/resources/scripts/components/server/files/RenameFileModal.tsx @@ -9,22 +9,23 @@ import tw from 'twin.macro'; import Button from '@/components/elements/Button'; import useServer from '@/plugins/useServer'; import useFileManagerSwr from '@/plugins/useFileManagerSwr'; -import withFlash, { WithFlashProps } from '@/hoc/withFlash'; +import useFlash from '@/plugins/useFlash'; interface FormikValues { name: string; } -type OwnProps = WithFlashProps & RequiredModalProps & { files: string[]; useMoveTerminology?: boolean }; +type OwnProps = RequiredModalProps & { files: string[]; useMoveTerminology?: boolean }; -const RenameFileModal = ({ flash, files, useMoveTerminology, ...props }: OwnProps) => { +const RenameFileModal = ({ files, useMoveTerminology, ...props }: OwnProps) => { const { uuid } = useServer(); const { mutate } = useFileManagerSwr(); + const { clearFlashes, clearAndAddHttpError } = useFlash(); const directory = ServerContext.useStoreState(state => state.files.directory); const setSelectedFiles = ServerContext.useStoreActions(actions => actions.files.setSelectedFiles); const submit = ({ name }: FormikValues, { setSubmitting }: FormikHelpers) => { - flash.clearFlashes('files'); + clearFlashes('files'); const len = name.split('/').length; if (files.length === 1) { @@ -50,7 +51,7 @@ const RenameFileModal = ({ flash, files, useMoveTerminology, ...props }: OwnProp .catch(error => { mutate(); setSubmitting(false); - flash.clearAndAddHttpError({ key: 'files', error }); + clearAndAddHttpError({ key: 'files', error }); }) .then(() => props.onDismissed()); }; @@ -96,4 +97,4 @@ const RenameFileModal = ({ flash, files, useMoveTerminology, ...props }: OwnProp ); }; -export default withFlash(RenameFileModal); +export default RenameFileModal; diff --git a/resources/scripts/hoc/withFlash.tsx b/resources/scripts/hoc/withFlash.tsx deleted file mode 100644 index 4a3f008f4..000000000 --- a/resources/scripts/hoc/withFlash.tsx +++ /dev/null @@ -1,23 +0,0 @@ -import React from 'react'; -import useFlash from '@/plugins/useFlash'; -import { Actions } from 'easy-peasy'; -import { ApplicationStore } from '@/state'; - -export interface WithFlashProps { - flash: Actions['flashes']; -} - -function withFlash (Component: React.ComponentType): React.ComponentType { - return (props: TOwnProps) => { - const { addError, addFlash, clearFlashes, clearAndAddHttpError } = useFlash(); - - return ( - - ); - }; -} - -export default withFlash;