Skip to content

armgit / ente

Public Imported from GitHub
0

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

[photos][web] Render remove link directly in link details

AswinAsokf353bd1af2f8
diff --git a/web/apps/photos/src/components/collections/CollectionShare.tsx b/web/apps/photos/src/components/collections/CollectionShare.tsx
index 7632dddcb1..e6b52c45a5 100644
--- a/web/apps/photos/src/components/collections/CollectionShare.tsx
+++ b/web/apps/photos/src/components/collections/CollectionShare.tsx
@@ -26,7 +26,6 @@ import NumberAvatar from "@mui/material/Avatar";
import TextField from "@mui/material/TextField";
import type { LocalUser } from "ente-accounts/services/user";
import { EnteSwitch } from "ente-base/components/EnteSwitch";
-import { FocusVisibleButton } from "ente-base/components/mui/FocusVisibleButton";
import { LoadingButton } from "ente-base/components/mui/LoadingButton";
import {
SidebarDrawer,
@@ -70,9 +69,8 @@ import { CollectionSubType, type CollectionUser } from "ente-media/collection";
import { useSettingsSnapshot } from "ente-new/photos/components/utils/use-snapshot";
import {
createPublicURL,
- deleteCollection,
- deleteShareURL,
getCollectionByID,
+ removePublicLink,
shareCollection,
unshareCollection,
updateCollectionLayout,
@@ -91,7 +89,6 @@ import React, {
useRef,
useState,
} from "react";
-import { createPortal } from "react-dom";
import { Trans } from "react-i18next";
import { z } from "zod";
@@ -1705,7 +1702,7 @@ type ManagePublicShareOptionsProps = {
variant?: "drawer";
onRootClose: () => void;
} & ModalVisibilityProps)
- | { variant: "inline"; removeLinkContainer?: HTMLElement | null }
+ | { variant: "inline" }
);
export const ManagePublicShareOptions: React.FC<
@@ -1770,21 +1767,18 @@ export const ManagePublicShareOptions: React.FC<
setBlockingLoad(true);
setErrorMessage("");
try {
- const isQuickLinkAlbum =
+ await removePublicLink(collection);
+ setPublicURL(undefined);
+ void onRemotePull({ silent: true });
+ if (
collection.magicMetadata?.data.subType ==
- CollectionSubType.quicklink;
- if (isQuickLinkAlbum && collection.sharees.length === 0) {
- await deleteCollection(collection.id, { keepFiles: true });
- setPublicURL(undefined);
- void onRemotePull({ silent: true });
+ CollectionSubType.quicklink &&
+ collection.sharees.length === 0
+ ) {
handleRootClose();
- return;
+ } else {
+ onClose();
}
-
- await deleteShareURL(collection.id);
- setPublicURL(undefined);
- void onRemotePull({ silent: true });
- onClose();
} catch (e) {
log.error("Failed to remove public link", e);
setErrorMessage(t("generic_error"));
@@ -1872,31 +1866,6 @@ export const ManagePublicShareOptions: React.FC<
);
if (props.variant == "inline") {
- const removeLinkButton = (
- <FocusVisibleButton
- color="critical"
- onClick={handleRemovePublicLink}
- sx={{
- alignSelf: props.removeLinkContainer
- ? "stretch"
- : "flex-start",
- ml: props.removeLinkContainer ? 0 : 1,
- px: 1,
- py: 1,
- bgcolor: "transparent",
- color: "critical.main",
- fontSize: 14,
- fontWeight: 500,
- width: props.removeLinkContainer ? "100%" : undefined,
- height: props.removeLinkContainer ? 52 : undefined,
- textDecoration: "underline",
- borderRadius: "20px",
- "&:hover": { bgcolor: "fill.faintHover" },
- }}
- >
- {t("remove_link")}
- </FocusVisibleButton>
- );
return (
<ThemeProvider theme={sidebarTheme}>
<Stack
@@ -1986,12 +1955,6 @@ export const ManagePublicShareOptions: React.FC<
</SidebarDrawerDepthContext.Provider>
</SidebarPanelContext.Provider>
</Box>
- {props.removeLinkContainer
- ? createPortal(
- removeLinkButton,
- props.removeLinkContainer,
- )
- : removeLinkButton}
{errorMessage && (
<Typography
variant="small"
diff --git a/web/apps/photos/src/components/gallery/PublicLinkDetails.tsx b/web/apps/photos/src/components/gallery/PublicLinkDetails.tsx
index b6de9fcaa3..987f063902 100644
--- a/web/apps/photos/src/components/gallery/PublicLinkDetails.tsx
+++ b/web/apps/photos/src/components/gallery/PublicLinkDetails.tsx
@@ -17,12 +17,16 @@ import { FocusVisibleButton } from "ente-base/components/mui/FocusVisibleButton"
import { useClipboardCopy } from "ente-base/components/utils/hooks";
import { useModalVisibility } from "ente-base/components/utils/modal";
import { useBaseContext } from "ente-base/context";
+import log from "ente-base/log";
import type { Collection, PublicURL } from "ente-media/collection";
import type { EnteFile } from "ente-media/file";
import { FileType } from "ente-media/file-type";
import { ItemCard } from "ente-new/photos/components/Tiles";
import { useSettingsSnapshot } from "ente-new/photos/components/utils/use-snapshot";
-import { updateCollectionDetails } from "ente-new/photos/services/collection";
+import {
+ removePublicLink,
+ updateCollectionDetails,
+} from "ente-new/photos/services/collection";
import { openURL } from "ente-new/photos/utils/web";
import { t } from "i18next";
import { useState } from "react";
@@ -51,8 +55,7 @@ export const PublicLinkDetails = ({
const { show: showPickCoverPhoto, props: pickCoverPhotoVisibilityProps } =
useModalVisibility();
const { customDomain } = useSettingsSnapshot();
- const [removeLinkContainer, setRemoveLinkContainer] =
- useState<HTMLDivElement | null>(null);
+ const [removeLinkError, setRemoveLinkError] = useState("");
const [shareState, setShareState] = useState({
collection,
publicURL: collection.publicURLs[0],
@@ -88,6 +91,21 @@ export const PublicLinkDetails = ({
}
};
+ const handleRemovePublicLink = async () => {
+ setBlockingLoad(true);
+ setRemoveLinkError("");
+ try {
+ await removePublicLink(collection);
+ setPublicURL(undefined);
+ void onRemotePull({ silent: true });
+ } catch (e) {
+ log.error("Failed to remove public link", e);
+ setRemoveLinkError(t("generic_error"));
+ } finally {
+ setBlockingLoad(false);
+ }
+ };
+
return (
<Box
sx={{
@@ -259,7 +277,34 @@ export const PublicLinkDetails = ({
>
{t("open_album")}
</FocusVisibleButton>
- <Box ref={setRemoveLinkContainer} />
+ {collection.owner.id === user.id && publicURL && (
+ <FocusVisibleButton
+ color="critical"
+ fullWidth
+ onClick={handleRemovePublicLink}
+ sx={{
+ height: 52,
+ bgcolor: "transparent",
+ color: "critical.main",
+ fontSize: 14,
+ fontWeight: 500,
+ textDecoration: "underline",
+ borderRadius: "20px",
+ "&:hover": { bgcolor: "fill.faintHover" },
+ }}
+ >
+ {t("remove_link")}
+ </FocusVisibleButton>
+ )}
+ {removeLinkError && (
+ <Typography
+ role="alert"
+ variant="small"
+ sx={{ color: "critical.main" }}
+ >
+ {removeLinkError}
+ </Typography>
+ )}
</Stack>
{collection.owner.id === user.id &&
publicURL &&
@@ -267,7 +312,6 @@ export const PublicLinkDetails = ({
<Box sx={{ minWidth: 0 }}>
<ManagePublicShareOptions
variant="inline"
- removeLinkContainer={removeLinkContainer}
{...{
collection,
publicURL,
diff --git a/web/packages/new/photos/services/collection.ts b/web/packages/new/photos/services/collection.ts
index 1730defd61..5d046b9515 100644
--- a/web/packages/new/photos/services/collection.ts
+++ b/web/packages/new/photos/services/collection.ts
@@ -1374,6 +1374,21 @@ export const updatePublicURL = async (
return z.object({ result: RemotePublicURL }).parse(await res.json()).result;
};
+/**
+ * Remove a public link, deleting an unshared quick link album while keeping its
+ * files. Regular albums and albums with participants keep their collection.
+ */
+export const removePublicLink = async (collection: Collection) => {
+ if (
+ collection.magicMetadata?.data.subType == CollectionSubType.quicklink &&
+ collection.sharees.length === 0
+ ) {
+ await deleteCollection(collection.id, { keepFiles: true });
+ } else {
+ await deleteShareURL(collection.id);
+ }
+};
+
export const deleteShareURL = async (collectionID: number) =>
ensureOk(
await fetch(await apiURL(`/collections/share-url/${collectionID}`), {