Skip to content

armgit / ente

Public Imported from GitHub
0

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

feat(FileViewer):arrow-navigation-with-info

Aswin Asok102a6a27268b
diff --git a/web/packages/base/locales/en-US/translation.json b/web/packages/base/locales/en-US/translation.json
index 3fa9ec208a..45ab8aa6b2 100644
--- a/web/packages/base/locales/en-US/translation.json
+++ b/web/packages/base/locales/en-US/translation.json
@@ -362,6 +362,7 @@
"details": "Details",
"view_exif": "View all Exif data",
"no_exif": "No Exif data",
+ "file_info_arrow_navigation_hint": "Use the left and right arrow keys to move between photos without closing this panel.",
"exif": "Exif",
"two_factor": "Two-factor",
"two_factor_authentication": "Two-factor authentication",
diff --git a/web/packages/gallery/components/FileInfo.tsx b/web/packages/gallery/components/FileInfo.tsx
index f2f2477515..19513b7fe1 100644
--- a/web/packages/gallery/components/FileInfo.tsx
+++ b/web/packages/gallery/components/FileInfo.tsx
@@ -183,6 +183,11 @@ export type FileInfoProps = ModalVisibilityProps & {
* Called when the user selects a person in the file info panel.
*/
onSelectPerson?: (personID: string) => void;
+ /**
+ * Called when an edit surface owned by the file info panel is opened or
+ * closed, so the viewer can avoid navigating to another file underneath it.
+ */
+ onNavigationLockChange?: (locked: boolean) => void;
};
export const FileInfo: React.FC<FileInfoProps> = ({
@@ -199,6 +204,7 @@ export const FileInfo: React.FC<FileInfoProps> = ({
onUpdateCaption,
onSelectCollection,
onSelectPerson,
+ onNavigationLockChange,
}) => {
const { mapEnabled } = useSettingsSnapshot();
const peopleState = usePeopleStateSnapshot();
@@ -213,6 +219,12 @@ export const FileInfo: React.FC<FileInfoProps> = ({
const { show: showEditLocation, props: editLocationVisibilityProps } =
useModalVisibility();
+ const [captionNavigationLocked, setCaptionNavigationLocked] =
+ useState(false);
+ const [dateTimeNavigationLocked, setDateTimeNavigationLocked] =
+ useState(false);
+ const [renameNavigationLocked, setRenameNavigationLocked] = useState(false);
+
const assignablePeople = useMemo(
() =>
(peopleState?.visiblePeople ?? []).filter(
@@ -303,6 +315,19 @@ export const FileInfo: React.FC<FileInfoProps> = ({
const uploaderName = file.pubMagicMetadata?.data.uploaderName;
+ const navigationLocked =
+ open &&
+ (rawExifVisibilityProps.open ||
+ assignPersonVisibilityProps.open ||
+ editLocationVisibilityProps.open ||
+ captionNavigationLocked ||
+ dateTimeNavigationLocked ||
+ renameNavigationLocked);
+
+ useEffect(() => {
+ onNavigationLockChange?.(navigationLocked);
+ }, [onNavigationLockChange, navigationLocked]);
+
return (
<FileInfoSidebar {...{ open, onClose }}>
<SidebarDrawerTitlebar
@@ -318,15 +343,24 @@ export const FileInfo: React.FC<FileInfoProps> = ({
onFileMetadataUpdate,
onUpdateCaption,
onClose,
+ onNavigationLockChange: setCaptionNavigationLocked,
+ }}
+ />
+ <CreationTime
+ {...{
+ file,
+ allowEdits,
+ onFileMetadataUpdate,
+ onNavigationLockChange: setDateTimeNavigationLocked,
}}
/>
- <CreationTime {...{ file, allowEdits, onFileMetadataUpdate }} />
<FileName
{...{
file,
annotatedExif,
allowEdits,
onFileMetadataUpdate,
+ onNavigationLockChange: setRenameNavigationLocked,
}}
/>
@@ -457,6 +491,20 @@ export const FileInfo: React.FC<FileInfoProps> = ({
{t("added_by_name", { name: uploaderName })}
</Typography>
)}
+ <Typography
+ variant="small"
+ sx={{
+ display: { xs: "none", sm: "block" },
+ px: 2,
+ color: "text.muted",
+ opacity: 0.3,
+ maxWidth: "300px",
+ fontSize: "12px",
+ lineHeight: "15px",
+ }}
+ >
+ {t("file_info_arrow_navigation_hint")}
+ </Typography>
</Stack>
<RawExif
{...rawExifVisibilityProps}
@@ -655,6 +703,7 @@ type CaptionProps = Pick<
| "onFileMetadataUpdate"
| "onUpdateCaption"
| "onClose"
+ | "onNavigationLockChange"
>;
const Caption: React.FC<CaptionProps> = ({
@@ -663,6 +712,7 @@ const Caption: React.FC<CaptionProps> = ({
onFileMetadataUpdate,
onUpdateCaption,
onClose,
+ onNavigationLockChange,
}) => {
const [isSaving, setIsSaving] = useState(false);
@@ -670,6 +720,7 @@ const Caption: React.FC<CaptionProps> = ({
const formik = useFormik<{ caption: string }>({
initialValues: { caption },
+ enableReinitialize: true,
validate: ({ caption }) =>
caption.length > 5000
? { caption: t("caption_character_limit") }
@@ -693,6 +744,10 @@ const Caption: React.FC<CaptionProps> = ({
const { values, errors, handleChange, handleSubmit, resetForm } = formik;
+ useEffect(() => {
+ onNavigationLockChange?.(values.caption != caption || isSaving);
+ }, [onNavigationLockChange, values.caption, caption, isSaving]);
+
if (!caption.length && !allowEdits) {
// Visually take up some space, otherwise the info panel for the shared
// photos without a caption looks squished at the top.
@@ -746,13 +801,14 @@ const CaptionForm = styled("form")(({ theme }) => ({
type CreationTimeProps = Pick<
FileInfoProps,
- "allowEdits" | "onFileMetadataUpdate"
+ "allowEdits" | "onFileMetadataUpdate" | "onNavigationLockChange"
> & { file: EnteFile };
const CreationTime: React.FC<CreationTimeProps> = ({
file,
allowEdits,
onFileMetadataUpdate,
+ onNavigationLockChange,
}) => {
const { onGenericError } = useBaseContext();
@@ -761,6 +817,10 @@ const CreationTime: React.FC<CreationTimeProps> = ({
const originalDate = fileCreationPhotoDate(file);
+ useEffect(() => {
+ onNavigationLockChange?.(isEditing || isSaving);
+ }, [onNavigationLockChange, isEditing, isSaving]);
+
const saveEdits = async (pickedTime: ParsedMetadataDate) => {
setIsEditing(false);
@@ -819,7 +879,7 @@ const CreationTime: React.FC<CreationTimeProps> = ({
type FileNameProps = Pick<
FileInfoProps,
- "allowEdits" | "onFileMetadataUpdate"
+ "allowEdits" | "onFileMetadataUpdate" | "onNavigationLockChange"
> & { file: EnteFile; annotatedExif: AnnotatedExif | undefined };
const FileName: React.FC<FileNameProps> = ({
@@ -827,10 +887,15 @@ const FileName: React.FC<FileNameProps> = ({
annotatedExif,
allowEdits,
onFileMetadataUpdate,
+ onNavigationLockChange,
}) => {
const { show: showRename, props: renameVisibilityProps } =
useModalVisibility();
+ useEffect(() => {
+ onNavigationLockChange?.(renameVisibilityProps.open);
+ }, [onNavigationLockChange, renameVisibilityProps.open]);
+
const fileName = fileFileName(file);
const handleRename = async (newFileName: string) => {
diff --git a/web/packages/gallery/components/viewer/FileViewer.tsx b/web/packages/gallery/components/viewer/FileViewer.tsx
index 64b393fe96..57cd001d9c 100644
--- a/web/packages/gallery/components/viewer/FileViewer.tsx
+++ b/web/packages/gallery/components/viewer/FileViewer.tsx
@@ -456,8 +456,23 @@ export const FileViewer: React.FC<FileViewerProps> = ({
const [activeFileExif, setActiveFileExif] = useState<
FileInfoExif | undefined
>(undefined);
+ const activeFileExifFileIDRef = useRef<number | undefined>(undefined);
+
+ const refreshActiveFileExif = useCallback((file: EnteFile) => {
+ const fileID = file.id;
+ activeFileExifFileIDRef.current = fileID;
+ setActiveFileExif(
+ fileInfoExifForFile(file, (exif) => {
+ if (activeFileExifFileIDRef.current == fileID) {
+ setActiveFileExif(exif);
+ }
+ }),
+ );
+ }, []);
const [openFileInfo, setOpenFileInfo] = useState(false);
+ const [fileInfoNavigationLocked, setFileInfoNavigationLocked] =
+ useState(false);
const [openComments, setOpenComments] = useState(false);
const [openLikes, setOpenLikes] = useState(false);
const [openLikeAlbumSelector, setOpenLikeAlbumSelector] = useState(false);
@@ -598,6 +613,7 @@ export const FileViewer: React.FC<FileViewerProps> = ({
return false;
});
setOpenFileInfo(false);
+ setFileInfoNavigationLocked(false);
setOpenComments(false);
setOpenLikes(false);
setOpenLikeAlbumSelector(false);
@@ -617,17 +633,22 @@ export const FileViewer: React.FC<FileViewerProps> = ({
const handleViewInfo = useCallback(
(annotatedFile: FileViewerAnnotatedFile) => {
- setActiveFileExif(
- fileInfoExifForFile(annotatedFile.file, (exif) =>
- setActiveFileExif(exif),
- ),
- );
+ refreshActiveFileExif(annotatedFile.file);
setOpenFileInfo(true);
},
- [],
+ [refreshActiveFileExif],
);
- const handleFileInfoClose = useCallback(() => setOpenFileInfo(false), []);
+ useEffect(() => {
+ if (openFileInfo && activeAnnotatedFile) {
+ refreshActiveFileExif(activeAnnotatedFile.file);
+ }
+ }, [activeAnnotatedFile, openFileInfo, refreshActiveFileExif]);
+
+ const handleFileInfoClose = useCallback(() => {
+ setOpenFileInfo(false);
+ setFileInfoNavigationLocked(false);
+ }, []);
const handleViewComments = useCallback(() => setOpenComments(true), []);
@@ -1513,10 +1534,20 @@ export const FileViewer: React.FC<FileViewerProps> = ({
const handleShortcutsClose = useCallback(() => setOpenShortcuts(false), []);
- const shouldIgnoreKeyboardEvent = useCallback(() => {
+ const shouldIgnoreKeyboardEvent = useCallback((event: KeyboardEvent) => {
+ // Allow the file info drawer itself to pass through plain slide arrows.
+ const shouldAllowFileInfoArrowNavigation =
+ openFileInfo &&
+ !fileInfoNavigationLocked &&
+ !event.shiftKey &&
+ !event.metaKey &&
+ !event.ctrlKey &&
+ !event.altKey &&
+ (event.key == "ArrowLeft" || event.key == "ArrowRight");
+
// Don't handle keydowns if any of the viewer's own modals are open.
if (
- openFileInfo ||
+ (openFileInfo && !shouldAllowFileInfoArrowNavigation) ||
openComments ||
openLikes ||
openLikeAlbumSelector ||
@@ -1549,6 +1580,7 @@ export const FileViewer: React.FC<FileViewerProps> = ({
return false;
}, [
openFileInfo,
+ fileInfoNavigationLocked,
openComments,
openLikes,
openLikeAlbumSelector,
@@ -2113,6 +2145,7 @@ export const FileViewer: React.FC<FileViewerProps> = ({
onUpdateCaption={handleUpdateCaption}
onSelectCollection={handleSelectCollection}
onSelectPerson={handleSelectPerson}
+ onNavigationLockChange={setFileInfoNavigationLocked}
{...{ collectionNameByID }}
/>
<CommentsSidebar
diff --git a/web/packages/gallery/components/viewer/photoswipe.ts b/web/packages/gallery/components/viewer/photoswipe.ts
index 6de253889a..65f2e7c23f 100644
--- a/web/packages/gallery/components/viewer/photoswipe.ts
+++ b/web/packages/gallery/components/viewer/photoswipe.ts
@@ -97,10 +97,10 @@ export interface FileViewerPhotoSwipeDelegate {
* Called when there is a keydown event, and our PhotoSwipe instance wants
* to know if it should ignore it or handle it.
*
- * The delegate should return true when, e.g., the file info dialog is
- * being displayed.
+ * The delegate should return true when it wants the keyboard event ignored,
+ * e.g. for most keys while a viewer dialog is being displayed.
*/
- shouldIgnoreKeyboardEvent: () => boolean;
+ shouldIgnoreKeyboardEvent: (event: KeyboardEvent) => boolean;
/**
* Called when the user triggers a potential action using a keyboard
* shortcut.
@@ -1819,14 +1819,14 @@ export class FileViewerPhotoSwipe {
const handleHelp = () => delegate.performKeyAction("help");
pswp.on("keydown", (pswpEvent) => {
+ const e: KeyboardEvent = pswpEvent.originalEvent;
+
// Ignore keyboard events when one of our sub-dialogs are open.
- if (delegate.shouldIgnoreKeyboardEvent()) {
+ if (delegate.shouldIgnoreKeyboardEvent(e)) {
pswpEvent.preventDefault();
return;
}
- const e: KeyboardEvent = pswpEvent.originalEvent;
-
const key = e.key;
// Even though we ignore shift, Caps lock might still be on.
const lkey = e.key.toLowerCase();