feat(entry): add scroll-to-exit tutorial with improved UX
- Add i18n support for "Scroll up to exit" text in 3 languages - Create first-time user tutorial with animated SVG demonstration - Show tutorial only once using atom-based storage persistence - Add visual hover feedback and click-to-dismiss interaction - Auto-dismiss tutorial when user actually uses scroll gesture - Improve SVG animation with clearer mouse/trackpad metaphor 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -20,6 +20,8 @@ import { AppLayoutGridContainerProvider } from "~/providers/app-grid-layout-cont
|
||||
|
||||
import { AIChatRoot } from "../ai-chat/components/layouts/AIChatRoot"
|
||||
import { useEntryContentScrollToTop } from "../entry-content/atoms"
|
||||
import { setScrollToExitTutorialSeen } from "./atoms/tutorial"
|
||||
import { ScrollToExitTutorial } from "./components/ScrollToExitTutorial"
|
||||
import { EntryColumn } from "./index"
|
||||
|
||||
const AIEntryLayoutImpl = () => {
|
||||
@@ -63,6 +65,7 @@ const AIEntryLayoutImpl = () => {
|
||||
if (accumulatedDelta.current > 1000) {
|
||||
handleCloseGesture()
|
||||
accumulatedDelta.current = 0
|
||||
setScrollToExitTutorialSeen(true)
|
||||
}
|
||||
} else {
|
||||
// Reset accumulation when scrolling down or not at top
|
||||
@@ -157,7 +160,7 @@ const AIEntryLayoutImpl = () => {
|
||||
aria-label="Scroll up or click to exit"
|
||||
>
|
||||
<div className="text-text flex items-center gap-2 rounded-full font-medium">
|
||||
<i className="i-mgc-up-cute-re repeat-[2] animate-smooth-bounce text-base" />
|
||||
<i className="i-mgc-up-cute-re repeat-[2] text-base" />
|
||||
<span>{t("entry.scroll_up_to_exit")}</span>
|
||||
</div>
|
||||
</Button>
|
||||
@@ -165,6 +168,9 @@ const AIEntryLayoutImpl = () => {
|
||||
)}
|
||||
</AnimatePresence>
|
||||
|
||||
{/* First-time user tutorial for scroll-to-exit */}
|
||||
<ScrollToExitTutorial show={!!realEntryId && isAtTop} />
|
||||
|
||||
<EntryContent entryId={realEntryId} className="h-[calc(100%-2.25rem)]" />
|
||||
</m.div>
|
||||
)}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
import { getStorageNS } from "@follow/utils/ns"
|
||||
import { atomWithStorage } from "jotai/utils"
|
||||
|
||||
import { createAtomHooks } from "~/lib/jotai"
|
||||
|
||||
const TUTORIAL_STORAGE_KEY = getStorageNS("scroll-to-exit-tutorial-seen")
|
||||
|
||||
// Create atom with storage for tutorial seen state
|
||||
const scrollToExitTutorialSeenAtom = atomWithStorage<boolean>(TUTORIAL_STORAGE_KEY, false)
|
||||
|
||||
// Create hooks for the atom
|
||||
export const [
|
||||
,
|
||||
,
|
||||
useScrollToExitTutorialSeen,
|
||||
,
|
||||
getScrollToExitTutorialSeen,
|
||||
setScrollToExitTutorialSeen,
|
||||
] = createAtomHooks(scrollToExitTutorialSeenAtom)
|
||||
+148
@@ -0,0 +1,148 @@
|
||||
import { Spring } from "@follow/components/constants/spring.js"
|
||||
import { AnimatePresence } from "motion/react"
|
||||
import { useCallback, useEffect } from "react"
|
||||
import { useTranslation } from "react-i18next"
|
||||
|
||||
import { m } from "~/components/common/Motion"
|
||||
|
||||
import { setScrollToExitTutorialSeen, useScrollToExitTutorialSeen } from "../atoms/tutorial"
|
||||
|
||||
// Simplified and clearer scroll gesture icon
|
||||
const ScrollGestureIcon = () => (
|
||||
<m.svg
|
||||
width="40"
|
||||
height="40"
|
||||
viewBox="0 0 40 40"
|
||||
fill="none"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
className="text-text-secondary"
|
||||
>
|
||||
{/* Mouse/trackpad outline */}
|
||||
<rect
|
||||
x="12"
|
||||
y="8"
|
||||
width="16"
|
||||
height="24"
|
||||
rx="8"
|
||||
stroke="currentColor"
|
||||
strokeWidth="1.5"
|
||||
fill="none"
|
||||
opacity="0.5"
|
||||
/>
|
||||
|
||||
{/* Animated scroll wheel/finger moving up */}
|
||||
<m.rect
|
||||
width="4"
|
||||
height="6"
|
||||
rx="2"
|
||||
fill="currentColor"
|
||||
style={{ x: 18 }}
|
||||
initial={{ y: 20 }}
|
||||
animate={{ y: 14 }}
|
||||
transition={{
|
||||
duration: 1.2,
|
||||
repeat: Infinity,
|
||||
repeatType: "reverse",
|
||||
ease: "easeInOut",
|
||||
}}
|
||||
/>
|
||||
|
||||
{/* Clear upward arrows */}
|
||||
<m.path
|
||||
d="M20 6L16 10L17.5 10L20 7.5L22.5 10L24 10L20 6Z"
|
||||
fill="currentColor"
|
||||
initial={{ opacity: 0.3, y: -3 }}
|
||||
animate={{ opacity: 1, y: -6 }}
|
||||
transition={{
|
||||
duration: 1.2,
|
||||
repeat: Infinity,
|
||||
repeatType: "reverse",
|
||||
ease: "easeInOut",
|
||||
}}
|
||||
/>
|
||||
|
||||
{/* Second arrow for emphasis */}
|
||||
<m.path
|
||||
d="M20 2L16 6L17.5 6L20 3.5L22.5 6L24 6L20 2Z"
|
||||
fill="currentColor"
|
||||
initial={{ opacity: 0.2, y: 0 }}
|
||||
animate={{ opacity: 0.8, y: -3 }}
|
||||
transition={{
|
||||
duration: 1.2,
|
||||
repeat: Infinity,
|
||||
repeatType: "reverse",
|
||||
ease: "easeInOut",
|
||||
delay: 0.2,
|
||||
}}
|
||||
/>
|
||||
</m.svg>
|
||||
)
|
||||
|
||||
interface ScrollToExitTutorialProps {
|
||||
/** Whether to show the tutorial */
|
||||
show: boolean
|
||||
/** Optional callback when tutorial is dismissed */
|
||||
onDismiss?: () => void
|
||||
}
|
||||
|
||||
export const ScrollToExitTutorial = ({ show, onDismiss }: ScrollToExitTutorialProps) => {
|
||||
const { t } = useTranslation()
|
||||
const hasSeenTutorial = useScrollToExitTutorialSeen()
|
||||
const isVisible = show && !hasSeenTutorial
|
||||
|
||||
const handleDismiss = useCallback(() => {
|
||||
setScrollToExitTutorialSeen(true)
|
||||
onDismiss?.()
|
||||
}, [onDismiss])
|
||||
|
||||
// Handle Escape key to dismiss
|
||||
useEffect(() => {
|
||||
if (!isVisible) return
|
||||
|
||||
const handleKeyDown = (e: KeyboardEvent) => {
|
||||
if (e.key === "Escape") {
|
||||
handleDismiss()
|
||||
}
|
||||
}
|
||||
|
||||
document.addEventListener("keydown", handleKeyDown)
|
||||
|
||||
return () => {
|
||||
document.removeEventListener("keydown", handleKeyDown)
|
||||
}
|
||||
}, [isVisible, handleDismiss])
|
||||
|
||||
return (
|
||||
<AnimatePresence>
|
||||
{isVisible && (
|
||||
<m.div
|
||||
initial={{ opacity: 0, y: -10, scale: 0.9 }}
|
||||
animate={{ opacity: 1, y: 0, scale: 1 }}
|
||||
exit={{ opacity: 0, y: -10, scale: 0.9 }}
|
||||
transition={Spring.presets.snappy}
|
||||
className="center absolute top-12 z-[102] w-full"
|
||||
onClick={handleDismiss}
|
||||
>
|
||||
<div className="w-fit">
|
||||
<div className="bg-background border-fill-secondary relative cursor-pointer rounded-xl border px-6 py-4 shadow-lg backdrop-blur-md transition-transform hover:scale-105">
|
||||
<div className="flex items-center gap-4">
|
||||
<ScrollGestureIcon />
|
||||
<div className="flex flex-col gap-1.5">
|
||||
<div className="text-text text-base">
|
||||
{t("tutorial.scroll_to_exit.title")}
|
||||
<div className="text-text-secondary text-sm">
|
||||
{t("tutorial.scroll_to_exit.description")}
|
||||
</div>
|
||||
<div className="text-text-tertiary mt-1 text-xs">
|
||||
{t("tutorial.scroll_to_exit.dismiss_hint")}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</m.div>
|
||||
)}
|
||||
</AnimatePresence>
|
||||
)
|
||||
}
|
||||
@@ -84,16 +84,6 @@ export default extendConfig({
|
||||
backgroundPosition: "-200% 0",
|
||||
},
|
||||
},
|
||||
"smooth-bounce": {
|
||||
"50%": {
|
||||
transform: "translateY(25%)",
|
||||
"animation-timing-function": "cubic-bezier(0.8, 0, 1, 1)",
|
||||
},
|
||||
"0%, 100%": {
|
||||
transform: "none",
|
||||
"animation-timing-function": "cubic-bezier(0, 0, 0.2, 1)",
|
||||
},
|
||||
},
|
||||
},
|
||||
animation: {
|
||||
"caret-blink": "caret-blink 1.25s ease-out infinite",
|
||||
@@ -102,7 +92,6 @@ export default extendConfig({
|
||||
"gradient-x": "gradient-x 3s linear infinite",
|
||||
glow: "glow 1.5s ease-in-out infinite",
|
||||
shimmer: "shimmer 2s linear infinite",
|
||||
"smooth-bounce": "smooth-bounce 1s infinite",
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
@@ -440,6 +440,9 @@
|
||||
"trending.feed": "Trending Feeds",
|
||||
"trending.list": "Trending Lists",
|
||||
"trending.user": "Trending Users",
|
||||
"tutorial.scroll_to_exit.description": "Scroll up when at the top to quickly return to timeline",
|
||||
"tutorial.scroll_to_exit.dismiss_hint": "Click to dismiss",
|
||||
"tutorial.scroll_to_exit.title": "Scroll up to return",
|
||||
"user_button.account": "Account",
|
||||
"user_button.achievement": "Achievements",
|
||||
"user_button.actions": "Actions",
|
||||
|
||||
@@ -438,6 +438,9 @@
|
||||
"trending.feed": "人気フィード",
|
||||
"trending.list": "人気リスト",
|
||||
"trending.user": "人気ユーザー",
|
||||
"tutorial.scroll_to_exit.description": "上部にいるときはスクロールアップしてタイムラインに素早く戻る",
|
||||
"tutorial.scroll_to_exit.dismiss_hint": "クリックして閉じる",
|
||||
"tutorial.scroll_to_exit.title": "上にスクロールして戻る",
|
||||
"user_button.account": "アカウント",
|
||||
"user_button.achievement": "実績",
|
||||
"user_button.actions": "アクション",
|
||||
|
||||
@@ -440,6 +440,9 @@
|
||||
"trending.feed": "热门订阅源",
|
||||
"trending.list": "热门列表",
|
||||
"trending.user": "热门用户",
|
||||
"tutorial.scroll_to_exit.description": "当在顶部时,向上滚动即可快速返回时间线",
|
||||
"tutorial.scroll_to_exit.dismiss_hint": "点击关闭",
|
||||
"tutorial.scroll_to_exit.title": "向上滚动返回",
|
||||
"user_button.account": "账号",
|
||||
"user_button.achievement": "成就",
|
||||
"user_button.actions": "自动化",
|
||||
|
||||
Reference in New Issue
Block a user