From 9ec5b4398c72c68f437f171d423683f6c97455ba Mon Sep 17 00:00:00 2001 From: Tsu-ba-me Date: Mon, 28 Feb 2022 21:26:26 -0500 Subject: [PATCH] fix(striker-ui): move ContainedButton out of Files --- ...ontainedButton.tsx => ContainedButton.tsx} | 6 +-- striker-ui/components/Files/FileEditForm.tsx | 50 +++++++++---------- .../components/Files/FileUploadForm.tsx | 23 +++++---- 3 files changed, 39 insertions(+), 40 deletions(-) rename striker-ui/components/{Files/StyledContainedButton.tsx => ContainedButton.tsx} (73%) diff --git a/striker-ui/components/Files/StyledContainedButton.tsx b/striker-ui/components/ContainedButton.tsx similarity index 73% rename from striker-ui/components/Files/StyledContainedButton.tsx rename to striker-ui/components/ContainedButton.tsx index a23cc88c..44993b51 100644 --- a/striker-ui/components/Files/StyledContainedButton.tsx +++ b/striker-ui/components/ContainedButton.tsx @@ -1,6 +1,6 @@ import { Button, ButtonProps, styled } from '@mui/material'; -import { BLACK, GREY, TEXT } from '../../lib/consts/DEFAULT_THEME'; +import { BLACK, GREY, TEXT } from '../lib/consts/DEFAULT_THEME'; const StyledButton = styled(Button)({ backgroundColor: TEXT, @@ -12,7 +12,7 @@ const StyledButton = styled(Button)({ }, }); -const StyledContainedButton = ({ +const ContainedButton = ({ children, onClick, sx, @@ -23,4 +23,4 @@ const StyledContainedButton = ({ ); -export default StyledContainedButton; +export default ContainedButton; diff --git a/striker-ui/components/Files/FileEditForm.tsx b/striker-ui/components/Files/FileEditForm.tsx index 04d56a3f..5dbd4bd1 100644 --- a/striker-ui/components/Files/FileEditForm.tsx +++ b/striker-ui/components/Files/FileEditForm.tsx @@ -9,11 +9,12 @@ import { Box, Checkbox, checkboxClasses } from '@mui/material'; import API_BASE_URL from '../../lib/consts/API_BASE_URL'; import { GREY, RED, TEXT } from '../../lib/consts/DEFAULT_THEME'; +import ContainedButton from '../ContainedButton'; import FileInfo from './FileInfo'; +import Spinner from '../Spinner'; + import fetchJSON from '../../lib/fetchers/fetchJSON'; import mainAxiosInstance from '../../lib/singletons/mainAxiosInstance'; -import StyledContainedButton from './StyledContainedButton'; -import Spinner from '../Spinner'; type FileEditProps = { filesOverview: FileOverviewMetadata[]; @@ -26,25 +27,24 @@ type FileToEdit = FileDetailMetadata & { const FileEditForm = ({ filesOverview }: FileEditProps): JSX.Element => { const [filesToEdit, setFilesToEdit] = useState([]); - const [isLoadingFilesToEdit, setIsLoadingFilesToEdit] = useState( - false, - ); - - const generateFileInfoChangeHandler = ( - fileIndex: number, - ): FileInfoChangeHandler => (inputValues, { fileLocationIndex } = {}) => { - if (fileLocationIndex) { - filesToEdit[fileIndex].fileLocations[fileLocationIndex] = { - ...filesToEdit[fileIndex].fileLocations[fileLocationIndex], - ...inputValues, - }; - } else { - filesToEdit[fileIndex] = { - ...filesToEdit[fileIndex], - ...inputValues, - }; - } - }; + const [isLoadingFilesToEdit, setIsLoadingFilesToEdit] = + useState(false); + + const generateFileInfoChangeHandler = + (fileIndex: number): FileInfoChangeHandler => + (inputValues, { fileLocationIndex } = {}) => { + if (fileLocationIndex) { + filesToEdit[fileIndex].fileLocations[fileLocationIndex] = { + ...filesToEdit[fileIndex].fileLocations[fileLocationIndex], + ...inputValues, + }; + } else { + filesToEdit[fileIndex] = { + ...filesToEdit[fileIndex], + ...inputValues, + }; + } + }; const editFiles: FormEventHandler = (event) => { event.preventDefault(); @@ -181,7 +181,7 @@ const FileEditForm = ({ filesOverview }: FileEditProps): JSX.Element => { }, }} > - { }} > Purge - - - Update - + + Update )} diff --git a/striker-ui/components/Files/FileUploadForm.tsx b/striker-ui/components/Files/FileUploadForm.tsx index 7159d0d8..ce4b1a38 100644 --- a/striker-ui/components/Files/FileUploadForm.tsx +++ b/striker-ui/components/Files/FileUploadForm.tsx @@ -1,3 +1,4 @@ +import EventEmitter from 'events'; import { ChangeEventHandler, FormEventHandler, @@ -6,15 +7,15 @@ import { useState, } from 'react'; import { Box, Input, InputLabel } from '@mui/material'; -import EventEmitter from 'events'; import { UPLOAD_FILE_TYPES } from '../../lib/consts/UPLOAD_FILE_TYPES'; -import FileInfo from './FileInfo'; import { ProgressBar } from '../Bars'; +import ContainedButton from '../ContainedButton'; +import FileInfo from './FileInfo'; import { BodyText } from '../Text'; + import mainAxiosInstance from '../../lib/singletons/mainAxiosInstance'; -import StyledContainedButton from './StyledContainedButton'; type FileUploadFormProps = { onFileUploadComplete?: () => void; @@ -87,14 +88,14 @@ const FileUploadForm = ( } }; - const generateFileInfoOnChangeHandler = ( - fileIndex: number, - ): FileInfoChangeHandler => (inputValues) => { - selectedFiles[fileIndex] = { - ...selectedFiles[fileIndex], - ...inputValues, + const generateFileInfoOnChangeHandler = + (fileIndex: number): FileInfoChangeHandler => + (inputValues) => { + selectedFiles[fileIndex] = { + ...selectedFiles[fileIndex], + ...inputValues, + }; }; - }; const uploadFiles: FormEventHandler = (event) => { event.preventDefault(); @@ -222,7 +223,7 @@ const FileUploadForm = ( justifyContent: 'flex-end', }} > - Upload + Upload )}