Skip to content

Commit

Permalink
[ProjectExport] Improve feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
imnasnainaec authored Nov 15, 2023
1 parent d020770 commit c3bd185
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 22 deletions.
6 changes: 3 additions & 3 deletions public/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,9 @@
},
"projectExport": {
"cannotExportEmpty": "Project is empty. You cannot export a project with no words.",
"downloadInProgress": "Download in progress",
"exportFailed": "Export failed",
"exportInProgress": "Export in progress"
"downloadInProgress": "Downloading project: {{ val }}",
"exportFailed": "Failed to export project {{ val }}. Click to clear this message.",
"exportInProgress": "Exporting project: {{ val }}"
},
"projectSettings": {
"project": "Project:",
Expand Down
34 changes: 21 additions & 13 deletions src/components/ProjectExport/DownloadButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@ export default function DownloadButton(
const dispatch = useAppDispatch();
const [fileName, setFileName] = useState<string | undefined>();
const [fileUrl, setFileUrl] = useState<string | undefined>();
const [projectName, setProjectName] = useState("");
const { t } = useTranslation();
const downloadLink = createRef<HTMLAnchorElement>();

const reset = useCallback(async (): Promise<void> => {
setFileName(undefined);
await dispatch(asyncResetExport());
}, [dispatch]);

Expand All @@ -67,25 +69,31 @@ export default function DownloadButton(
}
});
}
}, [dispatch, exportState.projectId, fileName, reset, setFileUrl]);
}, [dispatch, exportState.projectId, fileName, reset]);

useEffect(() => {
if (exportState.status === ExportStatus.Success) {
getProjectName(exportState.projectId).then((projectName) => {
setFileName(makeExportName(projectName));
});
if (exportState.projectId) {
getProjectName(exportState.projectId).then(setProjectName);
} else {
setProjectName("");
}
}, [exportState.projectId]);

useEffect(() => {
if (exportState.status === ExportStatus.Success && projectName) {
setFileName(makeExportName(projectName));
}
}, [exportState, setFileName]);
}, [exportState.status, projectName]);

function textId(): string {
function tooltipText(): string {
switch (exportState.status) {
case ExportStatus.Exporting:
return "projectExport.exportInProgress";
return t("projectExport.exportInProgress", { val: projectName });
case ExportStatus.Success:
case ExportStatus.Downloading:
return "projectExport.downloadInProgress";
return t("projectExport.downloadInProgress", { val: projectName });
case ExportStatus.Failure:
return "projectExport.exportFailed";
return t("projectExport.exportFailed", { val: projectName });
default:
throw new Error("Not implemented");
}
Expand Down Expand Up @@ -122,9 +130,9 @@ export default function DownloadButton(
}

return (
<Fragment>
<>
{exportState.status !== ExportStatus.Default && (
<Tooltip title={t(textId())} placement="bottom">
<Tooltip title={tooltipText()} placement="bottom">
<IconButton
tabIndex={-1}
onClick={iconFunction()}
Expand All @@ -145,6 +153,6 @@ export default function DownloadButton(
(This link should not be visible)
</a>
)}
</Fragment>
</>
);
}
8 changes: 4 additions & 4 deletions src/components/ProjectExport/Redux/ExportProjectActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
downloadingAction,
exportingAction,
failureAction,
resetAction,
resetExportAction,
successAction,
} from "components/ProjectExport/Redux//ExportProjectReducer";
import { StoreStateDispatch } from "types/Redux/actions";
Expand All @@ -24,8 +24,8 @@ export function failure(projectId: string): PayloadAction {
return failureAction(projectId);
}

export function reset(): Action {
return resetAction();
export function resetExport(): Action {
return resetExportAction();
}

export function success(projectId: string): PayloadAction {
Expand All @@ -52,7 +52,7 @@ export function asyncDownloadExport(projectId: string) {

export function asyncResetExport() {
return async (dispatch: StoreStateDispatch) => {
dispatch(reset());
dispatch(resetExport());
await deleteLift();
};
}
4 changes: 2 additions & 2 deletions src/components/ProjectExport/Redux/ExportProjectReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const exportProjectSlice = createSlice({
state.projectId = action.payload;
state.status = ExportStatus.Failure;
},
resetAction: () => defaultState,
resetExportAction: () => defaultState,
successAction: (state, action) => {
state.projectId = action.payload;
state.status = ExportStatus.Success;
Expand All @@ -36,7 +36,7 @@ export const {
downloadingAction,
exportingAction,
failureAction,
resetAction,
resetExportAction,
successAction,
} = exportProjectSlice.actions;

Expand Down

0 comments on commit c3bd185

Please sign in to comment.