π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Fix uploader name not getting used in form
Manav Rathi7f24ffd7eff3
diff --git a/web/apps/photos/src/components/Upload.tsx b/web/apps/photos/src/components/Upload.tsxindex 86424fca2b..fe9ec555f7 100644--- a/web/apps/photos/src/components/Upload.tsx+++ b/web/apps/photos/src/components/Upload.tsx@@ -194,6 +194,7 @@ export const Upload: React.FC<UploadProps> = ({const [percentComplete, setPercentComplete] = useState(0);const [hasLivePhotos, setHasLivePhotos] = useState(false);const [prefilledNewAlbumName, setPrefilledNewAlbumName] = useState("");+ const [uploaderName, setUploaderName] = useState("");const [openCollectionMappingChoice, setOpenCollectionMappingChoice] =useState(false);@@ -280,7 +281,6 @@ export const Upload: React.FC<UploadProps> = ({const currentUploadPromise = useRef<Promise<void> | undefined>(undefined);const uploadRunning = useRef(false);- const uploaderNameRef = useRef("");const isDragAndDrop = useRef(false);/**@@ -522,10 +522,11 @@ export const Upload: React.FC<UploadProps> = ({(async () => {if (publicCollectionGalleryContext.credentials) {- const uploaderName = await savedPublicCollectionUploaderName(- publicCollectionGalleryContext.credentials.accessToken,+ setUploaderName(+ await savedPublicCollectionUploaderName(+ publicCollectionGalleryContext.credentials.accessToken,+ ),);- uploaderNameRef.current = uploaderName ?? "";showUploaderNameInput();return;}@@ -888,7 +889,7 @@ export const Upload: React.FC<UploadProps> = ({<UploaderNameInputopen={uploaderNameInputVisibilityProps.open}onClose={handleUploaderNameInputClose}- uploaderName={uploaderNameRef.current}+ uploaderName={uploaderName}uploadFileCount={uploadItemsAndPaths.current?.length ?? 0}onSubmit={handlePublicUpload}/>diff --git a/web/packages/new/albums/components/UploaderNameInput.tsx b/web/packages/new/albums/components/UploaderNameInput.tsxindex cbb038d5b9..7aa31b7b0f 100644--- a/web/packages/new/albums/components/UploaderNameInput.tsx+++ b/web/packages/new/albums/components/UploaderNameInput.tsx@@ -46,27 +46,6 @@ export const UploaderNameInput: React.FC<UploaderNameInput> = ({// Make the dialog fullscreen if it starts to get too squished.const fullScreen = useMediaQuery("(width < 400px)");- const formik = useFormik({- initialValues: { value: uploaderName },- onSubmit: async (values, { setFieldError }) => {- const value = values.value;- const setValueFieldError = (message: string) =>- setFieldError("value", message);-- if (!value) {- setValueFieldError(t("required"));- return;- }- try {- await onSubmit(value);- onClose();- } catch (e) {- log.error(`Failed to submit input ${value}`, e);- setValueFieldError(t("generic_error"));- }- },- });-return (<Dialog{...{ open, onClose, fullScreen }}@@ -89,45 +68,82 @@ export const UploaderNameInput: React.FC<UploaderNameInput> = ({<Typography sx={{ color: "text.muted", pb: 1 }}>{t("uploader_name_hint")}</Typography>- <form onSubmit={formik.handleSubmit}>- <TextField- name="value"- value={formik.values.value}- onChange={formik.handleChange}- type={"text"}- fullWidth- autoFocus- margin="normal"- hiddenLabel- aria-label={t("name")}- placeholder={t("name_placeholder")}- disabled={formik.isSubmitting}- error={!!formik.errors.value}- // As an exception, we don't use an space character- // default here since that skews the look of the dialog- // too much in the happy case. The downside is that- // there will be a layout shift on errors.- helperText={formik.errors.value}- />- <Stack sx={{ mt: 1.5, gap: 1 }}>- <LoadingButton- fullWidth- type="submit"- loading={formik.isSubmitting}- color="accent"- >- {t("add_photos_count", { count: uploadFileCount })}- </LoadingButton>- <FocusVisibleButton- fullWidth- color="secondary"- onClick={onClose}- >- {t("cancel")}- </FocusVisibleButton>- </Stack>- </form>+ <UploaderNameInputForm+ {...{ onClose, uploaderName, uploadFileCount, onSubmit }}+ /></DialogContent></Dialog>);};++/**+ * The form that obtains the textual input of the uploader name.+ *+ * It is kept as a separate component so that it gets recreated on prop changes+ * (e.g. uploaderName changes).+ */+export const UploaderNameInputForm: React.FC<+ Omit<UploaderNameInput, "open">+> = ({ onClose, uploaderName, uploadFileCount, onSubmit }) => {+ const formik = useFormik({+ initialValues: { value: uploaderName },+ onSubmit: async (values, { setFieldError }) => {+ const value = values.value;+ const setValueFieldError = (message: string) =>+ setFieldError("value", message);++ if (!value) {+ setValueFieldError(t("required"));+ return;+ }+ try {+ await onSubmit(value);+ onClose();+ } catch (e) {+ log.error(`Failed to submit input ${value}`, e);+ setValueFieldError(t("generic_error"));+ }+ },+ });++ return (+ <form onSubmit={formik.handleSubmit}>+ <TextField+ name="value"+ value={formik.values.value}+ onChange={formik.handleChange}+ type={"text"}+ fullWidth+ autoFocus+ margin="normal"+ hiddenLabel+ aria-label={t("name")}+ placeholder={t("name_placeholder")}+ disabled={formik.isSubmitting}+ error={!!formik.errors.value}+ // As an exception, we don't use an space character default here+ // since that skews dialog's look too much in the happy case.+ //+ // The downside is that there will be a layout shift on errors.+ helperText={formik.errors.value}+ />+ <Stack sx={{ mt: 1.5, gap: 1 }}>+ <LoadingButton+ fullWidth+ type="submit"+ loading={formik.isSubmitting}+ color="accent"+ >+ {t("add_photos_count", { count: uploadFileCount })}+ </LoadingButton>+ <FocusVisibleButton+ fullWidth+ color="secondary"+ onClick={onClose}+ >+ {t("cancel")}+ </FocusVisibleButton>+ </Stack>+ </form>+ );+};