Skip to content

armgit / ente

Public Imported from GitHub
0

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

[web] Render notification icons from shared icon data

AswinAsok093927226ca8
diff --git a/web/apps/albums/src/public-album/components/TripLayout/MobileNavBar.tsx b/web/apps/albums/src/public-album/components/TripLayout/MobileNavBar.tsx
index 30bce3cd0e..54d99e4d19 100644
--- a/web/apps/albums/src/public-album/components/TripLayout/MobileNavBar.tsx
+++ b/web/apps/albums/src/public-album/components/TripLayout/MobileNavBar.tsx
@@ -7,7 +7,6 @@ import {
ShareIcon,
} from "@/public-album/components/ActionIcons";
import { Tick02Icon } from "@hugeicons/core-free-icons";
-import { HugeiconsIcon } from "@hugeicons/react";
import { Box, Button, IconButton, styled } from "@mui/material";
import { EnteLogo } from "ente-base/components/EnteLogo";
import { t } from "i18next";
@@ -105,13 +104,7 @@ export const MobileNavBar: React.FC<MobileNavBarProps> = ({
horizontal="left"
attributes={{
color: "secondary",
- startIcon: (
- <HugeiconsIcon
- icon={Tick02Icon}
- size={24}
- strokeWidth={1.8}
- />
- ),
+ startIcon: Tick02Icon,
title: "Copied!",
}}
/>
diff --git a/web/apps/albums/src/public-album/components/TripLayout/TopNavButtons.tsx b/web/apps/albums/src/public-album/components/TripLayout/TopNavButtons.tsx
index aac7e7cefd..4788b14257 100644
--- a/web/apps/albums/src/public-album/components/TripLayout/TopNavButtons.tsx
+++ b/web/apps/albums/src/public-album/components/TripLayout/TopNavButtons.tsx
@@ -7,7 +7,6 @@ import {
ShareIcon,
} from "@/public-album/components/ActionIcons";
import { Tick02Icon } from "@hugeicons/core-free-icons";
-import { HugeiconsIcon } from "@hugeicons/react";
import { Box, Button, IconButton, styled } from "@mui/material";
import { t } from "i18next";
import { useState } from "react";
@@ -80,13 +79,7 @@ export const TopNavButtons: React.FC<TopNavButtonsProps> = ({
horizontal="left"
attributes={{
color: "secondary",
- startIcon: (
- <HugeiconsIcon
- icon={Tick02Icon}
- size={24}
- strokeWidth={1.8}
- />
- ),
+ startIcon: Tick02Icon,
title: "Copied!",
}}
/>
diff --git a/web/apps/albums/src/public-album/page/PublicAlbumPage.tsx b/web/apps/albums/src/public-album/page/PublicAlbumPage.tsx
index 5ad9214e38..14972834fc 100644
--- a/web/apps/albums/src/public-album/page/PublicAlbumPage.tsx
+++ b/web/apps/albums/src/public-album/page/PublicAlbumPage.tsx
@@ -29,7 +29,6 @@ import type { PublicAlbumSingleFileViewerProps } from "@/public-album/viewer/com
import type { PublicFeedItemClickInfo } from "@/public-album/viewer/components/PublicFeedSidebar";
import { LazyPublicFeedSidebar } from "@/public-album/viewer/lib/lazy";
import { Tick02Icon } from "@hugeicons/core-free-icons";
-import { HugeiconsIcon } from "@hugeicons/react";
import CloseIcon from "@mui/icons-material/Close";
import {
Box,
@@ -1302,13 +1301,7 @@ const FileListHeader: React.FC<FileListHeaderProps> = ({
horizontal="left"
attributes={{
color: "secondary",
- startIcon: (
- <HugeiconsIcon
- icon={Tick02Icon}
- size={24}
- strokeWidth={1.8}
- />
- ),
+ startIcon: Tick02Icon,
title: "Copied!",
}}
/>
diff --git a/web/apps/albums/src/public-album/viewer/components/PublicAlbumSingleFileViewer.tsx b/web/apps/albums/src/public-album/viewer/components/PublicAlbumSingleFileViewer.tsx
index a65a879759..3a3dc036a6 100644
--- a/web/apps/albums/src/public-album/viewer/components/PublicAlbumSingleFileViewer.tsx
+++ b/web/apps/albums/src/public-album/viewer/components/PublicAlbumSingleFileViewer.tsx
@@ -2,7 +2,6 @@ import { LazyNotification } from "@/app/lazy/global-ui";
import { getEnteURL } from "@/public-album/access/utils/external-links";
import { downloadManager } from "@/public-album/download/services/download-manager";
import { Tick02Icon } from "@hugeicons/core-free-icons";
-import { HugeiconsIcon } from "@hugeicons/react";
import ContentCopyIcon from "@mui/icons-material/ContentCopy";
import DownloadOutlinedIcon from "@mui/icons-material/DownloadOutlined";
import ErrorOutlinedIcon from "@mui/icons-material/ErrorOutlined";
@@ -865,13 +864,7 @@ export const PublicAlbumSingleFileViewer: React.FC<
horizontal="left"
attributes={{
color: "secondary",
- startIcon: (
- <HugeiconsIcon
- icon={Tick02Icon}
- size={24}
- strokeWidth={1.8}
- />
- ),
+ startIcon: Tick02Icon,
title: "Copied!",
}}
/>
diff --git a/web/apps/photos/src/components/Upload.tsx b/web/apps/photos/src/components/Upload.tsx
index 2bd66c287f..e41d9258ac 100644
--- a/web/apps/photos/src/components/Upload.tsx
+++ b/web/apps/photos/src/components/Upload.tsx
@@ -22,7 +22,6 @@ import {
} from "@/services/upload-manager";
import watcher from "@/services/watch";
import { Database02Icon } from "@hugeicons/core-free-icons";
-import { HugeiconsIcon } from "@hugeicons/react";
import { Dialog, type DialogProps } from "@mui/material";
import type { LocalUser } from "ente-accounts/services/user";
import { isDesktop } from "ente-base/app";
@@ -1130,13 +1129,7 @@ export const Upload: React.FC<UploadProps> = ({
caption: t("storage_quota_exceeded"),
title: t("upgrade_now"),
onClick: onShowPlanSelector,
- startIcon: (
- <HugeiconsIcon
- icon={Database02Icon}
- size={24}
- strokeWidth={1.8}
- />
- ),
+ startIcon: Database02Icon,
});
break;
default:
diff --git a/web/apps/photos/src/pages/_app.tsx b/web/apps/photos/src/pages/_app.tsx
index 0eca552665..4caa47ee35 100644
--- a/web/apps/photos/src/pages/_app.tsx
+++ b/web/apps/photos/src/pages/_app.tsx
@@ -16,7 +16,6 @@ import { runMigrations } from "@/services/migration";
import "@fontsource-variable/inter";
import "@fontsource-variable/outfit";
import { ArrowRight02Icon } from "@hugeicons/core-free-icons";
-import { HugeiconsIcon } from "@hugeicons/react";
import { CssBaseline, Typography } from "@mui/material";
import { styled, ThemeProvider, useColorScheme } from "@mui/material/styles";
import { AuthPageProvider } from "ente-accounts/components/auth/AuthPageProvider";
@@ -123,13 +122,7 @@ const App: React.FC<PhotosAppProps> = ({ Component, pageProps }) => {
showNotification({
color: "secondary",
title: t("update_available"),
- endIcon: (
- <HugeiconsIcon
- icon={ArrowRight02Icon}
- size={24}
- strokeWidth={1.8}
- />
- ),
+ endIcon: ArrowRight02Icon,
onClick: () =>
showMiniDialog(
updateAvailableForDownloadDialogAttributes(update),
diff --git a/web/apps/photos/src/pages/gallery.tsx b/web/apps/photos/src/pages/gallery.tsx
index 5017091363..15de8a7ab2 100644
--- a/web/apps/photos/src/pages/gallery.tsx
+++ b/web/apps/photos/src/pages/gallery.tsx
@@ -70,7 +70,6 @@ import { externalLink } from "@/utils/link";
import { sortPeople, type PeopleSortBy } from "@/utils/people-sort";
import { visibleQuickLinks } from "@/utils/quick-links";
import { CheckmarkCircle02Icon } from "@hugeicons/core-free-icons";
-import { HugeiconsIcon } from "@hugeicons/react";
import { Typography } from "@mui/material";
import { sessionExpiredDialogAttributes } from "ente-accounts/components/utils/dialog";
import {
@@ -1456,13 +1455,7 @@ const Page: React.FC = () => {
)?.name;
showNotification({
color: "secondary",
- startIcon: (
- <HugeiconsIcon
- icon={CheckmarkCircle02Icon}
- size={24}
- strokeWidth={1.8}
- />
- ),
+ startIcon: CheckmarkCircle02Icon,
title: t("added_to_person"),
caption: personName,
});
diff --git a/web/apps/photos/tests/notification-icons.test.tsx b/web/apps/photos/tests/notification-icons.test.tsx
new file mode 100644
index 0000000000..3ac3265e3b
--- /dev/null
+++ b/web/apps/photos/tests/notification-icons.test.tsx
@@ -0,0 +1,70 @@
+import { Copy01Icon, ReloadIcon, Tick02Icon } from "@hugeicons/core-free-icons";
+import { HugeiconsIcon } from "@hugeicons/react";
+import { ThemeProvider } from "@mui/material";
+import {
+ Notification,
+ type NotificationAttributes,
+} from "ente-base/components/Notification";
+import { photosTheme } from "ente-base/components/utils/theme";
+import { renderToStaticMarkup } from "react-dom/server";
+import { describe, expect, test, vi } from "vitest";
+
+const renderNotification = (attributes: Partial<NotificationAttributes>) =>
+ renderToStaticMarkup(
+ <ThemeProvider theme={photosTheme}>
+ <Notification
+ open
+ onClose={vi.fn()}
+ attributes={{
+ color: "secondary",
+ title: "Done",
+ ...attributes,
+ }}
+ />
+ </ThemeProvider>,
+ );
+
+describe("notification icons", () => {
+ test("renders imported icon data at the shared sizes", () => {
+ const markup = renderNotification({
+ startIcon: Tick02Icon,
+ endIcon: ReloadIcon,
+ endIconLabel: "Retry",
+ showCloseButtonWithEndIcon: true,
+ });
+ const icons = markup.match(/<svg\b[^>]*>/g) ?? [];
+ expect(icons).toHaveLength(3);
+ expect(icons[0]).toContain('width="24"');
+ expect(icons[1]).toContain('width="22"');
+ expect(icons[2]).toContain('width="22"');
+ for (const icon of icons) expect(icon).toContain('stroke-width="1.8"');
+ expect(markup).toContain('aria-label="Retry"');
+ });
+
+ test("preserves custom icon elements and their sizing", () => {
+ const markup = renderNotification({
+ startIcon: null,
+ endIcon: (
+ <span data-testid="custom-copy">
+ <HugeiconsIcon
+ icon={Copy01Icon}
+ size={18}
+ strokeWidth={2}
+ />
+ </span>
+ ),
+ });
+ expect(markup).toContain('data-testid="custom-copy"');
+ const icons = markup.match(/<svg\b[^>]*>/g) ?? [];
+ expect(icons).toHaveLength(1);
+ expect(icons[0]).toContain('width="18"');
+ expect(icons[0]).toContain('stroke-width="2"');
+ });
+
+ test("keeps the default leading icon and allows explicitly omitting it", () => {
+ const defaultMarkup = renderNotification({});
+ const noLeadingIconMarkup = renderNotification({ startIcon: null });
+ expect(defaultMarkup.match(/<svg\b/g)).toHaveLength(2);
+ expect(noLeadingIconMarkup.match(/<svg\b/g)).toHaveLength(1);
+ });
+});
diff --git a/web/packages/base/components/Notification.tsx b/web/packages/base/components/Notification.tsx
index db200250cd..1bf3e2f3c0 100644
--- a/web/packages/base/components/Notification.tsx
+++ b/web/packages/base/components/Notification.tsx
@@ -3,7 +3,7 @@ import {
Cancel01Icon,
InformationCircleIcon,
} from "@hugeicons/core-free-icons";
-import { HugeiconsIcon } from "@hugeicons/react";
+import { HugeiconsIcon, type IconSvgElement } from "@hugeicons/react";
import {
Box,
IconButton,
@@ -23,15 +23,17 @@ import { isSxArray } from "ente-base/components/utils/sx";
import { t } from "i18next";
import React from "react";
+type NotificationIcon = IconSvgElement | React.ReactElement | null;
+
export interface NotificationAttributes {
captionFirst?: boolean;
color: ButtonProps["color"];
// Set to null to omit the leading icon.
- startIcon?: React.ReactNode;
+ startIcon?: NotificationIcon;
title: React.ReactNode;
caption?: React.ReactNode;
onClick?: () => void;
- endIcon?: React.ReactNode;
+ endIcon?: NotificationIcon;
endIconLabel?: string;
showCloseButtonWithEndIcon?: boolean;
onEndIconClick?: () => void;
@@ -46,6 +48,13 @@ type NotificationProps = ModalVisibilityProps & {
sx?: SxProps<Theme>;
};
+const renderIcon = (icon: NotificationIcon | undefined, size: number) =>
+ React.isValidElement(icon) || icon == null ? (
+ icon
+ ) : (
+ <HugeiconsIcon icon={icon} size={size} strokeWidth={1.8} />
+ );
+
const actionButtonSx = {
width: 38,
height: 38,
@@ -127,13 +136,7 @@ export const Notification: React.FC<NotificationProps> = ({
svg: { width: 24, height: 24, fontSize: 24 },
}}
>
- {startIcon ?? (
- <HugeiconsIcon
- icon={InformationCircleIcon}
- size={24}
- strokeWidth={1.8}
- />
- )}
+ {renderIcon(startIcon ?? InformationCircleIcon, 24)}
</Stack>
)}
<Stack
@@ -250,7 +253,7 @@ export const Notification: React.FC<NotificationProps> = ({
}}
sx={buttonSx}
>
- {endIcon}
+ {renderIcon(endIcon, 22)}
</IconButton>
)}
{(!endIcon || showCloseButtonWithEndIcon) && (
@@ -262,11 +265,7 @@ export const Notification: React.FC<NotificationProps> = ({
}}
sx={buttonSx}
>
- <HugeiconsIcon
- icon={Cancel01Icon}
- size={22}
- strokeWidth={1.8}
- />
+ {renderIcon(Cancel01Icon, 22)}
</IconButton>
)}
</Stack>
diff --git a/web/packages/gallery/components/DownloadStatusNotifications.tsx b/web/packages/gallery/components/DownloadStatusNotifications.tsx
index 4655589995..5ce2e2cc62 100644
--- a/web/packages/gallery/components/DownloadStatusNotifications.tsx
+++ b/web/packages/gallery/components/DownloadStatusNotifications.tsx
@@ -14,7 +14,10 @@ import {
styled,
Typography,
} from "@mui/material";
-import { Notification } from "ente-base/components/Notification";
+import {
+ Notification,
+ type NotificationAttributes,
+} from "ente-base/components/Notification";
import { useBaseContext } from "ente-base/context";
import {
isSaveComplete,
@@ -180,15 +183,9 @@ export const DownloadStatusNotifications: React.FC<
</Box>
);
- let startIcon: React.ReactNode;
+ let startIcon: NotificationAttributes["startIcon"];
if (hasErrors) {
- startIcon = (
- <HugeiconsIcon
- icon={AlertCircleIcon}
- size={24}
- strokeWidth={1.8}
- />
- );
+ startIcon = AlertCircleIcon;
} else if (isComplete) {
startIcon = (
<GlowingIconWrapper>
@@ -252,13 +249,7 @@ export const DownloadStatusNotifications: React.FC<
title: truncatedName,
caption,
onClick: createOnClick(group),
- endIcon: canRetry ? (
- <HugeiconsIcon
- icon={ReloadIcon}
- size={22}
- strokeWidth={1.8}
- />
- ) : undefined,
+ endIcon: canRetry ? ReloadIcon : undefined,
onEndIconClick: canRetry
? () => group.retry?.()
: undefined,