Skip to content

armgit / ente

Public Imported from GitHub
0

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

Add heart and comment action buttons to file viewer

Anand Baburajanad2a5a6663ea
diff --git a/web/apps/photos/src/styles/photoswipe.css b/web/apps/photos/src/styles/photoswipe.css
index c2d861e112..39afd1c671 100644
--- a/web/apps/photos/src/styles/photoswipe.css
+++ b/web/apps/photos/src/styles/photoswipe.css
@@ -151,10 +151,6 @@
/* 4 line caption */
.pswp-ente .pswp__caption {
- position: absolute;
- bottom: 0px;
- right: 0;
- margin: 20px 24px;
border-radius: 3px;
/* Same opacity as the other controls. */
color: rgb(255 255 255 / 0.85);
@@ -176,10 +172,6 @@
}
.pswp-ente .pswp__caption.ente-video {
- /* Add extra offset for video captions so that they do not overlap with the
- video controls. The constant was picked such that it lay above the media
- controls. */
- bottom: 48px;
/* Adding a caption with a blur backdrop filter above the video element
contained in a media-controller causes a subtle tint to be overlaid on
the entire video. This is visible on both Chrome and Firefox as of
@@ -351,14 +343,14 @@ media-settings-menu {
z-index: 1;
}
-/* Hide the caption when hovering over the video controls (and when the settings
- menu is open) since they occupy similar real estate as the caption. */
+/* Hide the bottom right controls when hovering over the video controls, when
+ video is playing, or when the settings menu is open. */
body:has(
media-time-range[mediapreviewtime],
media-controller:not([mediapaused]),
media-settings-menu:not([hidden])
) {
- & .pswp-ente .pswp__caption {
+ & .pswp-ente .pswp__bottom-right-controls {
display: none;
}
}
@@ -395,7 +387,61 @@ body:has(
opacity: 1;
}
-/* Also hide the caption in video fullscreen mode */
-.pswp-ente.pswp--video-fullscreen .pswp__caption {
+/* Also hide the bottom right controls in video fullscreen mode */
+.pswp-ente.pswp--video-fullscreen .pswp__bottom-right-controls {
display: none;
}
+
+/* Bottom right controls container (action buttons + caption) */
+.pswp-ente .pswp__bottom-right-controls {
+ position: absolute;
+ bottom: 20px;
+ right: 24px;
+ display: flex;
+ flex-direction: column;
+ align-items: flex-end;
+ gap: 12px;
+}
+
+/* Extra offset for video to clear video controls */
+.pswp-ente .pswp__bottom-right-controls:has(.pswp__caption.ente-video) {
+ bottom: 100px;
+}
+
+/* Action buttons row */
+.pswp-ente .pswp__action-buttons {
+ display: flex;
+ flex-direction: row;
+ gap: 20px;
+}
+
+.pswp-ente .pswp__action-button {
+ width: 56px;
+ height: 56px;
+ border-radius: 50%;
+ background-color: rgb(0 0 0 / 0.6);
+ border: 1px solid rgb(255 255 255 / 0.12);
+ cursor: pointer;
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ transition: background-color 0.2s ease;
+}
+
+.pswp-ente .pswp__action-button:hover {
+ background-color: rgb(0 0 0 / 0.8);
+}
+
+.pswp-ente .pswp__action-button svg {
+ width: 28px;
+ height: 28px;
+ fill: white;
+}
+
+/* Reduce padding on mobile */
+@media (width < 450px) {
+ .pswp-ente .pswp__bottom-right-controls {
+ bottom: 12px;
+ right: 12px;
+ }
+}
diff --git a/web/packages/gallery/components/viewer/icons.tsx b/web/packages/gallery/components/viewer/icons.tsx
index ce8bb72ea0..7892c54d80 100644
--- a/web/packages/gallery/components/viewer/icons.tsx
+++ b/web/packages/gallery/components/viewer/icons.tsx
@@ -20,6 +20,11 @@
const paths = {
// "@mui/icons-material/ErrorOutline"
error: '<path d="M11 15h2v2h-2zm0-8h2v6h-2zm.99-5C6.47 2 2 6.48 2 12s4.47 10 9.99 10C17.52 22 22 17.52 22 12S17.52 2 11.99 2M12 20c-4.42 0-8-3.58-8-8s3.58-8 8-8 8 3.58 8 8-3.58 8-8 8" transform="translate(7, 5.7) scale(0.85)"',
+ // Custom heart outline icon (30x26 viewBox)
+ heart: '<path d="M12.4926 23.4794C8.64537 20.6025 1.02344 14.0254 1.02344 8.10676C1.02344 4.19475 3.89425 1.02344 7.84162 1.02344C9.88707 1.02344 11.9325 1.70526 14.6598 4.43253C17.3871 1.70526 19.4325 1.02344 21.478 1.02344C25.4253 1.02344 28.2962 4.19475 28.2962 8.10676C28.2962 14.0254 20.6743 20.6025 16.827 23.4794C15.5324 24.4474 13.7872 24.4474 12.4926 23.4794Z" stroke="white" stroke-width="2.04545" stroke-linecap="round" stroke-linejoin="round" fill="none"',
+ // Custom comment bubble icon (28x28 viewBox, scaled to match heart)
+ comment:
+ '<path d="M13.636 25.9087C16.0633 25.9087 18.4361 25.189 20.4544 23.8404C22.4726 22.4919 24.0456 20.5751 24.9745 18.3326C25.9034 16.09 26.1465 13.6224 25.6729 11.2417C25.1994 8.86105 24.0305 6.67426 22.3141 4.95788C20.5978 3.24151 18.411 2.07265 16.0303 1.5991C13.6496 1.12556 11.182 1.3686 8.93944 2.29749C6.69689 3.22639 4.78015 4.79941 3.43161 6.81765C2.08306 8.83589 1.36328 11.2087 1.36328 13.636C1.36328 15.6651 1.85419 17.5783 2.72692 19.2637L1.36328 25.9087L8.00828 24.5451C9.69373 25.4178 11.6083 25.9087 13.636 25.9087Z" stroke="white" stroke-width="2.04545" stroke-linecap="round" stroke-linejoin="round" fill="none" transform="translate(1.5, 1.5) scale(0.9)"',
// "@mui/icons-material/AlbumOutlined"
live: '<path d="M12 2C6.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 8m0-12.5c-2.49 0-4.5 2.01-4.5 4.5s2.01 4.5 4.5 4.5 4.5-2.01 4.5-4.5-2.01-4.5-4.5-4.5m0 5.5c-.55 0-1-.45-1-1s.45-1 1-1 1 .45 1 1-.45 1-1 1" transform="translate(2, 8.7) scale(0.75)"',
// "@mui/icons-material/VolumeUp"
@@ -91,3 +96,17 @@ const fullscreenInner = () =>
* Assumes `viewBox="0 0 24 24"`.
*/
export const settingsSVGPath = `<path d="M19.14 12.94c.04-.3.06-.61.06-.94 0-.32-.02-.64-.07-.94l2.03-1.58c.18-.14.23-.41.12-.61l-1.92-3.32c-.12-.22-.37-.29-.59-.22l-2.39.96c-.5-.38-1.03-.7-1.62-.94l-.36-2.54c-.04-.24-.24-.41-.48-.41h-3.84c-.24 0-.43.17-.47.41l-.36 2.54c-.59.24-1.13.57-1.62.94l-2.39-.96c-.22-.08-.47 0-.59.22L2.74 8.87c-.12.21-.08.47.12.61l2.03 1.58c-.05.3-.09.63-.09.94s.02.64.07.94l-2.03 1.58c-.18.14-.23.41-.12.61l1.92 3.32c.12.22.37.29.59.22l2.39-.96c.5.38 1.03.7 1.62.94l.36 2.54c.05.24.24.41.48.41h3.84c.24 0 .44-.17.47-.41l.36-2.54c.59-.24 1.13-.56 1.62-.94l2.39.96c.22.08.47 0 .59-.22l1.92-3.32c.12-.22.07-.47-.12-.61zM12 15.6c-1.98 0-3.6-1.62-3.6-3.6s1.62-3.6 3.6-3.6 3.6 1.62 3.6 3.6-1.62 3.6-3.6 3.6"></path>`;
+
+/**
+ * The path for the custom heart outline icon.
+ *
+ * Assumes `viewBox="0 0 30 26"`.
+ */
+export const heartSVGPath = paths.heart;
+
+/**
+ * The path for the custom comment bubble icon.
+ *
+ * Assumes `viewBox="0 0 28 28"`.
+ */
+export const commentSVGPath = paths.comment;
diff --git a/web/packages/gallery/components/viewer/photoswipe.ts b/web/packages/gallery/components/viewer/photoswipe.ts
index 043d2a4de2..24fd70fc57 100644
--- a/web/packages/gallery/components/viewer/photoswipe.ts
+++ b/web/packages/gallery/components/viewer/photoswipe.ts
@@ -22,7 +22,12 @@ import {
type FileViewerAnnotatedFile,
type FileViewerProps,
} from "./FileViewer";
-import { createPSRegisterElementIconHTML, settingsSVGPath } from "./icons";
+import {
+ commentSVGPath,
+ createPSRegisterElementIconHTML,
+ heartSVGPath,
+ settingsSVGPath,
+} from "./icons";
export interface FileViewerPhotoSwipeDelegate {
/**
@@ -1397,25 +1402,20 @@ export class FileViewerPhotoSwipe {
});
ui.registerElement({
- name: "caption",
+ name: "bottom-right-controls",
// After the video controls so that we don't get occluded by
// them (nb: the caption will hide when the video is playing).
order: 31,
appendTo: "root",
- // The caption uses the line-clamp CSS property, which behaves
- // unexpectedly when we also assign padding to the "p" element
- // on which we're setting the line clamp: the "clipped" lines
- // show through in the padding area.
- //
- // As a workaround, wrap the p in a div. Set the line-clamp on
- // the p, and the padding on the div.
- html: "<div><p></p></div>",
+ html: bottomRightControlsHTML(),
onInit: (element, pswp) => {
+ const captionEl =
+ element.querySelector<HTMLElement>(".pswp__caption")!;
pswp.on("change", () => {
const { fileType, alt } = currSlideData();
- element.querySelector("p")!.innerText = alt ?? "";
- element.style.visibility = alt ? "visible" : "hidden";
- element.classList.toggle(
+ captionEl.querySelector("p")!.innerText = alt ?? "";
+ captionEl.style.display = alt ? "block" : "none";
+ captionEl.classList.toggle(
"ente-video",
fileType == FileType.video,
);
@@ -1889,6 +1889,28 @@ const livePhotoVideoHTML = (videoURL: string) => `
</video>
`;
+/**
+ * HTML for the bottom right controls (action buttons + caption).
+ *
+ * The caption uses the line-clamp CSS property, which behaves unexpectedly
+ * when we also assign padding to the "p" element on which we're setting the
+ * line clamp: the "clipped" lines show through in the padding area.
+ *
+ * As a workaround, wrap the p in a div. Set the line-clamp on the p, and the
+ * padding on the div.
+ */
+const bottomRightControlsHTML = () => `
+<div class="pswp__action-buttons">
+ <button class="pswp__action-button" aria-label="Like">
+ <svg viewBox="0 0 30 26" fill="none">${heartSVGPath} /></svg>
+ </button>
+ <button class="pswp__action-button" aria-label="Comment">
+ <svg viewBox="0 0 28 28" fill="none">${commentSVGPath} /></svg>
+ </button>
+</div>
+<div class="pswp__caption"><p></p></div>
+`;
+
const createElementFromHTMLString = (htmlString: string) => {
const template = document.createElement("template");
// Excess whitespace causes excess DOM nodes, causing our firstChild to not