mirror of
https://github.com/ente-io/ente.git
synced 2025-08-13 01:27:17 +00:00
Uncontext
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import log from "@/base/log";
|
import log from "@/base/log";
|
||||||
|
import type { FileInfoProps } from "@/gallery/components/FileInfo";
|
||||||
import {
|
import {
|
||||||
downloadManager,
|
downloadManager,
|
||||||
type LivePhotoSourceURL,
|
type LivePhotoSourceURL,
|
||||||
@@ -11,7 +12,7 @@ import { FileViewer } from "@/new/photos/components/FileViewerComponents";
|
|||||||
import type { GalleryBarMode } from "@/new/photos/components/gallery/reducer";
|
import type { GalleryBarMode } from "@/new/photos/components/gallery/reducer";
|
||||||
import { TRASH_SECTION } from "@/new/photos/services/collection";
|
import { TRASH_SECTION } from "@/new/photos/services/collection";
|
||||||
import { styled } from "@mui/material";
|
import { styled } from "@mui/material";
|
||||||
import { PhotoViewer, type PhotoViewerProps } from "components/PhotoViewer";
|
import { PhotoViewer } from "components/PhotoViewer";
|
||||||
import { useRouter } from "next/router";
|
import { useRouter } from "next/router";
|
||||||
import { GalleryContext } from "pages/gallery";
|
import { GalleryContext } from "pages/gallery";
|
||||||
import PhotoSwipe from "photoswipe";
|
import PhotoSwipe from "photoswipe";
|
||||||
@@ -67,7 +68,13 @@ export type DisplayFile = EnteFile & {
|
|||||||
canForceConvert?: boolean;
|
canForceConvert?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
export interface PhotoFrameProps {
|
export type PhotoFrameProps = Pick<
|
||||||
|
FileInfoProps,
|
||||||
|
| "fileCollectionIDs"
|
||||||
|
| "allCollectionsNameByID"
|
||||||
|
| "onSelectCollection"
|
||||||
|
| "onSelectPerson"
|
||||||
|
> & {
|
||||||
mode?: GalleryBarMode;
|
mode?: GalleryBarMode;
|
||||||
/**
|
/**
|
||||||
* This is an experimental prop, to see if we can merge the separate
|
* This is an experimental prop, to see if we can merge the separate
|
||||||
@@ -112,15 +119,12 @@ export interface PhotoFrameProps {
|
|||||||
/** This will be set if mode is "people". */
|
/** This will be set if mode is "people". */
|
||||||
activePersonID?: string | undefined;
|
activePersonID?: string | undefined;
|
||||||
enableDownload?: boolean;
|
enableDownload?: boolean;
|
||||||
fileCollectionIDs?: Map<number, number[]>;
|
|
||||||
allCollectionsNameByID?: Map<number, string>;
|
|
||||||
showAppDownloadBanner?: boolean;
|
showAppDownloadBanner?: boolean;
|
||||||
setIsPhotoSwipeOpen?: (value: boolean) => void;
|
setIsPhotoSwipeOpen?: (value: boolean) => void;
|
||||||
isInHiddenSection?: boolean;
|
isInHiddenSection?: boolean;
|
||||||
setFilesDownloadProgressAttributesCreator?: SetFilesDownloadProgressAttributesCreator;
|
setFilesDownloadProgressAttributesCreator?: SetFilesDownloadProgressAttributesCreator;
|
||||||
selectable?: boolean;
|
selectable?: boolean;
|
||||||
onSelectPerson?: PhotoViewerProps["onSelectPerson"];
|
};
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO: Rename me to FileListWithViewer (or Gallery?)
|
* TODO: Rename me to FileListWithViewer (or Gallery?)
|
||||||
@@ -145,6 +149,7 @@ const PhotoFrame = ({
|
|||||||
isInHiddenSection,
|
isInHiddenSection,
|
||||||
setFilesDownloadProgressAttributesCreator,
|
setFilesDownloadProgressAttributesCreator,
|
||||||
selectable,
|
selectable,
|
||||||
|
onSelectCollection,
|
||||||
onSelectPerson,
|
onSelectPerson,
|
||||||
}: PhotoFrameProps) => {
|
}: PhotoFrameProps) => {
|
||||||
const [open, setOpen] = useState(false);
|
const [open, setOpen] = useState(false);
|
||||||
@@ -524,6 +529,12 @@ const PhotoFrame = ({
|
|||||||
onClose={handleClose}
|
onClose={handleClose}
|
||||||
files={files}
|
files={files}
|
||||||
initialIndex={currentIndex}
|
initialIndex={currentIndex}
|
||||||
|
{...{
|
||||||
|
fileCollectionIDs,
|
||||||
|
allCollectionsNameByID,
|
||||||
|
onSelectCollection,
|
||||||
|
onSelectPerson,
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
<AutoSizer>
|
<AutoSizer>
|
||||||
@@ -555,9 +566,10 @@ const PhotoFrame = ({
|
|||||||
favoriteFileIDs,
|
favoriteFileIDs,
|
||||||
markUnsyncedFavoriteUpdate,
|
markUnsyncedFavoriteUpdate,
|
||||||
markTempDeleted,
|
markTempDeleted,
|
||||||
allCollectionsNameByID,
|
|
||||||
fileCollectionIDs,
|
|
||||||
setFilesDownloadProgressAttributesCreator,
|
setFilesDownloadProgressAttributesCreator,
|
||||||
|
fileCollectionIDs,
|
||||||
|
allCollectionsNameByID,
|
||||||
|
onSelectCollection,
|
||||||
onSelectPerson,
|
onSelectPerson,
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
@@ -9,7 +9,7 @@ import {
|
|||||||
} from "@/base/components/utils/modal";
|
} from "@/base/components/utils/modal";
|
||||||
import { lowercaseExtension } from "@/base/file-name";
|
import { lowercaseExtension } from "@/base/file-name";
|
||||||
import log from "@/base/log";
|
import log from "@/base/log";
|
||||||
import { FileInfo, type FileInfoProps } from "@/gallery/components/FileInfo";
|
import { FileInfo } from "@/gallery/components/FileInfo";
|
||||||
import { type FileInfoExif } from "@/gallery/components/viewer/data-source";
|
import { type FileInfoExif } from "@/gallery/components/viewer/data-source";
|
||||||
import { downloadManager } from "@/gallery/services/download";
|
import { downloadManager } from "@/gallery/services/download";
|
||||||
import { extractRawExif, parseExif } from "@/gallery/services/exif";
|
import { extractRawExif, parseExif } from "@/gallery/services/exif";
|
||||||
@@ -76,7 +76,13 @@ import { PublicCollectionGalleryContext } from "utils/publicCollectionGallery";
|
|||||||
|
|
||||||
export type PhotoViewerProps = Pick<
|
export type PhotoViewerProps = Pick<
|
||||||
PhotoFrameProps,
|
PhotoFrameProps,
|
||||||
"favoriteFileIDs" | "markUnsyncedFavoriteUpdate" | "markTempDeleted"
|
| "favoriteFileIDs"
|
||||||
|
| "markUnsyncedFavoriteUpdate"
|
||||||
|
| "markTempDeleted"
|
||||||
|
| "fileCollectionIDs"
|
||||||
|
| "allCollectionsNameByID"
|
||||||
|
| "onSelectCollection"
|
||||||
|
| "onSelectPerson"
|
||||||
> & {
|
> & {
|
||||||
/**
|
/**
|
||||||
* The PhotoViewer is shown when this is `true`.
|
* The PhotoViewer is shown when this is `true`.
|
||||||
@@ -102,9 +108,6 @@ export type PhotoViewerProps = Pick<
|
|||||||
isInHiddenSection: boolean;
|
isInHiddenSection: boolean;
|
||||||
enableDownload: boolean;
|
enableDownload: boolean;
|
||||||
setFilesDownloadProgressAttributesCreator: SetFilesDownloadProgressAttributesCreator;
|
setFilesDownloadProgressAttributesCreator: SetFilesDownloadProgressAttributesCreator;
|
||||||
fileCollectionIDs?: Map<number, number[]>;
|
|
||||||
allCollectionsNameByID?: Map<number, string>;
|
|
||||||
onSelectPerson?: FileInfoProps["onSelectPerson"];
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -138,6 +141,7 @@ export const PhotoViewer: React.FC<PhotoViewerProps> = ({
|
|||||||
setFilesDownloadProgressAttributesCreator,
|
setFilesDownloadProgressAttributesCreator,
|
||||||
fileCollectionIDs,
|
fileCollectionIDs,
|
||||||
allCollectionsNameByID,
|
allCollectionsNameByID,
|
||||||
|
onSelectCollection,
|
||||||
onSelectPerson,
|
onSelectPerson,
|
||||||
}) => {
|
}) => {
|
||||||
const { showLoadingBar, hideLoadingBar } = usePhotosAppContext();
|
const { showLoadingBar, hideLoadingBar } = usePhotosAppContext();
|
||||||
@@ -733,7 +737,7 @@ export const PhotoViewer: React.FC<PhotoViewerProps> = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleSelectCollection = (collectionID: number) => {
|
const handleSelectCollection = (collectionID: number) => {
|
||||||
galleryContext.onShowCollection(collectionID);
|
onSelectCollection(collectionID);
|
||||||
handleClose();
|
handleClose();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -134,7 +134,6 @@ import { FILE_OPS_TYPE, getSelectedFiles, handleFileOps } from "utils/file";
|
|||||||
|
|
||||||
const defaultGalleryContext: GalleryContextType = {
|
const defaultGalleryContext: GalleryContextType = {
|
||||||
setActiveCollectionID: () => null,
|
setActiveCollectionID: () => null,
|
||||||
onShowCollection: () => null,
|
|
||||||
syncWithRemote: () => null,
|
syncWithRemote: () => null,
|
||||||
setBlockingLoad: () => null,
|
setBlockingLoad: () => null,
|
||||||
photoListHeader: null,
|
photoListHeader: null,
|
||||||
@@ -813,11 +812,6 @@ const Page: React.FC = () => {
|
|||||||
value={{
|
value={{
|
||||||
...defaultGalleryContext,
|
...defaultGalleryContext,
|
||||||
setActiveCollectionID: handleSetActiveCollectionID,
|
setActiveCollectionID: handleSetActiveCollectionID,
|
||||||
onShowCollection: (id) =>
|
|
||||||
dispatch({
|
|
||||||
type: "showNormalOrHiddenCollectionSummary",
|
|
||||||
collectionSummaryID: id,
|
|
||||||
}),
|
|
||||||
syncWithRemote,
|
syncWithRemote,
|
||||||
setBlockingLoad,
|
setBlockingLoad,
|
||||||
photoListHeader,
|
photoListHeader,
|
||||||
@@ -1046,6 +1040,12 @@ const Page: React.FC = () => {
|
|||||||
setFilesDownloadProgressAttributesCreator
|
setFilesDownloadProgressAttributesCreator
|
||||||
}
|
}
|
||||||
selectable={true}
|
selectable={true}
|
||||||
|
onSelectCollection={(collectionID) =>
|
||||||
|
dispatch({
|
||||||
|
type: "showNormalOrHiddenCollectionSummary",
|
||||||
|
collectionSummaryID: collectionID,
|
||||||
|
})
|
||||||
|
}
|
||||||
onSelectPerson={(personID) => {
|
onSelectPerson={(personID) => {
|
||||||
dispatch({ type: "showPerson", personID });
|
dispatch({ type: "showPerson", personID });
|
||||||
}}
|
}}
|
||||||
|
@@ -40,8 +40,6 @@ export interface MergedSourceURL {
|
|||||||
|
|
||||||
export interface GalleryContextType {
|
export interface GalleryContextType {
|
||||||
setActiveCollectionID: (collectionID: number) => void;
|
setActiveCollectionID: (collectionID: number) => void;
|
||||||
/** Newer and almost equivalent alternative to setActiveCollectionID. */
|
|
||||||
onShowCollection: (collectionID: number) => void;
|
|
||||||
syncWithRemote: (force?: boolean, silent?: boolean) => Promise<void>;
|
syncWithRemote: (force?: boolean, silent?: boolean) => Promise<void>;
|
||||||
setBlockingLoad: (value: boolean) => void;
|
setBlockingLoad: (value: boolean) => void;
|
||||||
photoListHeader: TimeStampListItem;
|
photoListHeader: TimeStampListItem;
|
||||||
|
@@ -124,8 +124,9 @@ export type FileInfoProps = ModalVisibilityProps & {
|
|||||||
* If set, then a clickable chip will be shown for each collection that this
|
* If set, then a clickable chip will be shown for each collection that this
|
||||||
* file is a part of.
|
* file is a part of.
|
||||||
*
|
*
|
||||||
* Uses {@link fileCollectionIDs} and {@link allCollectionsNameByID}, so
|
* Uses {@link fileCollectionIDs}, {@link allCollectionsNameByID} and
|
||||||
* both of those props should also be set for this to have an effect.
|
* {@link onSelectCollection}, so all of those props should also be set for
|
||||||
|
* this to have an effect.
|
||||||
*/
|
*/
|
||||||
showCollections?: boolean;
|
showCollections?: boolean;
|
||||||
/**
|
/**
|
||||||
@@ -146,11 +147,11 @@ export type FileInfoProps = ModalVisibilityProps & {
|
|||||||
* Called when the user selects a collection from among the collections that
|
* Called when the user selects a collection from among the collections that
|
||||||
* the file belongs to.
|
* the file belongs to.
|
||||||
*/
|
*/
|
||||||
onSelectCollection: (collectionID: number) => void;
|
onSelectCollection?: (collectionID: number) => void;
|
||||||
/**
|
/**
|
||||||
* Called when the user selects a person in the file info panel.
|
* Called when the user selects a person in the file info panel.
|
||||||
*/
|
*/
|
||||||
onSelectPerson?: ((personID: string) => void) | undefined;
|
onSelectPerson?: (personID: string) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const FileInfo: React.FC<FileInfoProps> = ({
|
export const FileInfo: React.FC<FileInfoProps> = ({
|
||||||
@@ -315,7 +316,8 @@ export const FileInfo: React.FC<FileInfoProps> = ({
|
|||||||
)}
|
)}
|
||||||
{showCollections &&
|
{showCollections &&
|
||||||
fileCollectionIDs &&
|
fileCollectionIDs &&
|
||||||
allCollectionsNameByID && (
|
allCollectionsNameByID &&
|
||||||
|
onSelectCollection && (
|
||||||
<InfoItem icon={<FolderOutlinedIcon />}>
|
<InfoItem icon={<FolderOutlinedIcon />}>
|
||||||
<Stack
|
<Stack
|
||||||
direction="row"
|
direction="row"
|
||||||
|
@@ -17,39 +17,48 @@ import {
|
|||||||
useModalVisibility,
|
useModalVisibility,
|
||||||
type ModalVisibilityProps,
|
type ModalVisibilityProps,
|
||||||
} from "@/base/components/utils/modal";
|
} from "@/base/components/utils/modal";
|
||||||
import { FileInfo } from "@/gallery/components/FileInfo";
|
import { FileInfo, type FileInfoProps } from "@/gallery/components/FileInfo";
|
||||||
import type { EnteFile } from "@/media/file.js";
|
import type { EnteFile } from "@/media/file.js";
|
||||||
import { Button, styled } from "@mui/material";
|
import { Button, styled } from "@mui/material";
|
||||||
import { useCallback, useEffect, useRef, useState } from "react";
|
import { useCallback, useEffect, useRef, useState } from "react";
|
||||||
import { fileInfoExifForFile, type FileInfoExif } from "./data-source";
|
import { fileInfoExifForFile, type FileInfoExif } from "./data-source";
|
||||||
import { FileViewerPhotoSwipe } from "./photoswipe";
|
import { FileViewerPhotoSwipe } from "./photoswipe";
|
||||||
|
|
||||||
export type FileViewerProps = ModalVisibilityProps & {
|
export type FileViewerProps = ModalVisibilityProps &
|
||||||
|
Pick<
|
||||||
|
FileInfoProps,
|
||||||
|
| "fileCollectionIDs"
|
||||||
|
| "allCollectionsNameByID"
|
||||||
|
| "onSelectCollection"
|
||||||
|
| "onSelectPerson"
|
||||||
|
> & {
|
||||||
/**
|
/**
|
||||||
* The list of files that are currently being displayed in the context in
|
* The list of files that are currently being displayed in the context
|
||||||
* which the file viewer was invoked.
|
* in which the file viewer was invoked.
|
||||||
*
|
*
|
||||||
* Although the file viewer is called on to display a particular file
|
* Although the file viewer is called on to display a particular file
|
||||||
* (specified by the {@link initialIndex} prop), the viewer is always used
|
* (specified by the {@link initialIndex} prop), the viewer is always
|
||||||
* in the context of a an album, or search results, or some other arbitrary
|
* used in the context of a an album, or search results, or some other
|
||||||
* list of files. The {@link files} prop sets this underlying list of files.
|
* arbitrary list of files. The {@link files} prop sets this underlying
|
||||||
|
* list of files.
|
||||||
*
|
*
|
||||||
* After the initial file has been shown, the user can navigate through the
|
* After the initial file has been shown, the user can navigate through
|
||||||
* other files from within the viewer by using the arrow buttons.
|
* the other files from within the viewer by using the arrow buttons.
|
||||||
*/
|
*/
|
||||||
files: EnteFile[];
|
files: EnteFile[];
|
||||||
/**
|
/**
|
||||||
* The index of the file that should be initially shown.
|
* The index of the file that should be initially shown.
|
||||||
*
|
*
|
||||||
* Subsequently the user may navigate between files by using the controls
|
* Subsequently the user may navigate between files by using the
|
||||||
* provided within the file viewer itself.
|
* controls provided within the file viewer itself.
|
||||||
*/
|
*/
|
||||||
initialIndex: number;
|
initialIndex: number;
|
||||||
/**
|
/**
|
||||||
* If true then the viewer does not show controls for downloading the file.
|
* If true then the viewer does not show controls for downloading the
|
||||||
|
* file.
|
||||||
*/
|
*/
|
||||||
disableDownload?: boolean;
|
disableDownload?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A PhotoSwipe based image and video viewer.
|
* A PhotoSwipe based image and video viewer.
|
||||||
@@ -60,6 +69,10 @@ const FileViewer: React.FC<FileViewerProps> = ({
|
|||||||
files,
|
files,
|
||||||
initialIndex,
|
initialIndex,
|
||||||
disableDownload,
|
disableDownload,
|
||||||
|
fileCollectionIDs,
|
||||||
|
allCollectionsNameByID,
|
||||||
|
onSelectCollection,
|
||||||
|
onSelectPerson,
|
||||||
}) => {
|
}) => {
|
||||||
const pswpRef = useRef<FileViewerPhotoSwipe | undefined>();
|
const pswpRef = useRef<FileViewerPhotoSwipe | undefined>();
|
||||||
|
|
||||||
@@ -93,6 +106,18 @@ const FileViewer: React.FC<FileViewerProps> = ({
|
|||||||
[showFileInfo],
|
[showFileInfo],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const handleSelectCollection = (collectionID: number) => {
|
||||||
|
onSelectCollection(collectionID);
|
||||||
|
onClose();
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleSelectPerson = onSelectPerson
|
||||||
|
? (personID: string) => {
|
||||||
|
onSelectPerson(personID);
|
||||||
|
onClose();
|
||||||
|
}
|
||||||
|
: undefined;
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!open) {
|
if (!open) {
|
||||||
// The close state will be handled by the cleanup function.
|
// The close state will be handled by the cleanup function.
|
||||||
@@ -136,6 +161,9 @@ const FileViewer: React.FC<FileViewerProps> = ({
|
|||||||
{...fileInfoVisibilityProps}
|
{...fileInfoVisibilityProps}
|
||||||
file={activeFile}
|
file={activeFile}
|
||||||
exif={activeFileExif}
|
exif={activeFileExif}
|
||||||
|
onSelectCollection={handleSelectCollection}
|
||||||
|
onSelectPerson={handleSelectPerson}
|
||||||
|
{...{ fileCollectionIDs, allCollectionsNameByID }}
|
||||||
/>
|
/>
|
||||||
</Container>
|
</Container>
|
||||||
);
|
);
|
||||||
|
Reference in New Issue
Block a user