From cd879975d268dc5aaaf1e8043be50b05030f3ab2 Mon Sep 17 00:00:00 2001 From: Manav Rathi Date: Sat, 9 Nov 2024 11:39:32 +0530 Subject: [PATCH] Ref wip --- .../photos/src/components/FixCreationTime.tsx | 110 ++++++++---------- web/apps/photos/src/pages/gallery.tsx | 21 ++-- 2 files changed, 62 insertions(+), 69 deletions(-) diff --git a/web/apps/photos/src/components/FixCreationTime.tsx b/web/apps/photos/src/components/FixCreationTime.tsx index ca7292dd6b..af2a75107d 100644 --- a/web/apps/photos/src/components/FixCreationTime.tsx +++ b/web/apps/photos/src/components/FixCreationTime.tsx @@ -1,3 +1,5 @@ +import { FocusVisibleButton } from "@/base/components/mui/FocusVisibleButton"; +import type { ModalVisibilityProps } from "@/base/components/utils/modal"; import log from "@/base/log"; import { fileLogID, type EnteFile } from "@/media/file"; import { @@ -10,7 +12,6 @@ import { FileType } from "@/media/file-type"; import { PhotoDateTimePicker } from "@/new/photos/components/PhotoDateTimePicker"; import downloadManager from "@/new/photos/services/download"; import { extractExifDates } from "@/new/photos/services/exif"; -import { FocusVisibleButton } from "@/base/components/mui/FocusVisibleButton"; import { ensure } from "@/utils/ensure"; import { Box, @@ -29,71 +30,47 @@ import { import { useFormik } from "formik"; import { t } from "i18next"; import { GalleryContext } from "pages/gallery"; -import React, { useContext, useEffect, useState } from "react"; +import React, { useContext, useState } from "react"; -/** The current state of the fixing process. */ -type Status = "running" | "completed" | "completed-with-errors"; - -export type FixOption = - | "date-time-original" - | "date-time-digitized" - | "metadata-date" - | "custom"; - -export interface FixCreationTimeAttributes { +type FixCreationTimeProps = ModalVisibilityProps & { files: EnteFile[]; -} +}; -interface FixCreationTimeProps { - isOpen: boolean; - hide: () => void; - attributes: FixCreationTimeAttributes; -} - -const FixCreationTime: React.FC = ({ - isOpen, - hide, - attributes, +export const FixCreationTime: React.FC = ({ + open, + onClose, + files, }) => { - const [status, setStatus] = useState(); + const [step, setStep] = useState(); const [progress, setProgress] = useState({ completed: 0, total: 0 }); const galleryContext = useContext(GalleryContext); - useEffect(() => { - // TODO (MR): Not sure why this is needed - if (attributes && isOpen && status !== "running") setStatus(undefined); - }, [isOpen]); - const onSubmit = async (values: FormValues) => { - setStatus("running"); + setStep("running"); const completedWithErrors = await updateFiles( - attributes.files, + files, values.option, values.customDate, setProgress, ); - setStatus(completedWithErrors ? "completed-with-errors" : "completed"); + setStep(completedWithErrors ? "completed-with-errors" : "completed"); await galleryContext.syncWithRemote(); }; const title = - status == "running" + step == "running" ? t("FIX_CREATION_TIME_IN_PROGRESS") : t("FIX_CREATION_TIME"); - const message = messageForStatus(status); - - if (!attributes) { - return <>; - } + const message = messageForStatus(step); return ( { if (reason == "backdropClick") return; - hide(); + onClose(); }} > {title} @@ -102,18 +79,25 @@ const FixCreationTime: React.FC = ({ minWidth: "310px", display: "flex", flexDirection: "column", - ...(status == "running" ? { alignItems: "center" } : {}), + ...(step == "running" ? { alignItems: "center" } : {}), }} > {message && {message}} - {status === "running" && } - + {step === "running" && } + ); }; -export default FixCreationTime; +/** The current state of the fixing process. */ +type Step = "running" | "completed" | "completed-with-errors"; + +type FixOption = + | "date-time-original" + | "date-time-digitized" + | "metadata-date" + | "custom"; interface FormValues { option: FixOption; @@ -126,7 +110,7 @@ interface FixProgress { total: number; } -const messageForStatus = (step?: Status) => { +const messageForStatus = (step?: Step) => { switch (step) { case undefined: return undefined; @@ -156,12 +140,16 @@ const Progress: React.FC = ({ completed, total }) => ( ); interface OptionsFormProps { - step?: Status; + step: Step; onSubmit: (values: FormValues) => Promise; - hide: () => void; + onClose: () => void; } -const OptionsForm: React.FC = ({ step, onSubmit, hide }) => { +const OptionsForm: React.FC = ({ + step, + onSubmit, + onClose, +}) => { const { values, handleChange, setValues, handleSubmit } = useFormik({ initialValues: { @@ -217,12 +205,22 @@ const OptionsForm: React.FC = ({ step, onSubmit, hide }) => { )} )} -