Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

[web][photos] Refresh rename file dialog

AswinAsokb14a2f16f368
diff --git a/web/packages/base/components/SingleInputDialog.tsx b/web/packages/base/components/SingleInputDialog.tsx
index 713fbac962..33d8489a5a 100644
--- a/web/packages/base/components/SingleInputDialog.tsx
+++ b/web/packages/base/components/SingleInputDialog.tsx
@@ -50,16 +50,13 @@ export const SingleInputDialog: React.FC<SingleInputDialogProps> = ({
open={open}
onClose={onClose}
maxWidth={false}
- aria-labelledby={variant === "people" ? titleID : undefined}
+ aria-labelledby={titleID}
sx={sx}
slotProps={{ paper: { sx: v2PaperSx } }}
>
<Stack sx={{ p: "20px", gap: "20px" }}>
<Stack direction="row" sx={v2HeaderRowSx}>
- <Typography
- id={variant === "people" ? titleID : undefined}
- sx={v2TitleSx}
- >
+ <Typography id={titleID} sx={v2TitleSx}>
{title}
</Typography>
<IconButton
diff --git a/web/packages/base/components/SingleInputForm.tsx b/web/packages/base/components/SingleInputForm.tsx
index c7a62d1622..b111704046 100644
--- a/web/packages/base/components/SingleInputForm.tsx
+++ b/web/packages/base/components/SingleInputForm.tsx
@@ -26,9 +26,16 @@ import { ShowHidePasswordInputAdornment } from "./mui/PasswordInputAdornment";
export type SingleInputFormProps = Pick<
TextFieldProps,
- "label" | "placeholder" | "autoComplete" | "autoFocus" | "slotProps"
+ | "label"
+ | "placeholder"
+ | "autoComplete"
+ | "autoFocus"
+ | "slotProps"
+ | "helperText"
> & {
variant?: "default" | "v2" | "people";
+ endAdornment?: React.ReactNode;
+ selectOnFocus?: boolean;
inputType?: TextFieldProps["type"];
initialValue?: string;
submitButtonColor?: ButtonProps["color"];
@@ -48,6 +55,9 @@ export const SingleInputForm: React.FC<SingleInputFormProps> = ({
inputType,
initialValue,
autoFocus,
+ endAdornment,
+ selectOnFocus,
+ helperText,
submitButtonTitle,
submitButtonColor,
onCancel,
@@ -104,10 +114,18 @@ export const SingleInputForm: React.FC<SingleInputFormProps> = ({
)}
<InputBase
id={inputID}
- aria-describedby={error ? helperID : undefined}
+ aria-describedby={
+ error || helperText ? helperID : undefined
+ }
+ inputProps={{ "aria-invalid": !!error }}
name="value"
value={formik.values.value}
onChange={formik.handleChange}
+ onFocus={
+ selectOnFocus
+ ? (event) => event.target.select()
+ : undefined
+ }
type={showPassword ? "text" : (inputType ?? "text")}
placeholder={rest.placeholder}
autoComplete={rest.autoComplete}
@@ -121,7 +139,9 @@ export const SingleInputForm: React.FC<SingleInputFormProps> = ({
showPassword={showPassword}
onToggle={handleToggleShowHidePassword}
/>
- ) : undefined
+ ) : (
+ endAdornment
+ )
}
/>
<Typography
@@ -129,7 +149,7 @@ export const SingleInputForm: React.FC<SingleInputFormProps> = ({
aria-live="polite"
sx={v2HelperSx(!!error)}
>
- {error ?? ""}
+ {error ?? helperText ?? ""}
</Typography>
</Stack>
<Stack direction="row" sx={{ gap: "12px" }}>
@@ -185,7 +205,7 @@ export const SingleInputForm: React.FC<SingleInputFormProps> = ({
disabled={formik.isSubmitting}
error={!!formik.errors.value}
// The space reserves helper-text height before an error appears.
- helperText={formik.errors.value ?? " "}
+ helperText={formik.errors.value ?? helperText ?? " "}
slotProps={{
input:
inputType == "password"
diff --git a/web/packages/base/locales/en-US/translation.json b/web/packages/base/locales/en-US/translation.json
index f9a730fd7a..dbefcabd3c 100644
--- a/web/packages/base/locales/en-US/translation.json
+++ b/web/packages/base/locales/en-US/translation.json
@@ -568,6 +568,7 @@
"info": "Info",
"comments": "comments",
"file_name": "File name",
+ "file_extension_unchanged": "The file extension stays the same",
"caption_placeholder": "Add a description",
"location": "Location",
"view_on_map": "View on OpenStreetMap",
diff --git a/web/packages/gallery/components/FileInfo.tsx b/web/packages/gallery/components/FileInfo.tsx
index fd8d614c2d..4f367c776c 100644
--- a/web/packages/gallery/components/FileInfo.tsx
+++ b/web/packages/gallery/components/FileInfo.tsx
@@ -22,11 +22,7 @@ import {
Box,
Button,
CircularProgress,
- Dialog,
- DialogContent,
- DialogTitle,
IconButton,
- InputAdornment,
Link,
Stack,
styled,
@@ -42,18 +38,17 @@ import {
SidebarDrawer,
SidebarDrawerTitlebar,
} from "ente-base/components/mui/SidebarDrawer";
-import { SingleInputForm } from "ente-base/components/SingleInputForm";
import { EllipsizedTypography } from "ente-base/components/Typography";
import {
useModalVisibility,
type ModalVisibilityProps,
} from "ente-base/components/utils/modal";
import { useBaseContext } from "ente-base/context";
-import { nameAndExtension } from "ente-base/file-name";
import { formattedDate, formattedTime } from "ente-base/i18n-date";
import log from "ente-base/log";
import type { Location } from "ente-base/types";
import { CopyButton } from "ente-gallery/components/FileInfoComponents";
+import { RenameFileDialog } from "ente-gallery/components/RenameFileDialog";
import { tagNumericValue, type RawExifTags } from "ente-gallery/services/exif";
import { getLeafletWithDefaultIcons } from "ente-gallery/utils/leaflet";
import { formattedByteSize } from "ente-gallery/utils/units";
@@ -1119,57 +1114,6 @@ const createMultipartCaption = (
</Stack>
);
-type RenameFileDialogProps = ModalVisibilityProps & {
- fileName: string;
- onRename: (newFileName: string) => Promise<void>;
-};
-
-const RenameFileDialog: React.FC<RenameFileDialogProps> = ({
- open,
- onClose,
- fileName,
- onRename,
-}) => {
- const [name, extension] = nameAndExtension(fileName);
-
- const handleSubmit = async (newName: string) => {
- const newFileName = [newName, extension].filter((x) => !!x).join(".");
- if (newFileName != fileName) {
- await onRename(newFileName);
- }
- onClose();
- };
-
- return (
- <Dialog {...{ open, onClose }} fullWidth maxWidth="xs">
- <DialogTitle sx={{ "&&&": { paddingBlock: "26px 0px" } }}>
- {t("rename_file")}
- </DialogTitle>
- <DialogContent>
- <SingleInputForm
- label={t("file_name")}
- placeholder={t("file_name")}
- initialValue={name}
- submitButtonColor="primary"
- submitButtonTitle={t("rename")}
- onSubmit={handleSubmit}
- onCancel={onClose}
- slotProps={{
- input: {
- sx: { alignItems: "baseline" },
- endAdornment: extension && (
- <InputAdornment position="end">
- {`.${extension}`}
- </InputAdornment>
- ),
- },
- }}
- />
- </DialogContent>
- </Dialog>
- );
-};
-
const openStreetMapLink = ({ latitude, longitude }: Location) =>
`https://www.openstreetmap.org/?mlat=${latitude}&mlon=${longitude}#map=15/${latitude}/${longitude}`;
diff --git a/web/packages/gallery/components/RenameFileDialog.tsx b/web/packages/gallery/components/RenameFileDialog.tsx
new file mode 100644
index 0000000000..b59204acaf
--- /dev/null
+++ b/web/packages/gallery/components/RenameFileDialog.tsx
@@ -0,0 +1,58 @@
+import { Box, InputAdornment } from "@mui/material";
+import { SingleInputDialog } from "ente-base/components/SingleInputDialog";
+import type { ModalVisibilityProps } from "ente-base/components/utils/modal";
+import { nameAndExtension } from "ente-base/file-name";
+import { t } from "i18next";
+
+type RenameFileDialogProps = ModalVisibilityProps & {
+ fileName: string;
+ onRename: (newFileName: string) => Promise<void>;
+};
+
+export const RenameFileDialog: React.FC<RenameFileDialogProps> = ({
+ open,
+ onClose,
+ fileName,
+ onRename,
+}) => {
+ const [name, extension] = nameAndExtension(fileName);
+
+ return (
+ <SingleInputDialog
+ {...{ open, onClose }}
+ variant="v2"
+ title={t("rename_file")}
+ label={t("file_name")}
+ placeholder={t("file_name")}
+ initialValue={name}
+ selectOnFocus
+ submitButtonTitle={t("rename")}
+ helperText={extension ? t("file_extension_unchanged") : undefined}
+ endAdornment={
+ extension && (
+ <InputAdornment position="end">
+ <Box
+ component="span"
+ sx={{
+ fontSize: 13,
+ color: "text.muted",
+ borderLeft: "1px solid",
+ borderColor: "divider",
+ pl: 1.5,
+ ml: 1,
+ }}
+ >
+ {`.${extension}`}
+ </Box>
+ </InputAdornment>
+ )
+ }
+ onSubmit={async (newName) => {
+ const newFileName = [newName, extension]
+ .filter(Boolean)
+ .join(".");
+ if (newFileName !== fileName) await onRename(newFileName);
+ }}
+ />
+ );
+};