đź’š End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Improve public space notification prompt
Anand Baburajanec71e036b747
diff --git a/web/apps/space/src/components/SpacePWAInstallPrompt.tsx b/web/apps/space/src/components/SpacePWAInstallPrompt.tsxindex a7428185b5..4dabd0fd64 100644--- a/web/apps/space/src/components/SpacePWAInstallPrompt.tsx+++ b/web/apps/space/src/components/SpacePWAInstallPrompt.tsx@@ -151,35 +151,53 @@ export const SpacePWAInstallPrompt: React.FC<SpacePWAInstallPromptProps> = ({interface SpacePWAPromptBannerProps {actionDisabled?: boolean;- actionLabel: string;- dismissLabel: string;+ actionLabel?: string;+ dismissLabel?: string;icon: Parameters<typeof HugeiconsIcon>[0]["icon"];+ hidden?: boolean;label: string;- onAction: () => void;- onDismiss: () => void;+ onAction?: () => void;+ onDismiss?: () => void;+ placement?: "bottom" | "top";}-const SpacePWAPromptBanner: React.FC<SpacePWAPromptBannerProps> = ({+export const SpacePWAPromptBanner: React.FC<SpacePWAPromptBannerProps> = ({actionDisabled,actionLabel,dismissLabel,icon,+ hidden = false,label,onAction,onDismiss,+ placement = "top",}) => (<Box+ aria-hidden={hidden}sx={{+ bottom:+ placement == "bottom"+ ? "calc(env(safe-area-inset-bottom) + 16px)"+ : undefined,boxSizing: "border-box",left: "50%",px: "16px",pointerEvents: "none",position: "fixed",- top: "calc(env(safe-area-inset-top) + 10px)",- transform: "translateX(-50%)",+ top:+ placement == "top"+ ? "calc(env(safe-area-inset-top) + 10px)"+ : undefined,+ transform: hidden+ ? placement == "bottom"+ ? "translate(-50%, calc(100% + env(safe-area-inset-bottom) + 16px))"+ : "translate(-50%, calc(-100% - env(safe-area-inset-top) - 10px))"+ : "translate(-50%, 0)",+ transition: "transform 180ms ease",width: "100%",zIndex: 19,"@media (min-width: 600px)": { maxWidth: 390 },+ "@media (prefers-reduced-motion: reduce)": { transition: "none" },}}><Box@@ -198,7 +216,7 @@ const SpacePWAPromptBanner: React.FC<SpacePWAPromptBannerProps> = ({gap: "10px",lineHeight: "20px",minHeight: 50,- pointerEvents: "auto",+ pointerEvents: hidden ? "none" : "auto",pl: "10px",pr: "6px",py: "3px",@@ -224,6 +242,7 @@ const SpacePWAPromptBanner: React.FC<SpacePWAPromptBannerProps> = ({flex: "1 1 auto",minWidth: 0,overflow: "hidden",+ textAlign: "left",textOverflow: "ellipsis",whiteSpace: "nowrap",}}@@ -231,56 +250,60 @@ const SpacePWAPromptBanner: React.FC<SpacePWAPromptBannerProps> = ({{label}</Box><Box sx={{ alignItems: "center", display: "flex", flexShrink: 0 }}>- <Box- className="green-bg"- component="button"- type="button"- disabled={actionDisabled}- onClick={onAction}- sx={{- alignItems: "center",- bgcolor: green,- border: 0,- borderRadius: "14px",- color: "#FFFFFF",- cursor: actionDisabled ? "default" : "pointer",- display: "flex",- fontFamily: '"Inter Variable", Inter, sans-serif',- fontSize: 13,- fontWeight: 700,- height: 34,- justifyContent: "center",- minWidth: 48,- opacity: actionDisabled ? 0.7 : 1,- px: "17px",- }}- >- {actionLabel}- </Box>- <Box- component="button"- type="button"- aria-label={dismissLabel}- onClick={onDismiss}- sx={{- alignItems: "center",- bgcolor: "transparent",- border: 0,- color: textBase,- cursor: "pointer",- display: "flex",- height: spaceTouchTargetSize,- justifyContent: "center",- p: 0,- width: 36,- }}- >- <HugeiconsIcon- icon={MultiplicationSignIcon}- size={16}- strokeWidth={2}- />- </Box>+ {onAction && (+ <Box+ className="green-bg"+ component="button"+ type="button"+ disabled={actionDisabled}+ onClick={onAction}+ sx={{+ alignItems: "center",+ bgcolor: green,+ border: 0,+ borderRadius: "14px",+ color: "#FFFFFF",+ cursor: actionDisabled ? "default" : "pointer",+ display: "flex",+ fontFamily: '"Inter Variable", Inter, sans-serif',+ fontSize: 13,+ fontWeight: 700,+ height: 34,+ justifyContent: "center",+ minWidth: 48,+ opacity: actionDisabled ? 0.7 : 1,+ px: "17px",+ }}+ >+ {actionLabel}+ </Box>+ )}+ {onDismiss && (+ <Box+ component="button"+ type="button"+ aria-label={dismissLabel}+ onClick={onDismiss}+ sx={{+ alignItems: "center",+ bgcolor: "transparent",+ border: 0,+ color: textBase,+ cursor: "pointer",+ display: "flex",+ height: spaceTouchTargetSize,+ justifyContent: "center",+ p: 0,+ width: 36,+ }}+ >+ <HugeiconsIcon+ icon={MultiplicationSignIcon}+ size={16}+ strokeWidth={2}+ />+ </Box>+ )}</Box></Box></Box>diff --git a/web/apps/space/src/components/SpacePublicProfileNotificationControl.tsx b/web/apps/space/src/components/SpacePublicProfileNotificationControl.tsxindex d22e03bddd..1ed6da25e4 100644--- a/web/apps/space/src/components/SpacePublicProfileNotificationControl.tsx+++ b/web/apps/space/src/components/SpacePublicProfileNotificationControl.tsx@@ -1,11 +1,14 @@import {Notification02Icon,ScreenAddToHomeIcon,+ Tick02Icon,} from "@hugeicons/core-free-icons";-import { HugeiconsIcon, type IconSvgElement } from "@hugeicons/react";-import { Box } from "@mui/material";import { SpaceNotificationPermissionInstructions } from "components/SpaceNotificationPermissionInstructions";-import { SpacePWAInstallInstructions } from "components/SpacePWAInstallPrompt";+import {+ SpacePWAInstallInstructions,+ SpacePWAPromptBanner,+} from "components/SpacePWAInstallPrompt";+import { useHideOnScrollDirection } from "hooks/useHideOnScrollDirection";import {isSpaceIOS,isSpaceStandalone,@@ -20,6 +23,11 @@ import {type SpaceWebPushState,} from "services/spaceWebPush";+type SuccessState = "exiting" | "hidden" | "visible";++const successDisplayDurationMs = 2400;+const toastTransitionDurationMs = 180;+interface SpacePublicProfileNotificationControlProps {session: PublicSpaceLinkSession;}@@ -29,8 +37,11 @@ export const SpacePublicProfileNotificationControl: React.FC<> = ({ session }) => {const installPrompt = useSpacePWAInstallPrompt();const updating = React.useRef(false);+ const successTimer = React.useRef<number | undefined>(undefined);const [state, setState] = React.useState<SpaceWebPushState>("unavailable");const [busy, setBusy] = React.useState(true);+ const [successState, setSuccessState] =+ React.useState<SuccessState>("hidden");const [installInstructionsOpen, setInstallInstructionsOpen] =React.useState(false);const [permissionInstructionsOpen, setPermissionInstructionsOpen] =@@ -40,6 +51,16 @@ export const SpacePublicProfileNotificationControl: React.FC<? "": `${window.location.pathname}${window.location.search}${window.location.hash}`;const requiresIOSInstall = isSpaceIOS() && !isSpaceStandalone();+ const isHiddenForScroll = useHideOnScrollDirection();++ React.useEffect(+ () => () => {+ if (successTimer.current !== undefined) {+ window.clearTimeout(successTimer.current);+ }+ },+ [],+ );const reconcile = React.useCallback(async () => {if (!route || !isSpaceWebPushSupported() || requiresIOSInstall) {@@ -84,29 +105,22 @@ export const SpacePublicProfileNotificationControl: React.FC<const canShowNotifications =!requiresIOSInstall && isSpaceWebPushSupported();- const showNotificationButton =+ const showNotificationAction =canShowNotifications &&(updating.current ||(!busy && state != "subscribed" && state != "unavailable"));- const showNotificationStatus =- canShowNotifications && !busy && state == "subscribed";- const showInstall = requiresIOSInstall && installPrompt.canInstall;- const reserveControlSpace =- busy && (canShowNotifications || requiresIOSInstall);- if (- !showNotificationButton &&- !showNotificationStatus &&- !showInstall &&- !reserveControlSpace- ) {- return null;- }+ const showInstallPrompt = requiresIOSInstall && installPrompt.shouldShow;const enable = async () => {if (Notification.permission == "denied") {setPermissionInstructionsOpen(true);return;}+ if (successTimer.current !== undefined) {+ window.clearTimeout(successTimer.current);+ successTimer.current = undefined;+ }+ setSuccessState("hidden");updating.current = true;setBusy(true);try {@@ -116,6 +130,14 @@ export const SpacePublicProfileNotificationControl: React.FC<);if (permission == "granted") {setState("subscribed");+ setSuccessState("visible");+ successTimer.current = window.setTimeout(() => {+ setSuccessState("exiting");+ successTimer.current = window.setTimeout(() => {+ successTimer.current = undefined;+ setSuccessState("hidden");+ }, toastTransitionDurationMs);+ }, successDisplayDurationMs);} else if (permission == "denied") {setState("denied");setPermissionInstructionsOpen(true);@@ -129,43 +151,44 @@ export const SpacePublicProfileNotificationControl: React.FC<}};- const label = busy ? "Enabling…" : "Get notified of new posts";-return (<>- <Box- sx={{- alignItems: "center",- display: "flex",- flexWrap: "wrap",- gap: "8px",- justifyContent: "center",- minHeight: 40,- mt: "14px",- }}- >- {showNotificationButton && (- <PublicProfileControlButton- busy={busy}- icon={Notification02Icon}- label={label}- onClick={() => void enable()}- />- )}- {showNotificationStatus && <PublicProfileNotificationStatus />}- {showInstall && (- <PublicProfileControlButton- icon={ScreenAddToHomeIcon}- label="Add to home screen"- onClick={() => setInstallInstructionsOpen(true)}- />- )}- </Box>+ {successState != "hidden" ? (+ <SpacePWAPromptBanner+ hidden={isHiddenForScroll || successState == "exiting"}+ icon={Tick02Icon}+ label="You’ll be notified about new posts"+ placement="bottom"+ />+ ) : showNotificationAction ? (+ <SpacePWAPromptBanner+ actionDisabled={busy}+ actionLabel={busy ? "Enabling…" : "Enable"}+ hidden={isHiddenForScroll}+ icon={Notification02Icon}+ label="Get notified about new posts"+ onAction={() => void enable()}+ placement="bottom"+ />+ ) : null}+ {showInstallPrompt && (+ <SpacePWAPromptBanner+ actionLabel="Add"+ hidden={isHiddenForScroll}+ icon={ScreenAddToHomeIcon}+ label="Add to home screen"+ onAction={() => setInstallInstructionsOpen(true)}+ placement="bottom"+ />+ )}<SpacePWAInstallInstructionsmode={installPrompt.mode}open={installInstructionsOpen}onClose={() => setInstallInstructionsOpen(false)}- onDismiss={() => setInstallInstructionsOpen(false)}+ onDismiss={() => {+ setInstallInstructionsOpen(false);+ installPrompt.dismiss();+ }}/><SpaceNotificationPermissionInstructionsopen={permissionInstructionsOpen}@@ -174,61 +197,3 @@ export const SpacePublicProfileNotificationControl: React.FC<</>);};--const PublicProfileNotificationStatus: React.FC = () => (- <Box- role="status"- sx={{- alignItems: "center",- color: "#777777",- display: "inline-flex",- fontFamily: '"Inter Variable", Inter, sans-serif',- fontSize: 14,- fontWeight: 500,- gap: "8px",- minHeight: 40,- }}- >- <HugeiconsIcon icon={Notification02Icon} size={18} strokeWidth={1.9} />- You’ll be notified of new posts- </Box>-);--const PublicProfileControlButton: React.FC<{- busy?: boolean;- icon: IconSvgElement;- label: string;- onClick: () => void;-}> = ({ busy, icon, label, onClick }) => (- <Box- component="button"- type="button"- disabled={busy}- onClick={onClick}- sx={{- alignItems: "center",- appearance: "none",- bgcolor: "#F2F2F2",- border: 0,- borderRadius: "14px",- color: "#1B1B1B",- cursor: busy ? "default" : "pointer",- display: "inline-flex",- fontFamily: '"Inter Variable", Inter, sans-serif',- fontSize: 14,- fontWeight: 600,- gap: "8px",- minHeight: 40,- opacity: busy ? 0.7 : 1,- px: "16px",- "&:hover": { bgcolor: busy ? "#F2F2F2" : "#E7E7E7" },- "&:focus-visible": {- outline: "2px solid #1B1B1B",- outlineOffset: 2,- },- }}- >- <HugeiconsIcon icon={icon} size={18} strokeWidth={1.9} />- {label}- </Box>-);diff --git a/web/apps/space/src/hooks/useHideOnScrollDirection.ts b/web/apps/space/src/hooks/useHideOnScrollDirection.tsnew file mode 100644index 0000000000..30308d4b64--- /dev/null+++ b/web/apps/space/src/hooks/useHideOnScrollDirection.ts@@ -0,0 +1,60 @@+import React from "react";++const hideStartY = 96;+const hideDelta = 4;++const pageScrollY = () =>+ Math.max(+ 0,+ window.scrollY ||+ document.scrollingElement?.scrollTop ||+ document.documentElement.scrollTop ||+ document.body.scrollTop ||+ 0,+ );++export const useHideOnScrollDirection = () => {+ const [isHidden, setIsHidden] = React.useState(false);+ const lastScrollYRef = React.useRef(0);+ const frameRef = React.useRef<number | null>(null);++ React.useEffect(() => {+ lastScrollYRef.current = pageScrollY();++ const updateVisibility = () => {+ frameRef.current = null;+ const nextScrollY = pageScrollY();+ const delta = nextScrollY - lastScrollYRef.current;+ lastScrollYRef.current = nextScrollY;++ if (nextScrollY <= hideStartY) {+ setIsHidden(false);+ return;+ }++ if (delta > hideDelta) {+ setIsHidden(true);+ return;+ }++ if (delta < -1) setIsHidden(false);+ };++ const scheduleUpdate = () => {+ if (frameRef.current != null) return;+ frameRef.current = window.requestAnimationFrame(updateVisibility);+ };++ window.addEventListener("scroll", scheduleUpdate, { passive: true });+ document.addEventListener("scroll", scheduleUpdate, { passive: true });+ return () => {+ window.removeEventListener("scroll", scheduleUpdate);+ document.removeEventListener("scroll", scheduleUpdate);+ if (frameRef.current != null) {+ window.cancelAnimationFrame(frameRef.current);+ }+ };+ }, []);++ return isHidden;+};diff --git a/web/apps/space/src/screens/HomeScreen.tsx b/web/apps/space/src/screens/HomeScreen.tsxindex 748717ab84..942fb1618d 100644--- a/web/apps/space/src/screens/HomeScreen.tsx+++ b/web/apps/space/src/screens/HomeScreen.tsx@@ -28,6 +28,7 @@ import { SpaceLoadingSpinner } from "components/SpaceRouteFallback";import { SpaceShareInviteButton } from "components/SpaceShareInviteButton";import log from "ente-base/log";import { useBrowserBackClose } from "hooks/useBrowserBackClose";+import { useHideOnScrollDirection } from "hooks/useHideOnScrollDirection";import React, { useState } from "react";import type { SetupProfile } from "screens/SetupProfileScreen";import type {@@ -63,8 +64,6 @@ const headerAvatarSize = 28;const feedAvatarSize = 38;const headerHeight = 64;const headerIconSize = 30;-const headerHideStartY = 96;-const headerScrollDelta = 4;const headerSideWidth = 32;const feedLikeActionSize = spaceTouchTargetSize;const feedActionIconSize = 20;@@ -521,16 +520,6 @@ const useDecodedImage = (return { ready: !src, src };};-const pageScrollY = () =>- Math.max(- 0,- window.scrollY ||- document.scrollingElement?.scrollTop ||- document.documentElement.scrollTop ||- document.body.scrollTop ||- 0,- );-const scrollPageToTop = () => {const behavior = window.matchMedia("(prefers-reduced-motion: reduce)").matches@@ -550,52 +539,6 @@ const scheduleScrollPageToTop = () => {};};-const useHideHeaderOnScrollDirection = () => {- const [isHidden, setIsHidden] = useState(false);- const lastScrollYRef = React.useRef(0);- const frameRef = React.useRef<number | null>(null);-- React.useEffect(() => {- lastScrollYRef.current = pageScrollY();-- const updateVisibility = () => {- frameRef.current = null;- const nextScrollY = pageScrollY();- const delta = nextScrollY - lastScrollYRef.current;- lastScrollYRef.current = nextScrollY;-- if (nextScrollY <= headerHideStartY) {- setIsHidden(false);- return;- }-- if (delta > headerScrollDelta) {- setIsHidden(true);- return;- }-- if (delta < -1) setIsHidden(false);- };-- const scheduleUpdate = () => {- if (frameRef.current != null) return;- frameRef.current = window.requestAnimationFrame(updateVisibility);- };-- window.addEventListener("scroll", scheduleUpdate, { passive: true });- document.addEventListener("scroll", scheduleUpdate, { passive: true });- return () => {- window.removeEventListener("scroll", scheduleUpdate);- document.removeEventListener("scroll", scheduleUpdate);- if (frameRef.current != null) {- window.cancelAnimationFrame(frameRef.current);- }- };- }, []);-- return isHidden;-};-const usePostingDotCount = (isPosting: boolean) => {const [dotCount, setDotCount] = useState(1);@@ -1543,7 +1486,7 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({Record<string, string>>({});const [feedScrollRequest, setFeedScrollRequest] = useState(0);- const isHeaderTriggered = useHideHeaderOnScrollDirection();+ const isHeaderTriggered = useHideOnScrollDirection();const [isHeaderFocused, setIsHeaderFocused] = useState(false);const isHeaderHidden = isHeaderTriggered && !isHeaderFocused;const postInputRef = React.useRef<HTMLInputElement | null>(null);diff --git a/web/apps/space/src/screens/ProfileScreen.tsx b/web/apps/space/src/screens/ProfileScreen.tsxindex 3588021cb1..29dc4cc1ec 100644--- a/web/apps/space/src/screens/ProfileScreen.tsx+++ b/web/apps/space/src/screens/ProfileScreen.tsx@@ -1676,7 +1676,15 @@ export const ProfileScreen: React.FC<ProfileScreenProps> = ({</Box></Box>)}- {isPublicProfile && publicNotificationControl}+ {isPublicProfile && publicNotificationControl && (+ <Box+ sx={{+ display: selectedPost ? "none" : "contents",+ }}+ >+ {publicNotificationControl}+ </Box>+ )}</Box></Box><Box