diff --git a/web/apps/photos/src/components/FixCreationTime.tsx b/web/apps/photos/src/components/FixCreationTime.tsx index 6814cdf0e..2fb99a336 100644 --- a/web/apps/photos/src/components/FixCreationTime.tsx +++ b/web/apps/photos/src/components/FixCreationTime.tsx @@ -1,31 +1,28 @@ -import { Row, Value } from "@ente/shared/components/Container"; import DialogBox from "@ente/shared/components/DialogBox/"; -import { Button, LinearProgress } from "@mui/material"; -import EnteDateTimePicker from "components/EnteDateTimePicker"; +import { Button, LinearProgress, styled } from "@mui/material"; import { ComfySpan } from "components/ExportInProgress"; -import { Formik } from "formik"; +import { Field, Form, Formik, type FormikHelpers } from "formik"; import { t } from "i18next"; import { GalleryContext } from "pages/gallery"; -import React, { ChangeEvent, useContext, useEffect, useState } from "react"; -import { Form } from "react-bootstrap"; +import React, { useContext, useEffect, useState } from "react"; import { updateCreationTimeWithExif } from "services/updateCreationTimeWithExif"; import { EnteFile } from "types/file"; +import EnteDateTimePicker from "./EnteDateTimePicker"; export interface FixCreationTimeAttributes { files: EnteFile[]; } -type Step = "running" | "completed" | "error"; +type Step = "running" | "completed" | "completed-with-errors"; -export enum FIX_OPTIONS { - DATE_TIME_ORIGINAL, - DATE_TIME_DIGITIZED, - METADATA_DATE, - CUSTOM_TIME, -} +export type FixOption = + | "date-time-original" + | "date-time-digitized" + | "metadata-date" + | "custom-time"; -interface formValues { - option: FIX_OPTIONS; +interface FormValues { + option: FixOption; customTime: Date; } @@ -52,22 +49,18 @@ const FixCreationTime: React.FC = (props) => { } }, [props.isOpen]); - const startFix = async (option: FIX_OPTIONS, customTime: Date) => { + const onSubmit = async (values: FormValues) => { setStep("running"); - const failed = await updateCreationTimeWithExif( + const completedWithErrors = await updateCreationTimeWithExif( props.attributes.files, - option, - customTime, + values.option, + values.customTime, setProgressTracker, ); - setStep(failed ? "error" : "completed"); + setStep(completedWithErrors ? "completed-with-errors" : "completed"); await galleryContext.syncWithRemote(); }; - const onSubmit = (values: formValues) => { - startFix(Number(values.option), new Date(values.customTime)); - }; - const title = step === "running" ? t("FIX_CREATION_TIME_IN_PROGRESS") @@ -96,34 +89,10 @@ const FixCreationTime: React.FC = (props) => { {message &&
{message}
} {step === "running" && ( - + )} - - initialValues={{ - option: FIX_OPTIONS.DATE_TIME_ORIGINAL, - customTime: new Date(), - }} - validateOnBlur={false} - onSubmit={onSubmit} - > - {({ values, handleChange, handleSubmit }) => ( - <> - {(step === undefined || step === "error") && ( -
- -
- )} - - - )} - + + ); @@ -139,96 +108,105 @@ const messageForStep = (step?: Step) => { return undefined; case "completed": return t("UPDATE_CREATION_TIME_COMPLETED"); - case "error": + case "completed-with-errors": return t("UPDATE_CREATION_TIME_COMPLETED_WITH_ERROR"); } }; -const Option = ({ - value, - selected, - onChange, - label, -}: { - value: FIX_OPTIONS; - selected: FIX_OPTIONS; - onChange: (e: string | ChangeEvent) => void; - label: string; -}) => ( - - - - {label} - - -); - -function FixCreationTimeOptions({ handleChange, values }) { - return ( -
- - - - - - - - - - {Number(values.option) === FIX_OPTIONS.CUSTOM_TIME && ( - - - handleChange("customTime")(x.toUTCString()) - } - /> - - )} - -
- ); +interface OptionsFormProps { + step?: Step; + onSubmit: ( + values: FormValues, + formikHelpers: FormikHelpers, + ) => void | Promise; + hide: () => void; } -const FixCreationTimeFooter = ({ step, startFix, ...props }) => { +const OptionsForm: React.FC = ({ step, onSubmit, hide }) => { + return ( + + initialValues={{ + option: "date-time-original", + customTime: new Date(), + }} + validateOnBlur={false} + onSubmit={onSubmit} + > + {({ values, handleChange, handleSubmit }) => ( + <> + {(step === undefined || + step === "completed-with-errors") && ( +
+
+
+ )} +