Skip to content

armgit / ente

Public Imported from GitHub
0

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

feat(photos):add-inline-public-link-settings

Aswin Asok91bce4077173
diff --git a/web/apps/photos/src/components/Collections/CollectionShare.tsx b/web/apps/photos/src/components/Collections/CollectionShare.tsx
index f93b805708..534b96b426 100644
--- a/web/apps/photos/src/components/Collections/CollectionShare.tsx
+++ b/web/apps/photos/src/components/Collections/CollectionShare.tsx
@@ -20,7 +20,7 @@ import Photo, { default as PhotoIcon } from "@mui/icons-material/Photo";
import PublicIcon from "@mui/icons-material/Public";
import RemoveCircleOutlinedIcon from "@mui/icons-material/RemoveCircleOutlined";
import WorkspacesIcon from "@mui/icons-material/Workspaces";
-import { Dialog, Stack, styled, Typography } from "@mui/material";
+import { Box, Dialog, Stack, styled, Typography } from "@mui/material";
import NumberAvatar from "@mui/material/Avatar";
import TextField from "@mui/material/TextField";
import type { LocalUser } from "ente-accounts/services/user";
@@ -30,6 +30,10 @@ import {
SidebarDrawerTitlebar,
TitledNestedSidebarDrawer,
} from "ente-base/components/mui/SidebarDrawer";
+import {
+ SidebarDrawerDepthContext,
+ SidebarPanelContext,
+} from "ente-base/components/mui/SidebarDrawerContext";
import {
RowButton,
RowButtonDivider,
@@ -81,6 +85,7 @@ import { useFormik } from "formik";
import { t } from "i18next";
import React, {
useCallback,
+ useContext,
useEffect,
useMemo,
useRef,
@@ -1686,27 +1691,34 @@ const ReadOnlyPublicShare: React.FC<{ resolvedURL: string }> = ({
);
};
-type ManagePublicShareOptionsProps = ModalVisibilityProps & {
- onRootClose: () => void;
+type ManagePublicShareOptionsProps = {
publicURL: PublicURL;
setPublicURL: (publicURL: PublicURL | undefined) => void;
resolvedURL: string;
} & Pick<
- CollectionShareProps,
- "collection" | "setBlockingLoad" | "onRemotePull"
- >;
+ CollectionShareProps,
+ "collection" | "setBlockingLoad" | "onRemotePull"
+> &
+ (
+ | ({
+ variant?: "drawer";
+ onRootClose: () => void;
+ } & ModalVisibilityProps)
+ | { variant: "inline" }
+ );
-const ManagePublicShareOptions: React.FC<ManagePublicShareOptionsProps> = ({
- open,
- onClose,
- onRootClose,
- collection,
- publicURL,
- setPublicURL,
- resolvedURL,
- setBlockingLoad,
- onRemotePull,
-}) => {
+export const ManagePublicShareOptions: React.FC<
+ ManagePublicShareOptionsProps
+> = (props) => {
+ const {
+ collection,
+ publicURL,
+ setPublicURL,
+ resolvedURL,
+ setBlockingLoad,
+ onRemotePull,
+ } = props;
+ const panelRef = useRef<HTMLDivElement>(null);
const [errorMessage, setErrorMessage] = useState("");
const { embedURL: embedBaseURL } = useSettingsSnapshot();
@@ -1723,6 +1735,12 @@ const ManagePublicShareOptions: React.FC<ManagePublicShareOptionsProps> = ({
: "";
const [embedCopied, handleCopyEmbedLink] = useClipboardCopy(iframeHTML);
+ const onRootClose = () => {
+ if (props.variant != "inline") props.onRootClose();
+ };
+ const onClose = () => {
+ if (props.variant != "inline") props.onClose();
+ };
const handleRootClose = () => {
onClose();
onRootClose();
@@ -1774,93 +1792,117 @@ const ManagePublicShareOptions: React.FC<ManagePublicShareOptionsProps> = ({
}
};
- return (
- <TitledNestedSidebarDrawer
- anchor="right"
- {...{ open, onClose }}
- onRootClose={handleRootClose}
- title={t("manage_link")}
- >
- <Stack sx={{ gap: 3, py: "20px", px: "8px" }}>
- <ManageLayout
- {...{
- collection,
- onRootClose,
- onRemotePull,
- setBlockingLoad,
- }}
+ const content = (
+ <Stack sx={{ gap: 3, py: "20px", px: "8px" }}>
+ <ManageLayout
+ {...{ collection, onRootClose, onRemotePull, setBlockingLoad }}
+ />
+ <ManagePublicCollect
+ {...{ publicURL }}
+ onUpdate={handlePublicURLUpdate}
+ />
+ <ManageLinkExpiry
+ {...{ onRootClose, publicURL }}
+ onUpdate={handlePublicURLUpdate}
+ />
+ <RowButtonGroup>
+ <ManageDeviceLimit
+ {...{ onRootClose, publicURL }}
+ onUpdate={handlePublicURLUpdate}
/>
- <ManagePublicCollect
+ <RowButtonDivider />
+ <ManageDownloadAccess
{...{ publicURL }}
onUpdate={handlePublicURLUpdate}
/>
- <ManageLinkExpiry
- {...{ onRootClose, publicURL }}
+ <RowButtonDivider />
+ <ManageJoinAlbum
+ {...{ publicURL }}
onUpdate={handlePublicURLUpdate}
/>
- <RowButtonGroup>
- <ManageDeviceLimit
- {...{ onRootClose, publicURL }}
- onUpdate={handlePublicURLUpdate}
- />
- <RowButtonDivider />
- <ManageDownloadAccess
- {...{ publicURL }}
- onUpdate={handlePublicURLUpdate}
- />
- <RowButtonDivider />
- <ManageJoinAlbum
- {...{ publicURL }}
- onUpdate={handlePublicURLUpdate}
- />
- <RowButtonDivider />
- <ManageLinkPassword
- {...{ publicURL }}
- onUpdate={handlePublicURLUpdate}
- />
- </RowButtonGroup>
- <RowButtonGroup>
- <RowButton
- startIcon={
- copied ? (
- <DoneIcon sx={{ color: "accent.main" }} />
- ) : (
- <ContentCopyIcon />
- )
- }
- onClick={handleCopyLink}
- label={t("copy_link")}
- />
- <RowButtonDivider />
- <RowButton
- startIcon={
- embedCopied ? (
- <DoneIcon sx={{ color: "accent.main" }} />
- ) : (
- <CodeIcon />
- )
- }
- onClick={handleCopyEmbedLink}
- label={t("copy_embed_html")}
- />
- </RowButtonGroup>
- <RowButtonGroup>
- <RowButton
- color="critical"
- startIcon={<RemoveCircleOutlinedIcon />}
- onClick={handleRemovePublicLink}
- label={t("remove_link")}
- />
- </RowButtonGroup>
- {errorMessage && (
- <Typography
- variant="small"
- sx={{ color: "critical.main", textAlign: "center" }}
- >
- {errorMessage}
- </Typography>
- )}
- </Stack>
+ <RowButtonDivider />
+ <ManageLinkPassword
+ {...{ publicURL }}
+ onUpdate={handlePublicURLUpdate}
+ />
+ </RowButtonGroup>
+ <RowButtonGroup>
+ <RowButton
+ startIcon={
+ copied ? (
+ <DoneIcon sx={{ color: "accent.main" }} />
+ ) : (
+ <ContentCopyIcon />
+ )
+ }
+ onClick={handleCopyLink}
+ label={t("copy_link")}
+ />
+ <RowButtonDivider />
+ <RowButton
+ startIcon={
+ embedCopied ? (
+ <DoneIcon sx={{ color: "accent.main" }} />
+ ) : (
+ <CodeIcon />
+ )
+ }
+ onClick={handleCopyEmbedLink}
+ label={t("copy_embed_html")}
+ />
+ </RowButtonGroup>
+ <RowButtonGroup>
+ <RowButton
+ color="critical"
+ startIcon={<RemoveCircleOutlinedIcon />}
+ onClick={handleRemovePublicLink}
+ label={t("remove_link")}
+ />
+ </RowButtonGroup>
+ {errorMessage && (
+ <Typography
+ variant="small"
+ sx={{ color: "critical.main", textAlign: "center" }}
+ >
+ {errorMessage}
+ </Typography>
+ )}
+ </Stack>
+ );
+
+ if (props.variant == "inline") {
+ return (
+ <Box
+ ref={panelRef}
+ aria-label={t("manage_link")}
+ sx={{
+ position: "relative",
+ minWidth: 0,
+ borderRadius: 3,
+ overflow: "hidden",
+ }}
+ >
+ <SidebarPanelContext.Provider value={() => panelRef.current}>
+ <SidebarDrawerDepthContext.Provider value={1}>
+ <Typography component="h2" variant="h3" sx={{ px: 1 }}>
+ {t("manage_link")}
+ </Typography>
+ {content}
+ </SidebarDrawerDepthContext.Provider>
+ </SidebarPanelContext.Provider>
+ </Box>
+ );
+ }
+
+ return (
+ <TitledNestedSidebarDrawer
+ anchor="right"
+ open={props.open}
+ onClose={onClose}
+ onRootClose={handleRootClose}
+ title={t("manage_link")}
+ >
+ {content}
</TitledNestedSidebarDrawer>
);
};
@@ -2159,6 +2201,7 @@ const SetPublicLinkPassword: React.FC<SetPublicLinkPasswordProps> = ({
publicURL,
onUpdate,
}) => {
+ const inPanel = !!useContext(SidebarPanelContext);
const savePassword: SingleInputFormProps["onSubmit"] = async (password) => {
await enablePublicUrlPassword(password);
publicURL.passwordEnabled = true;
@@ -2177,7 +2220,37 @@ const SetPublicLinkPassword: React.FC<SetPublicLinkPasswordProps> = ({
});
};
- // This dialog is nested inside the sidebar.
+ const form = (
+ <Stack sx={{ gap: 3, p: 1.5 }}>
+ {!inPanel && (
+ <Typography variant="h3" sx={{ px: 1, py: 0.5 }}>
+ {t("password_lock")}
+ </Typography>
+ )}
+ <SingleInputForm
+ inputType="password"
+ label={t("password")}
+ submitButtonColor="primary"
+ submitButtonTitle={t("lock")}
+ onCancel={onClose}
+ onSubmit={savePassword}
+ />
+ </Stack>
+ );
+
+ if (inPanel) {
+ return (
+ <TitledNestedSidebarDrawer
+ anchor="right"
+ {...{ open, onClose }}
+ onRootClose={onClose}
+ title={t("password_lock")}
+ >
+ {form}
+ </TitledNestedSidebarDrawer>
+ );
+ }
+
return (
<Dialog
{...{ open, onClose }}
@@ -2190,19 +2263,7 @@ const SetPublicLinkPassword: React.FC<SetPublicLinkPasswordProps> = ({
maxWidth={"sm"}
fullWidth
>
- <Stack sx={{ gap: 3, p: 1.5 }}>
- <Typography variant="h3" sx={{ px: 1, py: 0.5 }}>
- {t("password_lock")}
- </Typography>
- <SingleInputForm
- inputType="password"
- label={t("password")}
- submitButtonColor="primary"
- submitButtonTitle={t("lock")}
- onCancel={onClose}
- onSubmit={savePassword}
- />
- </Stack>
+ {form}
</Dialog>
);
};
diff --git a/web/apps/photos/src/components/gallery/PhotosNavigationShell.tsx b/web/apps/photos/src/components/gallery/PhotosNavigationShell.tsx
index fc43920857..9c32dbdc6b 100644
--- a/web/apps/photos/src/components/gallery/PhotosNavigationShell.tsx
+++ b/web/apps/photos/src/components/gallery/PhotosNavigationShell.tsx
@@ -27,6 +27,7 @@ import { FocusVisibleButton } from "ente-base/components/mui/FocusVisibleButton"
import { NavbarBase } from "ente-base/components/Navbar";
import { useIsSmallWidth } from "ente-base/components/utils/hooks";
import { useModalVisibility } from "ente-base/components/utils/modal";
+import { isDevBuild } from "ente-base/env";
import { ut } from "ente-base/i18n";
import { thumbnailGridPadding } from "ente-new/photos/components/utils/thumbnail-grid-layout";
import { useSettingsSnapshot } from "ente-new/photos/components/utils/use-snapshot";
@@ -344,7 +345,7 @@ const NormalNavigationRail: React.FC<
/>
{(["albums", "people", "links"] as const).map((item) =>
(item == "people" && !isMLSupported) ||
- (item == "links" && !isInternalUser) ? null : (
+ (item == "links" && !isInternalUser && !isDevBuild) ? null : (
<Tooltip key={item} title={t(item)}>
<FocusVisibleButton
color="secondary"
diff --git a/web/apps/photos/src/components/gallery/PublicLinkDetails.tsx b/web/apps/photos/src/components/gallery/PublicLinkDetails.tsx
index c094fd3a5a..7caac20c4e 100644
--- a/web/apps/photos/src/components/gallery/PublicLinkDetails.tsx
+++ b/web/apps/photos/src/components/gallery/PublicLinkDetails.tsx
@@ -1,3 +1,4 @@
+import { ManagePublicShareOptions } from "@/components/Collections/CollectionShare";
import { PickCoverPhotoDialog } from "@/components/Collections/PickCoverPhotoDialog";
import { usePublicLinkURL } from "@/components/utils/use-public-link-url";
import { Copy01Icon, Edit03Icon } from "@hugeicons/core-free-icons";
@@ -16,7 +17,7 @@ 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 type { Collection } from "ente-media/collection";
+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";
@@ -24,6 +25,7 @@ import { useSettingsSnapshot } from "ente-new/photos/components/utils/use-snapsh
import { updateCollectionDetails } from "ente-new/photos/services/collection";
import { openURL } from "ente-new/photos/utils/web";
import { t } from "i18next";
+import { useState } from "react";
import type { RemotePullOpts } from ".";
interface PublicLinkDetailsProps {
@@ -32,6 +34,7 @@ interface PublicLinkDetailsProps {
coverFile?: EnteFile;
files: EnteFile[];
user: LocalUser;
+ setBlockingLoad: (value: boolean) => void;
onRemotePull: (opts?: RemotePullOpts) => Promise<void>;
}
@@ -41,15 +44,26 @@ export const PublicLinkDetails = ({
coverFile,
files,
user,
+ setBlockingLoad,
onRemotePull,
}: PublicLinkDetailsProps) => {
const { onGenericError } = useBaseContext();
const { show: showPickCoverPhoto, props: pickCoverPhotoVisibilityProps } =
useModalVisibility();
const { customDomain } = useSettingsSnapshot();
+ const [shareState, setShareState] = useState({
+ collection,
+ publicURL: collection.publicURLs[0],
+ });
+ const publicURL =
+ shareState.collection === collection
+ ? shareState.publicURL
+ : collection.publicURLs[0];
+ const setPublicURL = (publicURL: PublicURL | undefined) =>
+ setShareState({ collection, publicURL });
const { resolvedURL, isLoading, error } = usePublicLinkURL(
collection,
- collection.publicURLs[0],
+ publicURL,
customDomain,
);
const canChangeCover =
@@ -111,117 +125,149 @@ export const PublicLinkDetails = ({
{t("photos_count", { count: fileCount })}
</Typography>
</Stack>
- <Stack sx={{ width: "100%", maxWidth: 364, gap: "14px" }}>
- <Box sx={{ position: "relative" }}>
- <Box role="img" aria-label={collection.name}>
- <ItemCard
- key={`${collection.id}-${coverFile?.id ?? "empty"}`}
- TileComponent={Cover}
- coverFile={coverFile}
- />
+ <Stack
+ direction="row"
+ sx={{ flexWrap: "wrap", gap: "40px", alignItems: "flex-start" }}
+ >
+ <Stack sx={{ width: "100%", maxWidth: 364, gap: "14px" }}>
+ <Box sx={{ position: "relative" }}>
+ <Box role="img" aria-label={collection.name}>
+ <ItemCard
+ key={`${collection.id}-${coverFile?.id ?? "empty"}`}
+ TileComponent={Cover}
+ coverFile={coverFile}
+ />
+ </Box>
+ {canChangeCover && (
+ <Tooltip title={t("set_cover")}>
+ <IconButton
+ aria-label={t("set_cover")}
+ onClick={showPickCoverPhoto}
+ sx={{
+ position: "absolute",
+ top: 16,
+ right: 16,
+ width: 38,
+ height: 38,
+ p: "10px",
+ borderRadius: "12px",
+ bgcolor: "background.paper",
+ color: "text.base",
+ "&:hover": {
+ bgcolor: "background.paper",
+ },
+ }}
+ >
+ <HugeiconsIcon
+ icon={Edit03Icon}
+ size={18}
+ strokeWidth={1.5}
+ />
+ </IconButton>
+ </Tooltip>
+ )}
</Box>
- {canChangeCover && (
- <Tooltip title={t("set_cover")}>
- <IconButton
- aria-label={t("set_cover")}
- onClick={showPickCoverPhoto}
- sx={{
- position: "absolute",
- top: 16,
- right: 16,
- width: 38,
- height: 38,
- p: "10px",
- borderRadius: "12px",
- bgcolor: "background.paper",
- color: "text.base",
- "&:hover": { bgcolor: "background.paper" },
- }}
- >
- <HugeiconsIcon
- icon={Edit03Icon}
- size={18}
- strokeWidth={1.5}
- />
- </IconButton>
- </Tooltip>
- )}
- </Box>
- <Stack
- direction="row"
- sx={(theme) => ({
- alignItems: "center",
- gap: "8px",
- height: 52,
- px: "16px",
- borderRadius: "16px",
- bgcolor: "fill.faint",
- ...theme.applyStyles("light", { bgcolor: "#F4F4F4" }),
- })}
- >
+ <Stack
+ direction="row"
+ sx={(theme) => ({
+ alignItems: "center",
+ gap: "8px",
+ height: 52,
+ px: "16px",
+ borderRadius: "16px",
+ bgcolor: "fill.faint",
+ ...theme.applyStyles("light", {
+ bgcolor: "#F4F4F4",
+ }),
+ })}
+ >
+ <Typography
+ component="span"
+ title={resolvedURL}
+ aria-live="polite"
+ sx={{
+ flex: 1,
+ minWidth: 0,
+ fontSize: 14,
+ fontWeight: 500,
+ lineHeight: "20px",
+ letterSpacing: 0,
+ overflow: "hidden",
+ textOverflow: "ellipsis",
+ whiteSpace: "nowrap",
+ }}
+ >
+ {resolvedURL?.replace(/^https?:\/\//, "") ??
+ (error
+ ? t("generic_error")
+ : isLoading
+ ? t("loading")
+ : null)}
+ </Typography>
+ <CopyLinkButton
+ key={resolvedURL ?? "pending"}
+ url={resolvedURL}
+ />
+ </Stack>
<Typography
- component="span"
- title={resolvedURL}
- aria-live="polite"
sx={{
- flex: 1,
- minWidth: 0,
+ color: "text.muted",
+ fontSize: "11.5px",
+ fontWeight: 400,
+ lineHeight: 1.45,
+ letterSpacing: 0,
+ }}
+ >
+ {t("public_link_description")}
+ </Typography>
+ <FocusVisibleButton
+ color="secondary"
+ fullWidth
+ disabled={!resolvedURL}
+ onClick={() => {
+ if (resolvedURL) openURL(resolvedURL);
+ }}
+ sx={(theme) => ({
+ height: 52,
+ px: "24px",
+ py: "14px",
+ borderRadius: "20px",
fontSize: 14,
fontWeight: 500,
lineHeight: "20px",
letterSpacing: 0,
- overflow: "hidden",
- textOverflow: "ellipsis",
- whiteSpace: "nowrap",
- }}
+ ...theme.applyStyles("light", {
+ bgcolor: "#EAEAEA",
+ "&:hover": { bgcolor: "secondary.hover" },
+ }),
+ })}
>
- {resolvedURL?.replace(/^https?:\/\//, "") ??
- (error
- ? t("generic_error")
- : isLoading
- ? t("loading")
- : null)}
- </Typography>
- <CopyLinkButton
- key={resolvedURL ?? "pending"}
- url={resolvedURL}
- />
+ {t("open_album")}
+ </FocusVisibleButton>
</Stack>
- <Typography
- sx={{
- color: "text.muted",
- fontSize: "11.5px",
- fontWeight: 400,
- lineHeight: 1.45,
- letterSpacing: 0,
- }}
- >
- {t("public_link_description")}
- </Typography>
- <FocusVisibleButton
- color="secondary"
- fullWidth
- disabled={!resolvedURL}
- onClick={() => {
- if (resolvedURL) openURL(resolvedURL);
- }}
- sx={(theme) => ({
- height: 52,
- px: "24px",
- py: "14px",
- borderRadius: "20px",
- fontSize: 14,
- fontWeight: 500,
- lineHeight: "20px",
- letterSpacing: 0,
- ...theme.applyStyles("light", {
- bgcolor: "#EAEAEA",
- "&:hover": { bgcolor: "secondary.hover" },
- }),
- })}
- >
- {t("open_album")}
- </FocusVisibleButton>
+ {collection.owner.id === user.id &&
+ publicURL &&
+ resolvedURL && (
+ <Box
+ sx={{
+ flex: "1 1 320px",
+ minWidth: 0,
+ maxWidth: 520,
+ }}
+ >
+ <ManagePublicShareOptions
+ variant="inline"
+ {...{
+ collection,
+ publicURL,
+ setPublicURL,
+ resolvedURL,
+ setBlockingLoad,
+ onRemotePull,
+ }}
+ />
+ </Box>
+ )}
</Stack>
{canChangeCover && pickCoverPhotoVisibilityProps.open && (
<PickCoverPhotoDialog
diff --git a/web/apps/photos/src/pages/gallery.tsx b/web/apps/photos/src/pages/gallery.tsx
index 8d1863eab4..ea793ec9ea 100644
--- a/web/apps/photos/src/pages/gallery.tsx
+++ b/web/apps/photos/src/pages/gallery.tsx
@@ -2274,6 +2274,7 @@ const Page: React.FC = () => {
}
files={selectedLinkFiles}
user={user}
+ setBlockingLoad={setBlockingLoad}
onRemotePull={remotePull}
coverFile={selectedLinkSummary?.coverFile}
/>