diff --git a/web/apps/photos/src/components/FixCreationTime.tsx b/web/apps/photos/src/components/FixCreationTime.tsx
index 244f4d019..264ec5179 100644
--- a/web/apps/photos/src/components/FixCreationTime.tsx
+++ b/web/apps/photos/src/components/FixCreationTime.tsx
@@ -6,7 +6,7 @@ import { ComfySpan } from "components/ExportInProgress";
import { Formik } from "formik";
import { t } from "i18next";
import { GalleryContext } from "pages/gallery";
-import { ChangeEvent, useContext, useEffect, useState } from "react";
+import React, { ChangeEvent, useContext, useEffect, useState } from "react";
import { Form } from "react-bootstrap";
import { updateCreationTimeWithExif } from "services/updateCreationTimeWithExif";
import { EnteFile } from "types/file";
@@ -15,21 +15,9 @@ export interface FixCreationTimeAttributes {
files: EnteFile[];
}
-interface Props {
- isOpen: boolean;
- show: () => void;
- hide: () => void;
- attributes: FixCreationTimeAttributes;
-}
+type Step = "running" | "completed" | "error";
-enum FIX_STATE {
- NOT_STARTED,
- RUNNING,
- COMPLETED,
- COMPLETED_WITH_ERRORS,
-}
-
-enum FIX_OPTIONS {
+export enum FIX_OPTIONS {
DATE_TIME_ORIGINAL,
DATE_TIME_DIGITIZED,
METADATA_DATE,
@@ -41,41 +29,31 @@ interface formValues {
customTime: Date;
}
-function Message({ fixState }: { fixState: FIX_STATE }) {
- let message = null;
- switch (fixState) {
- case FIX_STATE.NOT_STARTED:
- message = t("UPDATE_CREATION_TIME_NOT_STARTED");
- break;
- case FIX_STATE.COMPLETED:
- message = t("UPDATE_CREATION_TIME_COMPLETED");
- break;
- case FIX_STATE.COMPLETED_WITH_ERRORS:
- message = t("UPDATE_CREATION_TIME_COMPLETED_WITH_ERROR");
- break;
- }
- return message ?
{message}
: <>>;
+interface FixCreationTimeProps {
+ isOpen: boolean;
+ show: () => void;
+ hide: () => void;
+ attributes: FixCreationTimeAttributes;
}
-export default function FixCreationTime(props: Props) {
- const [fixState, setFixState] = useState(FIX_STATE.NOT_STARTED);
+const FixCreationTime: React.FC = (props) => {
+ const [step, setStep] = useState();
const [progressTracker, setProgressTracker] = useState({
current: 0,
total: 0,
});
+
const galleryContext = useContext(GalleryContext);
+
useEffect(() => {
- if (
- props.attributes &&
- props.isOpen &&
- fixState !== FIX_STATE.RUNNING
- ) {
- setFixState(FIX_STATE.NOT_STARTED);
+ // TODO (MR): Not sure why this is needed
+ if (props.attributes && props.isOpen && step !== "running") {
+ setStep(undefined);
}
}, [props.isOpen]);
const startFix = async (option: FIX_OPTIONS, customTime: Date) => {
- setFixState(FIX_STATE.RUNNING);
+ setStep("running");
const completedWithoutError = await updateCreationTimeWithExif(
props.attributes.files,
option,
@@ -83,45 +61,45 @@ export default function FixCreationTime(props: Props) {
setProgressTracker,
);
if (!completedWithoutError) {
- setFixState(FIX_STATE.COMPLETED);
+ setStep("completed");
} else {
- setFixState(FIX_STATE.COMPLETED_WITH_ERRORS);
+ setStep("error");
}
await galleryContext.syncWithRemote();
};
- if (!props.attributes) {
- return <>>;
- }
const onSubmit = (values: formValues) => {
startFix(Number(values.option), new Date(values.customTime));
};
+ const title =
+ step === "running"
+ ? t("FIX_CREATION_TIME_IN_PROGRESS")
+ : t("FIX_CREATION_TIME");
+
+ const message = messageForStep(step);
+
+ if (!props.attributes) {
+ return <>>;
+ }
+
return (
-
+ {message &&
{message}
}
- {fixState === FIX_STATE.RUNNING && (
+ {step === "running" && (
)}
@@ -134,9 +112,7 @@ export default function FixCreationTime(props: Props) {
>
{({ values, handleChange, handleSubmit }) => (
<>
- {(fixState === FIX_STATE.NOT_STARTED ||
- fixState ===
- FIX_STATE.COMPLETED_WITH_ERRORS) && (
+ {(step === undefined || step === "error") && (
)}
@@ -155,7 +131,22 @@ export default function FixCreationTime(props: Props) {
);
-}
+};
+
+export default FixCreationTime;
+
+const messageForStep = (step?: Step) => {
+ switch (step) {
+ case undefined:
+ return t("UPDATE_CREATION_TIME_NOT_STARTED");
+ case "running":
+ return undefined;
+ case "completed":
+ return t("UPDATE_CREATION_TIME_COMPLETED");
+ case "error":
+ return t("UPDATE_CREATION_TIME_COMPLETED_WITH_ERROR");
+ }
+};
const Option = ({
value,
@@ -241,9 +232,9 @@ function FixCreationTimeOptions({ handleChange, values }) {
);
}
-const FixCreationTimeFooter = ({ fixState, startFix, ...props }) => {
+const FixCreationTimeFooter = ({ step, startFix, ...props }) => {
return (
- fixState !== FIX_STATE.RUNNING && (
+ step !== "running" && (
{
justifyContent: "space-around",
}}
>
- {(fixState === FIX_STATE.NOT_STARTED ||
- fixState === FIX_STATE.COMPLETED_WITH_ERRORS) && (
+ {(step === undefined || step === "error") && (
)}
- {fixState === FIX_STATE.COMPLETED && (
+ {step === "completed" && (
)}
- {(fixState === FIX_STATE.NOT_STARTED ||
- fixState === FIX_STATE.COMPLETED_WITH_ERRORS) && (
+ {(step === undefined || step === "error") && (
<>