Skip to content

armgit / ente

Public Imported from GitHub
0

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

Add animated pokes and empty tile backgrounds in Space

Anand Baburajan89721957998c
diff --git a/web/apps/space/src/components/FriendTilePokeButton.tsx b/web/apps/space/src/components/FriendTilePokeButton.tsx
new file mode 100644
index 0000000000..fea53a433d
--- /dev/null
+++ b/web/apps/space/src/components/FriendTilePokeButton.tsx
@@ -0,0 +1,142 @@
+import { HandPointingLeftIcon } from "@hugeicons/core-free-icons";
+import { HugeiconsIcon } from "@hugeicons/react";
+import { Box } from "@mui/material";
+import type { SpaceActionPhase } from "components/ActionFeedback";
+import log from "ente-base/log";
+import React from "react";
+import { spaceAppBackgroundColor, spaceText } from "styles/colors";
+import { spaceTileCircleInset } from "styles/tiles";
+import { spaceTouchTargetSize } from "styles/touch-targets";
+
+const iconSize = 18;
+const pokeAnimationDurationMs = 2000;
+
+export const FriendTilePokeButton: React.FC<{
+ avatarSize: number;
+ name: string;
+ onPoke: () => Promise<void>;
+ tileWidth: number;
+}> = ({ avatarSize, name, onPoke, tileWidth }) => {
+ const [phase, setPhase] = React.useState<SpaceActionPhase | null>(null);
+ const [failed, setFailed] = React.useState(false);
+ const iconTipInset = avatarSize / 12;
+ const inset = `calc(${spaceTileCircleInset(avatarSize)} - ${(spaceTouchTargetSize - avatarSize) / 2}px)`;
+ const contactX = `calc(${2 * avatarSize - iconTipInset - tileWidth}px + 2 * ${spaceTileCircleInset(avatarSize)})`;
+
+ React.useEffect(() => {
+ if (phase != "done") return;
+ const timeout = window.setTimeout(
+ () => setPhase(null),
+ pokeAnimationDurationMs + 100,
+ );
+ return () => window.clearTimeout(timeout);
+ }, [phase]);
+
+ const poke = async () => {
+ setPhase("busy");
+ setFailed(false);
+ try {
+ await onPoke();
+ setPhase("done");
+ } catch (error) {
+ log.error("Failed to send poke", error);
+ setPhase(null);
+ setFailed(true);
+ }
+ };
+
+ const label = failed
+ ? `Couldn't poke ${name}. Tap to retry.`
+ : phase == "busy"
+ ? `Poking ${name}`
+ : phase == "done"
+ ? `Poked ${name}`
+ : `Poke ${name}`;
+
+ return (
+ <Box
+ component="button"
+ type="button"
+ aria-label={label}
+ aria-live="polite"
+ aria-busy={phase == "busy"}
+ title={label}
+ disabled={phase != null}
+ onClick={() => void poke()}
+ sx={{
+ "--space-poke-contact-x": contactX,
+ "--space-poke-icon-scale": avatarSize / iconSize,
+ alignItems: "center",
+ appearance: "none",
+ bgcolor: "transparent",
+ border: 0,
+ borderRadius: "999px",
+ bottom: inset,
+ color: failed
+ ? "#F63A3A"
+ : phase
+ ? "#08C225"
+ : spaceAppBackgroundColor,
+ cursor: phase ? "default" : "pointer",
+ display: "flex",
+ height: spaceTouchTargetSize,
+ justifyContent: "center",
+ lineHeight: 0,
+ p: 0,
+ position: "absolute",
+ right: inset,
+ width: spaceTouchTargetSize,
+ zIndex: 3,
+ "&:focus-visible": {
+ outline: `2px solid ${spaceText}`,
+ outlineOffset: 2,
+ },
+ }}
+ >
+ <Box
+ component="span"
+ sx={{
+ alignItems: "center",
+ bgcolor: "#FFFFFF",
+ borderRadius: "50%",
+ display: "flex",
+ height: avatarSize,
+ justifyContent: "center",
+ width: avatarSize,
+ }}
+ >
+ <Box
+ component="span"
+ aria-hidden
+ sx={{
+ animation: phase
+ ? `spaceTilePokeJab ${pokeAnimationDurationMs}ms ease-in-out`
+ : "none",
+ display: "flex",
+ pointerEvents: "none",
+ "@keyframes spaceTilePokeJab": {
+ "0%, 100%": { transform: "translateX(0) scale(1)" },
+ "27.5%, 52%, 73.75%": {
+ transform:
+ "translateX(calc(var(--space-poke-contact-x) + 8px)) scale(var(--space-poke-icon-scale))",
+ },
+ "41%, 63%": {
+ transform:
+ "translateX(var(--space-poke-contact-x)) scale(var(--space-poke-icon-scale))",
+ },
+ },
+ "@media (prefers-reduced-motion: reduce)": {
+ animation: "none",
+ },
+ }}
+ >
+ <HugeiconsIcon
+ icon={HandPointingLeftIcon}
+ size={iconSize}
+ strokeWidth={2}
+ />
+ </Box>
+ </Box>
+ </Box>
+ );
+};
diff --git a/web/apps/space/src/pages/layout-demo.tsx b/web/apps/space/src/pages/layout-demo.tsx
index e77b0afd19..665210db4d 100644
--- a/web/apps/space/src/pages/layout-demo.tsx
+++ b/web/apps/space/src/pages/layout-demo.tsx
@@ -119,6 +119,7 @@ const LayoutDemoPost: React.FC<LayoutDemoPostProps> = ({
friendRequestDirection ? () => undefined : undefined
}
onOpenPosts={() => undefined}
+ onPoke={() => Promise.resolve()}
isNineTileLayout={count == maximumHomeTileCount}
isTwoTileLayout={count == 2}
placement={placement}
diff --git a/web/apps/space/src/screens/HomeScreen.tsx b/web/apps/space/src/screens/HomeScreen.tsx
index efea5e467c..14ad2bb643 100644
--- a/web/apps/space/src/screens/HomeScreen.tsx
+++ b/web/apps/space/src/screens/HomeScreen.tsx
@@ -15,6 +15,7 @@ import {
type SpaceViewerPostActionMode,
} from "components/FileViewer";
import { FriendQuickActionsDialog } from "components/FriendQuickActionsDialog";
+import { FriendTilePokeButton } from "components/FriendTilePokeButton";
import { SpaceHomeHeader, spaceHomeHeaderHeight } from "components/HomeHeader";
import { SpaceNewPostButton } from "components/NewPostButton";
import {
@@ -61,6 +62,7 @@ import {
import { createLoadedLocalPostPhoto } from "utils/local-post-photo";
import {
canPreviewSpaceImageFile,
+ spaceDefaultCoverImagePath,
spacePostImageErrorMessage,
spacePostImageInputAccept,
spacePostPreviewImageForFile,
@@ -271,6 +273,7 @@ interface FriendPostTileProps {
onOpenFriend?: HomeScreenProps["onOpenFriend"];
onOpenAvatar?: (anchorRect: DOMRect) => void;
onOpenFriendRequest?: () => void;
+ onPoke?: () => Promise<void>;
onOpenPosts: (
friend: FriendProfile,
posts: SpacePost[],
@@ -300,6 +303,7 @@ export const FriendPostTile: React.FC<FriendPostTileProps> = ({
onOpenAvatar,
onOpenFriendRequest,
onOpenPosts,
+ onPoke,
isNineTileLayout = false,
isTwoTileLayout = false,
placement,
@@ -318,6 +322,7 @@ export const FriendPostTile: React.FC<FriendPostTileProps> = ({
);
const post = posts[0];
const isRequestPending = Boolean(friendRequestDirection);
+ const showPokeButton = !isLoading && !post && !isRequestPending && onPoke;
const isFriendRequestActionBusy = friendRequestAction != null;
const canOpenFriendRequest =
friendRequestDirection == "sent" && Boolean(onOpenFriendRequest);
@@ -510,6 +515,12 @@ export const FriendPostTile: React.FC<FriendPostTileProps> = ({
!isLoading && (!post || postUnavailable)
? mediaPlaceholderColor
: "transparent",
+ backgroundImage:
+ !isLoading && !post
+ ? `linear-gradient(rgba(0, 0, 0, 0.3), rgba(0, 0, 0, 0.3)), url("${spaceDefaultCoverImagePath}")`
+ : undefined,
+ backgroundPosition: "center",
+ backgroundSize: "cover",
border: 0,
borderRadius: "inherit",
color: textBase,
@@ -655,6 +666,14 @@ export const FriendPostTile: React.FC<FriendPostTileProps> = ({
<SpacePostUnreadBadge count={posts.length} />
))}
</Box>
+ {showPokeButton && (
+ <FriendTilePokeButton
+ avatarSize={avatarSize}
+ name={displayName}
+ onPoke={onPoke}
+ tileWidth={placement.width}
+ />
+ )}
{friendRequestDirection != "received" &&
!isAvatarPending &&
decodedAvatar.ready && (
@@ -1442,6 +1461,7 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({
setSelectedContact({ anchorRect, friend, avatarUrl })
}
onOpenPosts={openPostPhotos}
+ onPoke={() => onPokeFriend(friend)}
isNineTileLayout={
orderedHomeItems.length == maximumHomeTileCount
}