Skip to content

armgit / ente

Public Imported from GitHub
0

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

Update space viewer like and caption polish

Anand Baburajan2a4a84649ae4
diff --git a/web/apps/space/src/components/SpaceFileViewer.tsx b/web/apps/space/src/components/SpaceFileViewer.tsx
index cc5ee7e0c6..b69b6e2724 100644
--- a/web/apps/space/src/components/SpaceFileViewer.tsx
+++ b/web/apps/space/src/components/SpaceFileViewer.tsx
@@ -15,6 +15,12 @@ import {
spaceActionDoneDurationMs,
type SpaceActionPhase,
} from "components/SpaceActionFeedback";
+import {
+ spacePostLikeButtonPop,
+ spacePostLikeHeartPop,
+ spacePostLikePopDurationMs,
+ spacePostLikePopTiming,
+} from "components/SpacePostLikeAnimation";
import type PhotoSwipe from "photoswipe";
import React from "react";
import { firstNameFrom, formatSpaceDate } from "utils/spaceDisplay";
@@ -264,6 +270,7 @@ export const SpaceFileViewer: React.FC<SpaceFileViewerProps> = ({
const [isPhotoLiked, setIsPhotoLiked] = React.useState(
activePhoto.viewerLiked ?? false,
);
+ const [photoLikePopID, setPhotoLikePopID] = React.useState(0);
const [caption, setCaption] = React.useState(activePhoto.caption ?? "");
const [replyText, setReplyText] = React.useState("");
const [isReplyFocused, setIsReplyFocused] =
@@ -311,6 +318,8 @@ export const SpaceFileViewer: React.FC<SpaceFileViewerProps> = ({
const isReplyMode =
canReplyToPost &&
(isReplyFocused || replyText.trim().length > 0 || isReplyActionRunning);
+ const isPhotoLikePopping =
+ !isReplyMode && isPhotoLiked && photoLikePopID > 0;
const canSendReply =
canReplyToPost &&
Boolean(activePhoto.postId) &&
@@ -328,13 +337,15 @@ export const SpaceFileViewer: React.FC<SpaceFileViewerProps> = ({
isDraftPostPreviewPending;
const handlePhotoLikeClick = () => {
+ const nextLiked = !isPhotoLiked;
if (!activePhoto.postId || !onSetPostLiked) {
- setIsPhotoLiked((isLiked) => !isLiked);
+ setIsPhotoLiked(nextLiked);
+ if (nextLiked) setPhotoLikePopID((id) => id + 1);
return;
}
- const nextLiked = !isPhotoLiked;
setIsPhotoLiked(nextLiked);
+ if (nextLiked) setPhotoLikePopID((id) => id + 1);
void onSetPostLiked(activePhoto.postId, nextLiked).catch(
(error: unknown) => {
console.error("Failed to update post like", error);
@@ -522,6 +533,20 @@ export const SpaceFileViewer: React.FC<SpaceFileViewerProps> = ({
focusReplyOnOpen,
]);
+ React.useEffect(() => {
+ setPhotoLikePopID(0);
+ }, [activePhoto.imageUrl, activePhoto.postId]);
+
+ React.useEffect(() => {
+ if (photoLikePopID == 0) return;
+
+ const timeoutID = window.setTimeout(
+ () => setPhotoLikePopID(0),
+ spacePostLikePopDurationMs,
+ );
+ return () => window.clearTimeout(timeoutID);
+ }, [photoLikePopID]);
+
React.useEffect(() => {
const pswp = pswpRef.current;
if (!pswp) return;
@@ -1273,27 +1298,35 @@ export const SpaceFileViewer: React.FC<SpaceFileViewerProps> = ({
fontFamily: '"Inter Variable", Inter, sans-serif',
fontSize: 14,
fontWeight: 650,
- bgcolor: "rgba(48, 48, 48, 0.82)",
- borderRadius: "10px",
left: "50%",
- lineHeight: "20px",
+ lineHeight: "23px",
m: 0,
- maxWidth: "calc(100vw - 32px)",
+ maxWidth: "90vw",
minWidth: 0,
- overflow: "hidden",
- px: "8px",
- py: "2px",
+ overflowWrap: "break-word",
position: "fixed",
textAlign: "center",
- textOverflow: "ellipsis",
textShadow: "0 1px 10px rgba(0, 0, 0, 0.74)",
top: "85%",
transform: "translateX(-50%)",
- whiteSpace: "nowrap",
+ whiteSpace: "pre-wrap",
+ width: "90vw",
zIndex: 2,
}}
>
- {displayCaption}
+ <Box
+ component="span"
+ sx={{
+ bgcolor: "rgba(48, 48, 48, 0.82)",
+ borderRadius: "10px",
+ boxDecorationBreak: "clone",
+ px: "8px",
+ py: "2px",
+ WebkitBoxDecorationBreak: "clone",
+ }}
+ >
+ {displayCaption}
+ </Box>
</Box>
)}
{showPhotoLikeButton && (
@@ -1415,6 +1448,9 @@ export const SpaceFileViewer: React.FC<SpaceFileViewerProps> = ({
}
sx={{
...viewerActionButtonSx,
+ animation: isPhotoLikePopping
+ ? `${spacePostLikeButtonPop} ${spacePostLikePopDurationMs}ms ${spacePostLikePopTiming} both`
+ : undefined,
bgcolor:
isReplyMode && canSendReply
? "#FFFFFF"
@@ -1431,6 +1467,9 @@ export const SpaceFileViewer: React.FC<SpaceFileViewerProps> = ({
userSelect: "none",
WebkitTouchCallout: "none",
WebkitUserSelect: "none",
+ "@media (prefers-reduced-motion: reduce)": {
+ animation: "none",
+ },
}}
>
{isReplyMode ? (
@@ -1468,15 +1507,34 @@ export const SpaceFileViewer: React.FC<SpaceFileViewerProps> = ({
/>
)
) : (
- <HugeiconsIcon
- fill={isPhotoLiked ? green : "none"}
- icon={FavouriteIcon}
- primaryColor={
- isPhotoLiked ? green : undefined
+ <Box
+ key={
+ isPhotoLikePopping
+ ? `heart-${photoLikePopID}`
+ : "heart"
}
- size={26}
- strokeWidth={1.8}
- />
+ component="span"
+ sx={{
+ animation: isPhotoLikePopping
+ ? `${spacePostLikeHeartPop} ${spacePostLikePopDurationMs}ms ${spacePostLikePopTiming} both`
+ : undefined,
+ display: "flex",
+ lineHeight: 0,
+ transformOrigin: "50% 58%",
+ "@media (prefers-reduced-motion: reduce)":
+ { animation: "none" },
+ }}
+ >
+ <HugeiconsIcon
+ fill={isPhotoLiked ? green : "none"}
+ icon={FavouriteIcon}
+ primaryColor={
+ isPhotoLiked ? green : undefined
+ }
+ size={26}
+ strokeWidth={1.8}
+ />
+ </Box>
)}
</Box>
</Box>
diff --git a/web/apps/space/src/components/SpacePostLikeAnimation.ts b/web/apps/space/src/components/SpacePostLikeAnimation.ts
new file mode 100644
index 0000000000..707153ce16
--- /dev/null
+++ b/web/apps/space/src/components/SpacePostLikeAnimation.ts
@@ -0,0 +1,47 @@
+import { keyframes } from "@mui/material/styles";
+
+export const spacePostLikePopDurationMs = 520;
+export const spacePostLikePopTiming = "cubic-bezier(0.2, 0.82, 0.22, 1)";
+
+export const spacePostLikeButtonPop = keyframes`
+ 0% {
+ transform: scale(1);
+ }
+
+ 24% {
+ transform: scale(0.88);
+ }
+
+ 55% {
+ transform: scale(1.16);
+ }
+
+ 78% {
+ transform: scale(0.97);
+ }
+
+ 100% {
+ transform: scale(1);
+ }
+`;
+
+export const spacePostLikeHeartPop = keyframes`
+ 0% {
+ opacity: 0.72;
+ transform: scale(0.58) rotate(-10deg);
+ }
+
+ 44% {
+ opacity: 1;
+ transform: scale(1.38) rotate(6deg);
+ }
+
+ 72% {
+ transform: scale(0.93) rotate(-3deg);
+ }
+
+ 100% {
+ opacity: 1;
+ transform: scale(1) rotate(0deg);
+ }
+`;
diff --git a/web/apps/space/src/screens/HomeScreen.tsx b/web/apps/space/src/screens/HomeScreen.tsx
index 5fdf46cf75..7825ef3d0f 100644
--- a/web/apps/space/src/screens/HomeScreen.tsx
+++ b/web/apps/space/src/screens/HomeScreen.tsx
@@ -7,13 +7,18 @@ import {
} from "@hugeicons/core-free-icons";
import { HugeiconsIcon } from "@hugeicons/react";
import { Box, Skeleton } from "@mui/material";
-import { keyframes } from "@mui/material/styles";
import {
SpaceFileViewer,
type SpaceViewerDraftPostEdit,
type SpaceViewerPhoto,
type SpaceViewerPostActionMode,
} from "components/SpaceFileViewer";
+import {
+ spacePostLikeButtonPop,
+ spacePostLikeHeartPop,
+ spacePostLikePopDurationMs,
+ spacePostLikePopTiming,
+} from "components/SpacePostLikeAnimation";
import { EnteLogo } from "ente-base/components/EnteLogo";
import { useBrowserBackClose } from "hooks/useBrowserBackClose";
import React, { useState } from "react";
@@ -54,7 +59,6 @@ const floatingAddIconSize = 34;
const feedLikeActionSize = 38;
const feedActionIconSize = 20;
const feedReplyIconSize = 17;
-const feedLikePopDurationMs = 520;
const emptyFeedItemGap = "22px";
const feedSkeletonAspectRatios = [
"3 / 4",
@@ -67,49 +71,6 @@ const feedSkeletonAspectRatios = [
];
const minimumFeedPhotoFrameAspectRatio = 3 / 4;
-const feedLikeButtonPop = keyframes`
- 0% {
- transform: scale(1);
- }
-
- 24% {
- transform: scale(0.88);
- }
-
- 55% {
- transform: scale(1.16);
- }
-
- 78% {
- transform: scale(0.97);
- }
-
- 100% {
- transform: scale(1);
- }
-`;
-
-const feedLikeHeartPop = keyframes`
- 0% {
- opacity: 0.72;
- transform: scale(0.58) rotate(-10deg);
- }
-
- 44% {
- opacity: 1;
- transform: scale(1.38) rotate(6deg);
- }
-
- 72% {
- transform: scale(0.93) rotate(-3deg);
- }
-
- 100% {
- opacity: 1;
- transform: scale(1) rotate(0deg);
- }
-`;
-
const FeedReplyIcon: React.FC = () => (
<svg
width={feedReplyIconSize}
@@ -490,7 +451,7 @@ const FeedLikeButton: React.FC<FeedLikeButtonProps> = ({
sx={{
alignItems: "center",
animation: isPopping
- ? `${feedLikeButtonPop} ${feedLikePopDurationMs}ms cubic-bezier(0.2, 0.82, 0.22, 1) both`
+ ? `${spacePostLikeButtonPop} ${spacePostLikePopDurationMs}ms ${spacePostLikePopTiming} both`
: undefined,
appearance: "none",
bgcolor: isLiked ? paleGreen : feedActionBackground,
@@ -527,7 +488,7 @@ const FeedLikeButton: React.FC<FeedLikeButtonProps> = ({
component="span"
sx={{
animation: isPopping
- ? `${feedLikeHeartPop} ${feedLikePopDurationMs}ms cubic-bezier(0.2, 0.82, 0.22, 1) both`
+ ? `${spacePostLikeHeartPop} ${spacePostLikePopDurationMs}ms ${spacePostLikePopTiming} both`
: undefined,
display: "flex",
lineHeight: 0,
@@ -651,7 +612,7 @@ const FeedItem: React.FC<FeedItemProps> = ({
const timeoutID = window.setTimeout(
() => setLikePopID(0),
- feedLikePopDurationMs,
+ spacePostLikePopDurationMs,
);
return () => window.clearTimeout(timeoutID);
}, [likePopID]);