diff --git a/src/app/(frontend)/styles.css b/src/app/(frontend)/styles.css index 0f62d2a3..a5233313 100644 --- a/src/app/(frontend)/styles.css +++ b/src/app/(frontend)/styles.css @@ -312,21 +312,27 @@ } } -/* Journal "this will earn XP" hint: the sparkles pop in, then the copy wipes in - from the left half a beat later. The motion is skipped when the user asks for - reduced motion; the hint itself still shows, just without animating. */ -@keyframes journal-xp-icon-in { - from { +/* "This will earn XP" hint: the sparkles pop in, the copy wipes in from the + left half a beat later, and a gold glint sweeps from the sparkles across the + text. The motion is skipped when the user asks for reduced motion; the hint + itself still shows, just without animating. Reused wherever a surface grants + contribution XP (see components/frontend/contributions/XpHint.tsx). */ +@keyframes xp-hint-icon-in { + 0% { opacity: 0; - transform: scale(0.7); + transform: scale(0.4); } - to { + 60% { + opacity: 1; + transform: scale(1.15); + } + 100% { opacity: 1; transform: scale(1); } } -@keyframes journal-xp-text-in { +@keyframes xp-hint-text-in { from { opacity: 0; clip-path: inset(0 100% 0 0); @@ -340,21 +346,56 @@ } } -.journal-xp-hint-icon { - animation: journal-xp-icon-in 0.35s ease-out both; +@keyframes xp-hint-glint { + 0% { + opacity: 0; + transform: translateX(-100%); + } + 15% { + opacity: 1; + } + 85% { + opacity: 1; + } + 100% { + opacity: 0; + transform: translateX(100%); + } } -.journal-xp-hint-text { - animation: journal-xp-text-in 0.45s ease-out 0.5s both; +.xp-hint-icon { + animation: xp-hint-icon-in 0.4s ease-out both; +} + +.xp-hint-text { + animation: xp-hint-text-in 0.45s ease-out 0.5s both; +} + +.xp-hint-glint { + position: absolute; + inset: 0; + z-index: 10; + pointer-events: none; + background: linear-gradient( + 90deg, + transparent 40%, + rgb(253 224 71 / 0.95) 50%, + transparent 60% + ); + animation: xp-hint-glint 1s ease-in-out 0.3s both; } @media (prefers-reduced-motion: reduce) { - .journal-xp-hint-icon, - .journal-xp-hint-text { + .xp-hint-icon, + .xp-hint-text { animation: none; opacity: 1; clip-path: none; } + + .xp-hint-glint { + display: none; + } } .locker-search-highlight { diff --git a/src/components/frontend/contributions/XpHint.tsx b/src/components/frontend/contributions/XpHint.tsx new file mode 100644 index 00000000..4d9a4e88 --- /dev/null +++ b/src/components/frontend/contributions/XpHint.tsx @@ -0,0 +1,36 @@ +"use client"; + +import { SparklesIcon } from "lucide-react"; + +import { cn } from "@/lib/utils"; + +interface XpHintProps { + /** XP the action will grant. */ + points: number; + /** Optional trailing context, e.g. "from this journal entry". */ + context?: string; + className?: string; +} + +/** + * Small gold "you'll earn N XP" hint. The sparkles pop in, the copy wipes in + * from the left half a beat later, and a gold glint sweeps across. Callers + * render it once their content qualifies; the animation is skipped under + * `prefers-reduced-motion` (the hint still shows). + */ +export function XpHint({ points, context, className }: XpHintProps) { + return ( +

+ + + + {`Nice - you'll earn ${points} XP${context ? ` ${context}` : ""}!`} + +

+ ); +} diff --git a/src/components/frontend/journals/JournalFormDialog.tsx b/src/components/frontend/journals/JournalFormDialog.tsx index 9799b33f..ce35a6f5 100644 --- a/src/components/frontend/journals/JournalFormDialog.tsx +++ b/src/components/frontend/journals/JournalFormDialog.tsx @@ -3,7 +3,7 @@ import * as React from "react"; import { useRouter } from "next/navigation"; import { toast } from "sonner"; -import { Loader2Icon, SparklesIcon } from "lucide-react"; +import { Loader2Icon } from "lucide-react"; import { Button } from "@/components/ui/button"; import { @@ -28,6 +28,7 @@ import { type LexicalJson, } from "@/components/frontend/intelligence/LexicalRichTextEditor"; import { createJournal, updateJournal } from "@/app/(frontend)/journals/actions"; +import { XpHint } from "@/components/frontend/contributions/XpHint"; import { journalBodyLength } from "@/lib/journals/excerpt"; import { JOURNAL_XP_MIN_CHARS, JOURNAL_XP_POINTS } from "@/lib/journals/xp"; @@ -251,12 +252,7 @@ export function JournalFormDialog({ placeholder="Write your entry here..." /> {bodyLength >= JOURNAL_XP_MIN_CHARS && ( -

- - - {`Nice - you'll earn ${JOURNAL_XP_POINTS} XP from this journal entry!`} - -

+ )}