freezmo/components/activities/Flashcard.tsx
Martin Dvorak 7da308fa1e Aero button glass + homework report control; reduced-motion sheet glitch
Buttons: the recipe's thin veils let btn-secondary/btn-ghost/glass-pill
blend into the grass and sky - they now carry a stronger pale-glass veil
(the Ask-pill look) over the blurred scene, ghosts plus a rim and
full-contrast text. Homework make/check results gained the same red "!"
report control as the feeds and the guide (a synthetic short-answer
activity maps into the report flow; pinned in phase3).

Reduced motion: the manual toggle only fed framer's MotionConfig, which
strips transform animations - while components branched on the OS-only
useReducedMotion - so translucent sheets still spring-faded their opacity
in over the page (the "ugly visual glitch with the settings panel"). All
16 components now read useAppReducedMotion() (OS or toggle), and the
settings sheet/scrim and the library's phone sheet go instant. Verified
frame by frame: opacity 1.00 from the first frame.

Contrast 0 findings, axe clean; mobile 126/126, chat 102/102, providers
20/20, wizard 95/95, phase3 31/31, bubbles 34/34, i18n 13/13, native
33/33. Version 0.5.4, SW -> freezmo-v76.
2026-10-14 09:19:54 +00:00

114 lines
4.2 KiB
TypeScript

"use client";
import { motion } from "framer-motion";
import { useAppReducedMotion as useReducedMotion } from "@/lib/motion-pref";
import { useState } from "react";
import { useI18n } from "@/lib/i18n";
import type { Activity } from "@/lib/schemas";
import { Button } from "@/components/ui";
import {
ActivityHeader,
FeedbackPanel,
Hint,
PromptCard,
QuestionText,
type ActivityComponentProps,
} from "./shared";
type FlashcardActivity = Extract<Activity, { type: "flashcard" }>;
export function Flashcard({ activity, onAnswered, onNext, isLast, nextLabel }: ActivityComponentProps<FlashcardActivity>) {
const { t } = useI18n();
const reduceMotion = useReducedMotion();
const [flipped, setFlipped] = useState(false);
const [result, setResult] = useState<boolean | null>(null);
/**
* Which face is painted. The swap happens at the 90° edge-on moment instead
* of relying on backface-visibility: a backdrop-filter layer (the card
* glass) keeps rendering its backface on some GPU/compositing paths, which
* showed the question mirrored over the answer.
*/
const [face, setFace] = useState<"front" | "back">("front");
const showFaceFor = (angle: number) => {
const next = angle > 90 && angle < 270 ? "back" : "front";
setFace((current) => (current === next ? current : next));
};
const settle = (correct: boolean) => {
if (result !== null) return;
setResult(correct);
onAnswered(correct);
};
return (
<>
<ActivityHeader type="flashcard" topic={activity.topic} />
<Hint>{flipped ? t("flashcard.didYouKnow") : t("flashcard.tapToFlip")}</Hint>
<button
type="button"
onClick={() => setFlipped((value) => !value)}
className="group relative block w-full text-left [perspective:1400px]"
aria-label={flipped ? t("flashcard.flipBack") : t("flashcard.reveal")}
>
<motion.div
animate={{ rotateX: flipped ? 180 : 0 }}
transition={reduceMotion ? { duration: 0 } : { type: "spring", stiffness: 220, damping: 24 }}
onUpdate={(latest) => showFaceFor(Number(latest.rotateX ?? 0))}
onAnimationComplete={() => showFaceFor(flipped ? 180 : 0)}
className="relative min-h-56 w-full [transform-style:preserve-3d]"
>
<PromptCard
className="absolute inset-0 flex flex-col justify-center gap-3 group-hover:border-frost-300"
style={{ visibility: face === "front" ? "visible" : "hidden" }}
>
<span className="text-xs font-bold uppercase tracking-widest text-frost-600 dark:text-frost-200">
{t("flashcard.question")}
</span>
<QuestionText>{activity.front}</QuestionText>
<span className="mt-2 text-xs font-semibold text-frost-400 dark:text-frost-400">
{t("flashcard.tapFlip")}
</span>
</PromptCard>
<div className="[transform:rotateX(180deg)]" style={{ visibility: face === "back" ? "visible" : "hidden" }}>
<div className="card flex min-h-56 flex-col justify-center gap-3 px-5 py-6 sm:px-6">
<span className="text-xs font-bold uppercase tracking-widest text-frost-600 dark:text-frost-200">
{t("flashcard.answer")}
</span>
<p className="text-lg font-semibold leading-relaxed text-frost-950 dark:text-frost-50">
{activity.back}
</p>
</div>
</div>
</motion.div>
</button>
{flipped && result === null ? (
<div className="grid grid-cols-2 gap-3">
<Button variant="secondary" size="lg" onClick={() => settle(false)}>
{t("flashcard.notYet")}
</Button>
<Button variant="success" size="lg" onClick={() => settle(true)}>
{t("flashcard.knewIt")}
</Button>
</div>
) : null}
{result !== null ? (
<FeedbackPanel
correct={result}
explanation={activity.explanation}
xp={activity.xp}
isLast={isLast}
nextLabel={nextLabel}
headline={result ? t("flashcard.frozenSolid") : t("flashcard.keepPile")}
onNext={onNext}
/>
) : null}
</>
);
}