Skip to content

armgit / ente

Public Imported from GitHub
0

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

Ref

Manav Rathie350ac207663
diff --git a/web/apps/photos/src/components/Collections/CollectionShare/publicShare/EnablePublicShareOptions.tsx b/web/apps/photos/src/components/Collections/CollectionShare/publicShare/EnablePublicShareOptions.tsx
index e6b49845b2..9c5f77c467 100644
--- a/web/apps/photos/src/components/Collections/CollectionShare/publicShare/EnablePublicShareOptions.tsx
+++ b/web/apps/photos/src/components/Collections/CollectionShare/publicShare/EnablePublicShareOptions.tsx
@@ -20,13 +20,13 @@ import { handleSharingErrors } from "utils/error/ui";
interface Iprops {
collection: Collection;
setPublicShareProp: (value: PublicURL) => void;
- setCopyLinkModalView: (value: boolean) => void;
+ onLinkCreated: () => void;
}
export default function EnablePublicShareOptions({
collection,
setPublicShareProp,
- setCopyLinkModalView,
+ onLinkCreated,
}: Iprops) {
const galleryContext = useContext(GalleryContext);
const [sharableLinkError, setSharableLinkError] = useState(null);
@@ -37,7 +37,7 @@ export default function EnablePublicShareOptions({
galleryContext.setBlockingLoad(true);
const publicURL = await createShareableURL(collection);
setPublicShareProp(publicURL);
- setCopyLinkModalView(true);
+ onLinkCreated();
galleryContext.syncWithRemote(false, true);
} catch (e) {
const errorMessage = handleSharingErrors(e);
@@ -57,7 +57,7 @@ export default function EnablePublicShareOptions({
enableCollect: true,
});
setPublicShareProp(publicURL);
- setCopyLinkModalView(true);
+ onLinkCreated();
galleryContext.syncWithRemote(false, true);
} catch (e) {
const errorMessage = handleSharingErrors(e);
diff --git a/web/apps/photos/src/components/Collections/CollectionShare/publicShare/index.tsx b/web/apps/photos/src/components/Collections/CollectionShare/publicShare/index.tsx
index 9fbff2702e..78168783e7 100644
--- a/web/apps/photos/src/components/Collections/CollectionShare/publicShare/index.tsx
+++ b/web/apps/photos/src/components/Collections/CollectionShare/publicShare/index.tsx
@@ -1,5 +1,6 @@
+import { useModalVisibility } from "@/base/components/utils/modal";
import type { Collection, PublicURL } from "@/media/collection";
-import CopyLinkModal from "@/new/photos/components/share/PublicLinkCreated";
+import { PublicLinkCreated } from "@/new/photos/components/share/PublicLinkCreated";
import { useEffect, useState } from "react";
import { appendCollectionKeyToShareURL } from "utils/collection";
import EnablePublicShareOptions from "./EnablePublicShareOptions";
@@ -14,7 +15,10 @@ export default function PublicShare({
}) {
const [publicShareUrl, setPublicShareUrl] = useState<string>(null);
const [publicShareProp, setPublicShareProp] = useState<PublicURL>(null);
- const [copyLinkModalView, setCopyLinkModalView] = useState(false);
+ const {
+ show: showPublicLinkCreated,
+ props: publicLinkCreatedVisibilityProps,
+ } = useModalVisibility();
useEffect(() => {
if (collection.publicURLs?.length) {
@@ -36,10 +40,6 @@ export default function PublicShare({
const copyToClipboardHelper = () => {
navigator.clipboard.writeText(publicShareUrl);
- handleCancel();
- };
- const handleCancel = () => {
- setCopyLinkModalView(false);
};
return (
@@ -57,14 +57,12 @@ export default function PublicShare({
<EnablePublicShareOptions
setPublicShareProp={setPublicShareProp}
collection={collection}
- setCopyLinkModalView={setCopyLinkModalView}
+ onLinkCreated={showPublicLinkCreated}
/>
)}
- <CopyLinkModal
- open={copyLinkModalView}
- onClose={handleCancel}
- handleCancel={handleCancel}
- copyToClipboardHelper={copyToClipboardHelper}
+ <PublicLinkCreated
+ {...publicLinkCreatedVisibilityProps}
+ onCopyLink={copyToClipboardHelper}
/>
</>
);
diff --git a/web/packages/new/photos/components/share/PublicLinkCreated.tsx b/web/packages/new/photos/components/share/PublicLinkCreated.tsx
index 1a7067cdb7..eb7928abed 100644
--- a/web/packages/new/photos/components/share/PublicLinkCreated.tsx
+++ b/web/packages/new/photos/components/share/PublicLinkCreated.tsx
@@ -1,3 +1,4 @@
+import type { ModalVisibilityProps } from "@/base/components/utils/modal";
import { VerticallyCentered } from "@ente/shared/components/Container";
import DialogBoxBase from "@ente/shared/components/DialogBox/base";
import Check from "@mui/icons-material/Check";
@@ -9,18 +10,24 @@ import {
Typography,
} from "@mui/material";
import { t } from "i18next";
-interface Iprops {
- open: boolean;
- onClose: () => void;
- handleCancel: () => void;
- copyToClipboardHelper: () => void;
-}
-export default function CopyLinkModal({
+
+type PublicLinkCreatedProps = ModalVisibilityProps & {
+ /**
+ * Callback invoked when the user presses the button to copy the newly
+ * created link. The dialog also closes when this happens.
+ */
+ onCopyLink: () => void;
+};
+
+/**
+ * A Dialog acknowledging the creation of a link to a public album, and offering
+ * the user a choice to copy the newly created link.
+ */
+export const PublicLinkCreated: React.FC<PublicLinkCreatedProps> = ({
open,
onClose,
- handleCancel,
- copyToClipboardHelper,
-}: Iprops) {
+ onCopyLink,
+}) => {
return (
<DialogBoxBase
open={open}
@@ -43,11 +50,14 @@ export default function CopyLinkModal({
</VerticallyCentered>
</DialogContent>
<DialogActions>
- <Button onClick={handleCancel} color="secondary" size={"large"}>
+ <Button onClick={onClose} color="secondary" size={"large"}>
{t("DONE")}
</Button>
<Button
- onClick={copyToClipboardHelper}
+ onClick={() => {
+ onCopyLink();
+ onClose();
+ }}
size={"large"}
color="primary"
autoFocus
@@ -57,4 +67,4 @@ export default function CopyLinkModal({
</DialogActions>
</DialogBoxBase>
);
-}
+};