Skip to content

armgit / ente

Public Imported from GitHub
0

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

Use

Manav Rathi71650df31ff9
diff --git a/web/apps/photos/src/components/Collections/CollectionShare.tsx b/web/apps/photos/src/components/Collections/CollectionShare.tsx
index d33e2e8a4c..a2bef017a3 100644
--- a/web/apps/photos/src/components/Collections/CollectionShare.tsx
+++ b/web/apps/photos/src/components/Collections/CollectionShare.tsx
@@ -16,7 +16,7 @@ import { Dialog, Stack, styled, Typography } from "@mui/material";
import NumberAvatar from "@mui/material/Avatar";
import TextField from "@mui/material/TextField";
import Avatar from "components/pages/gallery/Avatar";
-import { ensureLocalUser } from "ente-accounts/services/user";
+import { type LocalUser } from "ente-accounts/services/user";
import { LoadingButton } from "ente-base/components/mui/LoadingButton";
import {
SidebarDrawer,
@@ -75,10 +75,8 @@ import { CustomError, parseSharingErrorCodes } from "ente-shared/error";
import { wait } from "ente-utils/promise";
import { useFormik } from "formik";
import { t } from "i18next";
-import { GalleryContext } from "pages/gallery";
import React, {
useCallback,
- useContext,
useEffect,
useMemo,
useRef,
@@ -88,8 +86,17 @@ import { Trans } from "react-i18next";
import { z } from "zod/v4";
export type CollectionShareProps = ModalVisibilityProps & {
+ /**
+ * The currently logged in user.
+ */
+ user: LocalUser;
collection: Collection;
collectionSummary: CollectionSummary;
+ /**
+ * A list of emails that can be served up as suggestions when the user is
+ * trying to share an album with another Ente user.
+ */
+ shareSuggestionEmails: string[];
setBlockingLoad: (value: boolean) => void;
/**
* Called when an operation in the share menu requires a full remote pull.
@@ -100,8 +107,10 @@ export type CollectionShareProps = ModalVisibilityProps & {
export const CollectionShare: React.FC<CollectionShareProps> = ({
open,
onClose,
+ user,
collection,
collectionSummary,
+ shareSuggestionEmails,
setBlockingLoad,
onRemotePull,
}) => {
@@ -155,12 +164,18 @@ export const CollectionShare: React.FC<CollectionShareProps> = ({
<Stack sx={{ py: "20px", px: "8px", gap: "24px" }}>
{type == "incomingShareCollaborator" ||
type == "incomingShareViewer" ? (
- <SharingDetails {...{ collection, type }} />
+ <SharingDetails {...{ user, collection, type }} />
) : (
<>
<EmailShare
onRootClose={onClose}
- {...{ wrap, collection, onRemotePull }}
+ {...{
+ user,
+ collection,
+ shareSuggestionEmails,
+ wrap,
+ onRemotePull,
+ }}
/>
<PublicShare
onRootClose={onClose}
@@ -178,17 +193,16 @@ export const CollectionShare: React.FC<CollectionShareProps> = ({
);
};
-interface SharingDetailsProps {
- collection: Collection;
- type: CollectionSummaryType;
-}
+type SharingDetailsProps = { type: CollectionSummaryType } & Pick<
+ CollectionShareProps,
+ "user" | "collection"
+>;
const SharingDetails: React.FC<SharingDetailsProps> = ({
+ user,
collection,
type,
}) => {
- const user = ensureLocalUser();
-
const isOwner = user.id == collection.owner?.id;
const ownerEmail = isOwner ? user?.email : collection.owner?.email;
@@ -285,11 +299,16 @@ const handleSharingErrors = (error) => {
type EmailShareProps = {
onRootClose: () => void;
wrap: (f: () => Promise<void>) => () => void;
-} & Pick<CollectionShareProps, "collection" | "onRemotePull">;
+} & Pick<
+ CollectionShareProps,
+ "user" | "collection" | "shareSuggestionEmails" | "onRemotePull"
+>;
const EmailShare: React.FC<EmailShareProps> = ({
onRootClose,
+ user,
collection,
+ shareSuggestionEmails,
wrap,
onRemotePull,
}) => {
@@ -354,13 +373,26 @@ const EmailShare: React.FC<EmailShareProps> = ({
</Stack>
<AddParticipant
{...addParticipantVisibilityProps}
- {...{ onRootClose, collection, onRemotePull }}
+ {...{
+ onRootClose,
+ user,
+ collection,
+ shareSuggestionEmails,
+ onRemotePull,
+ }}
role={participantRole}
/>
<ManageEmailShare
{...manageEmailVisibilityProps}
- {...{ onRootClose, wrap, collection, onRemotePull }}
- participantCount={participantCount}
+ {...{
+ onRootClose,
+ user,
+ collection,
+ shareSuggestionEmails,
+ participantCount,
+ wrap,
+ onRemotePull,
+ }}
/>
</>
);
@@ -416,27 +448,28 @@ const AvatarGroup = ({ sharees }: { sharees: Collection["sharees"] }) => {
type AddParticipantProps = ModalVisibilityProps & {
onRootClose: () => void;
role: CollectionNewParticipantRole;
-} & Pick<CollectionShareProps, "collection" | "onRemotePull">;
+} & Pick<
+ CollectionShareProps,
+ "user" | "collection" | "shareSuggestionEmails" | "onRemotePull"
+ >;
const AddParticipant: React.FC<AddParticipantProps> = ({
open,
onClose,
onRootClose,
+ user,
collection,
+ shareSuggestionEmails,
role,
onRemotePull,
}) => {
- const { user, emailList } = useContext(GalleryContext);
-
- const eligibleEmails = useMemo(
- () =>
- emailList.filter(
- (email) =>
- email != user.email &&
- !collection?.sharees?.find((value) => value.email == email),
- ),
- [emailList, collection.sharees],
- );
+ const eligibleEmails = useMemo(() => {
+ return shareSuggestionEmails.filter(
+ (email) =>
+ email != user.email &&
+ !collection?.sharees?.find((value) => value.email == email),
+ );
+ }, [shareSuggestionEmails, collection.sharees]);
const handleRootClose = () => {
onClose();
@@ -647,19 +680,22 @@ type ManageEmailShareProps = ModalVisibilityProps & {
onRootClose: () => void;
participantCount: number;
wrap: (f: () => Promise<void>) => () => void;
-} & Pick<CollectionShareProps, "collection" | "onRemotePull">;
+} & Pick<
+ CollectionShareProps,
+ "user" | "collection" | "shareSuggestionEmails" | "onRemotePull"
+ >;
const ManageEmailShare: React.FC<ManageEmailShareProps> = ({
open,
onClose,
onRootClose,
+ user,
collection,
+ shareSuggestionEmails,
participantCount,
wrap,
onRemotePull,
}) => {
- const galleryContext = useContext(GalleryContext);
-
const { show: showAddParticipant, props: addParticipantVisibilityProps } =
useModalVisibility();
const {
@@ -687,11 +723,9 @@ const ManageEmailShare: React.FC<ManageEmailShareProps> = ({
};
const ownerEmail =
- galleryContext.user.id === collection.owner?.id
- ? galleryContext.user.email
- : collection.owner?.email;
+ user.id == collection.owner?.id ? user.email : collection.owner?.email;
- const isOwner = galleryContext.user.id === collection.owner?.id;
+ const isOwner = user.id == collection.owner?.id;
const collaborators = collection.sharees
?.filter((sharee) => sharee.role == "COLLABORATOR")
@@ -795,7 +829,13 @@ const ManageEmailShare: React.FC<ManageEmailShareProps> = ({
</TitledNestedSidebarDrawer>
<AddParticipant
{...addParticipantVisibilityProps}
- {...{ collection, onRootClose, onRemotePull }}
+ {...{
+ user,
+ collection,
+ shareSuggestionEmails,
+ onRootClose,
+ onRemotePull,
+ }}
role={participantType.current}
/>
<ManageParticipant
diff --git a/web/apps/photos/src/components/Collections/GalleryBarAndListHeader.tsx b/web/apps/photos/src/components/Collections/GalleryBarAndListHeader.tsx
index f5a20dd98e..8943d55ca9 100644
--- a/web/apps/photos/src/components/Collections/GalleryBarAndListHeader.tsx
+++ b/web/apps/photos/src/components/Collections/GalleryBarAndListHeader.tsx
@@ -58,7 +58,10 @@ type GalleryBarAndListHeaderProps = Omit<
CollectionHeaderProps,
"setFilesDownloadProgressAttributesCreator" | "onRemotePull"
> &
- Pick<CollectionShareProps, "setBlockingLoad">;
+ Pick<
+ CollectionShareProps,
+ "user" | "shareSuggestionEmails" | "setBlockingLoad"
+ >;
/**
* The gallery bar, the header for the list items, and state for any associated
@@ -84,6 +87,7 @@ export const GalleryBarAndListHeader: React.FC<
shouldHide,
mode,
onChangeMode,
+ user,
collectionSummaries,
activeCollection,
activeCollectionID,
@@ -92,6 +96,7 @@ export const GalleryBarAndListHeader: React.FC<
hiddenCollectionSummaries,
people,
activePerson,
+ shareSuggestionEmails,
onRemotePull,
onSelectPerson,
setPhotoListHeader,
@@ -229,7 +234,12 @@ export const GalleryBarAndListHeader: React.FC<
activeCollectionID,
)}
collection={activeCollection}
- {...{ setBlockingLoad, onRemotePull }}
+ {...{
+ user,
+ shareSuggestionEmails,
+ setBlockingLoad,
+ onRemotePull,
+ }}
/>
<AlbumCastDialog
{...collectionCastVisibilityProps}
diff --git a/web/apps/photos/src/pages/gallery.tsx b/web/apps/photos/src/pages/gallery.tsx
index edf969fc0a..0efb15e5f9 100644
--- a/web/apps/photos/src/pages/gallery.tsx
+++ b/web/apps/photos/src/pages/gallery.tsx
@@ -134,7 +134,6 @@ const defaultGalleryContext: GalleryContextType = {
photoListHeader: null,
user: null,
userIDToEmailMap: null,
- emailList: null,
};
export const GalleryContext = createContext<GalleryContextType>(
@@ -879,7 +878,6 @@ const Page: React.FC = () => {
user,
// TODO(RE): Rename
userIDToEmailMap: state.emailByUserID,
- emailList: state.shareSuggestionEmails,
}}
>
<FullScreenDropZone
@@ -994,6 +992,7 @@ const Page: React.FC = () => {
<GalleryBarAndListHeader
{...{
+ user,
activeCollection,
activeCollectionID,
activePerson,
@@ -1005,6 +1004,7 @@ const Page: React.FC = () => {
shouldHide={isInSearchMode}
collectionSummaries={normalCollectionSummaries}
hiddenCollectionSummaries={state.hiddenCollectionSummaries}
+ shareSuggestionEmails={state.shareSuggestionEmails}
people={
(state.view.type == "people"
? state.view.visiblePeople
diff --git a/web/apps/photos/src/types/gallery/index.ts b/web/apps/photos/src/types/gallery/index.ts
index 5549cf5cde..a793bdc1dc 100644
--- a/web/apps/photos/src/types/gallery/index.ts
+++ b/web/apps/photos/src/types/gallery/index.ts
@@ -43,5 +43,4 @@ export interface GalleryContextType {
photoListHeader: TimeStampListItem;
user: User;
userIDToEmailMap: Map<number, string>;
- emailList: string[];
}