From da7899bd42059d555fa7391b16b816e0ebf37034 Mon Sep 17 00:00:00 2001 From: Danny Rorabaugh Date: Fri, 27 Oct 2023 15:25:06 -0400 Subject: [PATCH] Fix export/download --- .../ProjectExport/DownloadButton.tsx | 33 +++++++---------- .../Redux/ExportProjectActions.ts | 5 --- .../Redux/ExportProjectReducer.ts | 37 +++++-------------- 3 files changed, 24 insertions(+), 51 deletions(-) diff --git a/src/components/ProjectExport/DownloadButton.tsx b/src/components/ProjectExport/DownloadButton.tsx index 8ad3456650..ce844d3a90 100644 --- a/src/components/ProjectExport/DownloadButton.tsx +++ b/src/components/ProjectExport/DownloadButton.tsx @@ -36,12 +36,8 @@ interface DownloadButtonProps { export default function DownloadButton( props: DownloadButtonProps ): ReactElement { - const projectId = useAppSelector((state: StoreState) => { - console.info(state.exportProjectState); - return state.exportProjectState.projectId; - }); - const status = useAppSelector( - (state: StoreState) => state.exportProjectState.status + const exportState = useAppSelector( + (state: StoreState) => state.exportProjectState ); const dispatch = useAppDispatch(); const [fileName, setFileName] = useState(); @@ -64,26 +60,25 @@ export default function DownloadButton( useEffect(() => { if (fileName) { - dispatch(asyncDownloadExport(projectId)).then((url) => { + dispatch(asyncDownloadExport(exportState.projectId)).then((url) => { if (url) { setFileUrl(url); reset(); } }); } - }, [dispatch, fileName, projectId, reset]); + }, [dispatch, exportState.projectId, fileName, reset, setFileUrl]); useEffect(() => { - console.info("exportState updated"); - if (status === ExportStatus.Success) { - getProjectName(projectId).then((projectName) => { + if (exportState.status === ExportStatus.Success) { + getProjectName(exportState.projectId).then((projectName) => { setFileName(makeExportName(projectName)); }); } - }, [projectId, status]); + }, [exportState, setFileName]); function textId(): string { - switch (status) { + switch (exportState.status) { case ExportStatus.Exporting: return "projectExport.exportInProgress"; case ExportStatus.Success: @@ -97,7 +92,7 @@ export default function DownloadButton( } function icon(): ReactElement { - switch (status) { + switch (exportState.status) { case ExportStatus.Exporting: case ExportStatus.Downloading: case ExportStatus.Success: @@ -110,7 +105,7 @@ export default function DownloadButton( } function iconColor(): `#${string}` { - return status === ExportStatus.Failure + return exportState.status === ExportStatus.Failure ? themeColors.error : props.colorSecondary ? themeColors.secondary @@ -118,7 +113,7 @@ export default function DownloadButton( } function iconFunction(): () => void { - switch (status) { + switch (exportState.status) { case ExportStatus.Failure: return reset; default: @@ -127,8 +122,8 @@ export default function DownloadButton( } return ( - <> - {status !== ExportStatus.Default && ( + + {exportState.status !== ExportStatus.Default && ( )} - + ); } diff --git a/src/components/ProjectExport/Redux/ExportProjectActions.ts b/src/components/ProjectExport/Redux/ExportProjectActions.ts index 5b0e3344c4..8bd8488ff1 100644 --- a/src/components/ProjectExport/Redux/ExportProjectActions.ts +++ b/src/components/ProjectExport/Redux/ExportProjectActions.ts @@ -36,19 +36,14 @@ export function success(projectId: string): PayloadAction { export function asyncExportProject(projectId: string) { return async (dispatch: StoreStateDispatch) => { - console.info("dispatching export"); dispatch(exporting(projectId)); - console.info("exporting"); await exportLift(projectId).catch(() => dispatch(failure(projectId))); - console.info("exported"); }; } export function asyncDownloadExport(projectId: string) { return async (dispatch: StoreStateDispatch) => { - console.info("dispatching download"); dispatch(downloading(projectId)); - console.info("downloading"); return await downloadLift(projectId).catch(() => { dispatch(failure(projectId)); }); diff --git a/src/components/ProjectExport/Redux/ExportProjectReducer.ts b/src/components/ProjectExport/Redux/ExportProjectReducer.ts index f5d032d833..2e8d128898 100644 --- a/src/components/ProjectExport/Redux/ExportProjectReducer.ts +++ b/src/components/ProjectExport/Redux/ExportProjectReducer.ts @@ -12,41 +12,24 @@ const exportProjectSlice = createSlice({ /* eslint-disable @typescript-eslint/no-unused-vars */ reducers: { downloadingAction: (state, action) => { - console.info("updating state to downloading"); - console.info(action); - state = { - ...defaultState, - projectId: action.payload, - status: ExportStatus.Downloading, - }; - console.info(state); + state.projectId = action.payload; + state.status = ExportStatus.Downloading; }, exportingAction: (state, action) => { - console.info("updating state to exporting"); - console.info(action); - state = { - ...defaultState, - projectId: action.payload, - status: ExportStatus.Exporting, - }; - console.info(state); + state.projectId = action.payload; + state.status = ExportStatus.Exporting; }, failureAction: (state, action) => { - state = { - ...defaultState, - projectId: action.payload, - status: ExportStatus.Failure, - }; + state.projectId = action.payload; + state.status = ExportStatus.Failure; }, resetAction: (state) => { - state = { ...defaultState, status: ExportStatus.Default }; + state.projectId = ""; + state.status = ExportStatus.Default; }, successAction: (state, action) => { - state = { - ...defaultState, - projectId: action.payload, - status: ExportStatus.Success, - }; + state.projectId = action.payload; + state.status = ExportStatus.Success; }, }, /* eslint-enable @typescript-eslint/no-unused-vars */