Skip to content

armgit / ente

Public Imported from GitHub
0

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

Move out icons

Manav Rathi84aeb7941221
diff --git a/web/packages/gallery/components/viewer/icons.tsx b/web/packages/gallery/components/viewer/icons.tsx
index 1238f7f619..ef4fadd8e1 100644
--- a/web/packages/gallery/components/viewer/icons.tsx
+++ b/web/packages/gallery/components/viewer/icons.tsx
@@ -8,12 +8,37 @@
* adding the following code in some existing React component to render the
* corresponding MUI icon React component to a string, and retain the path.
*
- * 1. import { renderToString } from "react-dom/server";
*
- * 2. console.log(renderToString(<InfoOutlinedIcon />));
+ * import { renderToString } from "react-dom/server";
+ * import InfoOutlinedIcon from ;
+ *
+ * console.log(renderToString(<InfoOutlinedIcon />));
*/
-// const html =
-// console.log(renderToString(<InfoOutlinedIcon />));
-// const path =
-// '<path d="M11 7h2v2h-2zm0 4h2v6h-2zm1-9C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2m0 18c-4.41 0-8-3.59-8-8s3.59-8 8-8 8 3.59 8 8-3.59 8-8 8"></path>';
+const paths = {
+ // "@mui/icons-material/InfoOutlined"
+ info: '<path d="M11 7h2v2h-2zm0 4h2v6h-2zm1-9C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2m0 18c-4.41 0-8-3.59-8-8s3.59-8 8-8 8 3.59 8 8-3.59 8-8 8"',
+};
+
+/**
+ * Return an object that can be passed verbatim to the "html" option expected by
+ * PhotoSwipe's registerElement function.
+ *
+ * API docs for registerElement:
+ * https://photoswipe.com/adding-ui-elements/#uiregisterelement-api
+ *
+ * Example:
+ *
+ * html: {
+ * isCustomSVG: true,
+ * inner: '<path d="M11 7h2v2h-2zm0 4h2v6h-2zm1-9C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2m0 18c-4.41 0-8-3.59-8-8s3.59-8 8-8 8 3.59 8 8-3.59 8-8 8" transform="translate(3.5, 3.5)" id="pswp__icn-info" />',
+ * outlineID: "pswp__icn-info",
+ * }
+ *
+ */
+export const createPSRegisterElementIconHTML = (name: "info") => ({
+ isCustomSVG: true,
+ // TODO(PS): This transform is temporary, audit later.
+ inner: `${paths[name]} transform="translate(3.5, 3.5)" id="pswp__icn-${name}"`,
+ outlineID: `pswp__icn-${name}`,
+});
diff --git a/web/packages/gallery/components/viewer/photoswipe.ts b/web/packages/gallery/components/viewer/photoswipe.ts
index 9f2b73d84b..aea060e0ce 100644
--- a/web/packages/gallery/components/viewer/photoswipe.ts
+++ b/web/packages/gallery/components/viewer/photoswipe.ts
@@ -10,6 +10,7 @@ import {
import type { EnteFile } from "@/media/file";
import { FileType } from "@/media/file-type";
import type { FileViewerProps } from "./FileViewer";
+import { createPSRegisterElementIconHTML } from "./icons";
// TODO(PS): WIP gallery using upstream photoswipe
//
@@ -324,19 +325,13 @@ export class FileViewerPhotoSwipe {
// - zoom: 10
// - close: 20
pswp.on("uiRegister", () => {
- const pathWithIDAndTransform =
- '<path d="M11 7h2v2h-2zm0 4h2v6h-2zm1-9C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2m0 18c-4.41 0-8-3.59-8-8s3.59-8 8-8 8 3.59 8 8-3.59 8-8 8" transform="translate(3.5, 3.5)" id="pswp__icn-info" />';
pswp.ui.registerElement({
name: "info",
title: "Info",
ariaLabel: "Info",
order: 15,
isButton: true,
- html: {
- isCustomSVG: true,
- inner: pathWithIDAndTransform,
- outlineID: "pswp__icn-info",
- },
+ html: createPSRegisterElementIconHTML("info"),
onClick: (e, element, pswp) => {
const file = this.files[pswp.currIndex];
if (!file) {