Pass directly

This commit is contained in:
Manav Rathi
2025-07-07 16:08:43 +05:30
parent bcd5ca7bf5
commit f1cc16ddae
5 changed files with 74 additions and 109 deletions

View File

@@ -245,12 +245,6 @@ export const FileList: React.FC<FileListProps> = ({
if (header) {
timeStampList.push(asFullSpanListItem(header));
} else if (publicCollectionGalleryContext.photoListHeader) {
timeStampList.push(
getPhotoListHeader(
publicCollectionGalleryContext.photoListHeader,
),
);
}
if (isMagicSearchResult) {
noGrouping(timeStampList);
@@ -267,19 +261,14 @@ export const FileList: React.FC<FileListProps> = ({
timeStampList.push(getVacuumItem(timeStampList));
if (footer) {
timeStampList.push(asFullSpanListItem(footer));
} else if (publicCollectionGalleryContext.credentials) {
if (publicCollectionGalleryContext.photoListFooter) {
timeStampList.push(
getPhotoListFooter(
publicCollectionGalleryContext.photoListFooter,
),
);
}
timeStampList.push(getAlbumsFooter());
} else if (showAppDownloadBanner) {
timeStampList.push(getAppDownloadFooter());
}
if (publicCollectionGalleryContext.credentials) {
timeStampList.push(getAlbumsFooter());
}
setTimeStampList(timeStampList);
refreshInProgress.current = false;
if (shouldRefresh.current) {
@@ -293,8 +282,9 @@ export const FileList: React.FC<FileListProps> = ({
height,
annotatedFiles,
header,
publicCollectionGalleryContext.photoListHeader,
footer,
isMagicSearchResult,
publicCollectionGalleryContext.credentials,
]);
useEffect(() => {
@@ -354,28 +344,6 @@ export const FileList: React.FC<FileListProps> = ({
});
};
const getPhotoListHeader = (photoListHeader) => {
return {
...photoListHeader,
item: (
<ListItemContainer span={columns}>
{photoListHeader.item}
</ListItemContainer>
),
};
};
const getPhotoListFooter = (photoListFooter) => {
return {
...photoListFooter,
item: (
<ListItemContainer span={columns}>
{photoListFooter.item}
</ListItemContainer>
),
};
};
const getEmptyListItem = () => {
return {
item: (

View File

@@ -57,6 +57,7 @@ export type FileListWithViewerProps = {
| "mode"
| "modePlus"
| "header"
| "footer"
| "showAppDownloadBanner"
| "isMagicSearchResult"
| "selectable"
@@ -93,6 +94,7 @@ export const FileListWithViewer: React.FC<FileListWithViewerProps> = ({
mode,
modePlus,
header,
footer,
user,
files,
enableDownload,
@@ -182,6 +184,7 @@ export const FileListWithViewer: React.FC<FileListWithViewerProps> = ({
mode,
modePlus,
header,
footer,
user,
showAppDownloadBanner,
isMagicSearchResult,

View File

@@ -180,23 +180,23 @@ const Page: React.FC = () => {
const [fixCreationTimeFiles, setFixCreationTimeFiles] = useState<
EnteFile[]
>([]);
// The (non-sticky) header shown at the top of the gallery items.
const [fileListHeader, setFileListHeader] = useState<
TimeStampListItem | undefined
>(undefined);
const [openCollectionSelector, setOpenCollectionSelector] = useState(false);
const [collectionSelectorAttributes, setCollectionSelectorAttributes] =
useState<CollectionSelectorAttributes | undefined>();
const userDetails = useUserDetailsSnapshot();
const peopleState = usePeopleStateSnapshot();
// The (non-sticky) header shown at the top of the gallery items.
const [photoListHeader, setPhotoListHeader] =
useState<TimeStampListItem>(null);
const { saveGroups, onAddSaveGroup, onRemoveSaveGroup } = useSaveGroups();
const [, setPostCreateAlbumOp] = useState<CollectionOp | undefined>(
undefined,
);
const [openCollectionSelector, setOpenCollectionSelector] = useState(false);
const [collectionSelectorAttributes, setCollectionSelectorAttributes] =
useState<CollectionSelectorAttributes | undefined>();
/**
* The last time (epoch milliseconds) when we prompted the user for their
* password when opening the hidden section.
@@ -408,7 +408,7 @@ const Page: React.FC = () => {
useEffect(() => {
if (isInSearchMode && state.searchSuggestion) {
setPhotoListHeader({
setFileListHeader({
height: 104,
item: (
<SearchResultsHeader
@@ -1072,7 +1072,7 @@ const Page: React.FC = () => {
activeCollection,
activeCollectionID,
activePerson,
setPhotoListHeader,
setPhotoListHeader: setFileListHeader,
saveGroups,
onAddSaveGroup,
}}
@@ -1147,7 +1147,7 @@ const Page: React.FC = () => {
<FileListWithViewer
mode={barMode}
modePlus={isInSearchMode ? "search" : barMode}
header={photoListHeader}
header={fileListHeader}
user={user}
files={filteredFiles}
enableDownload={true}

View File

@@ -1,5 +1,4 @@
// TODO: Audit this file
/* eslint-disable @typescript-eslint/no-unused-expressions */
import AddPhotoAlternateOutlinedIcon from "@mui/icons-material/AddPhotoAlternateOutlined";
import CloseIcon from "@mui/icons-material/Close";
import DownloadIcon from "@mui/icons-material/Download";
@@ -7,7 +6,6 @@ import FileDownloadOutlinedIcon from "@mui/icons-material/FileDownloadOutlined";
import { Box, Button, IconButton, Stack, styled, Tooltip } from "@mui/material";
import Typography from "@mui/material/Typography";
import { DownloadStatusNotifications } from "components/DownloadStatusNotifications";
import type { TimeStampListItem } from "components/FileList";
import { FileListWithViewer } from "components/FileListWithViewer";
import { Upload } from "components/Upload";
import {
@@ -94,10 +92,6 @@ export default function PublicCollectionGallery() {
const { showMiniDialog, onGenericError } = useBaseContext();
const { showLoadingBar, hideLoadingBar } = usePhotosAppContext();
const credentials = useRef<PublicAlbumsCredentials | undefined>(undefined);
const collectionKey = useRef<string>(null);
const url = useRef<string>(null);
const referralCode = useRef<string>("");
const [publicCollection, setPublicCollection] = useState<
Collection | undefined
>(undefined);
@@ -107,15 +101,6 @@ export default function PublicCollectionGallery() {
const [errorMessage, setErrorMessage] = useState<string>(null);
const [loading, setLoading] = useState(true);
const [isPasswordProtected, setIsPasswordProtected] = useState(false);
const router = useRouter();
const [photoListHeader, setPhotoListHeader] =
useState<TimeStampListItem>(null);
const [photoListFooter, setPhotoListFooter] =
useState<TimeStampListItem>(null);
const [uploadTypeSelectorView, setUploadTypeSelectorView] = useState(false);
const [blockingLoad, setBlockingLoad] = useState(false);
const [shouldDisableDropzone, setShouldDisableDropzone] = useState(false);
@@ -128,17 +113,15 @@ export default function PublicCollectionGallery() {
collectionID: 0,
context: undefined,
});
const credentials = useRef<PublicAlbumsCredentials | undefined>(undefined);
const collectionKey = useRef<string>(null);
const url = useRef<string>(null);
const referralCode = useRef<string>("");
const { saveGroups, onAddSaveGroup, onRemoveSaveGroup } = useSaveGroups();
const onAddPhotos = useMemo(() => {
return publicCollection?.publicURLs[0]?.enableCollect
? () => setUploadTypeSelectorView(true)
: undefined;
}, [publicCollection]);
const closeUploadTypeSelectorView = () => {
setUploadTypeSelectorView(false);
};
const router = useRouter();
const showPublicLinkExpiredMessage = () =>
showMiniDialog({
@@ -229,35 +212,6 @@ export default function PublicCollectionGallery() {
const downloadEnabled =
publicCollection?.publicURLs?.[0]?.enableDownload ?? true;
useEffect(() => {
publicCollection &&
publicFiles &&
setPhotoListHeader({
item: (
<ListHeader
{...{ publicCollection, publicFiles, onAddSaveGroup }}
/>
),
tag: "header",
height: 68,
});
}, [publicCollection, publicFiles]);
useEffect(() => {
setPhotoListFooter(
onAddPhotos
? {
item: (
<CenteredFill sx={{ marginTop: "56px" }}>
<AddMorePhotosButton onClick={onAddPhotos} />
</CenteredFill>
),
height: 104,
}
: null,
);
}, [onAddPhotos]);
/**
* Pull the latest data related to the public album from remote, updating
* both our local database and component state.
@@ -421,6 +375,51 @@ export default function PublicCollectionGallery() {
}
};
const onAddPhotos = useMemo(() => {
return publicCollection?.publicURLs[0]?.enableCollect
? () => setUploadTypeSelectorView(true)
: undefined;
}, [publicCollection]);
const closeUploadTypeSelectorView = () => {
setUploadTypeSelectorView(false);
};
const fileListHeader = useMemo(
() =>
publicCollection && publicFiles
? {
item: (
<ListHeader
{...{
publicCollection,
publicFiles,
onAddSaveGroup,
}}
/>
),
tag: "header" as const,
height: 68,
}
: undefined,
[onAddSaveGroup, publicCollection, publicFiles],
);
const fileListFooter = useMemo(
() =>
onAddPhotos
? {
item: (
<CenteredFill sx={{ marginTop: "56px" }}>
<AddMorePhotosButton onClick={onAddPhotos} />
</CenteredFill>
),
height: 104,
}
: undefined,
[onAddPhotos],
);
if (loading && (!publicFiles || !credentials.current)) {
return <LoadingIndicator />;
} else if (errorMessage) {
@@ -464,8 +463,6 @@ export default function PublicCollectionGallery() {
const context = {
credentials: credentials.current,
referralCode: referralCode.current,
photoListHeader,
photoListFooter,
};
return (
@@ -503,6 +500,8 @@ export default function PublicCollectionGallery() {
<FileListWithViewer
files={publicFiles}
header={fileListHeader}
footer={fileListFooter}
enableDownload={downloadEnabled}
selectable={downloadEnabled}
selected={selected}

View File

@@ -1,4 +1,3 @@
import type { TimeStampListItem } from "components/FileList";
import type { PublicAlbumsCredentials } from "ente-base/http";
import { createContext } from "react";
@@ -10,14 +9,10 @@ export interface PublicCollectionGalleryContextType {
*/
credentials: PublicAlbumsCredentials | undefined;
referralCode: string | null;
photoListHeader: TimeStampListItem;
photoListFooter: TimeStampListItem;
}
export const PublicCollectionGalleryContext =
createContext<PublicCollectionGalleryContextType>({
credentials: undefined,
referralCode: null,
photoListHeader: null,
photoListFooter: null,
});