quiz seo image and authguard

This commit is contained in:
gosangam
2026-10-15 21:09:37 +05:30
parent 6a6143ceb2
commit 0e2e0d7300
8 changed files with 602 additions and 447 deletions
+6 -2
View File
@@ -5,6 +5,7 @@
*
* Asks the BFF whether this page has a published quiz and renders nothing if
* not, so it can sit on every content page without leaving an empty slot.
* Quizzes are for signed-in readers only, so signed out it never asks.
* Its label tracks progress: Take quiz → Continue quiz → View results.
*/
@@ -24,10 +25,12 @@ export function QuizButton({
className?: string;
}) {
const { user } = useAuth();
const userId = user?.id;
const [card, setCard] = useState<QuizCard | null>(null);
// Re-asked when the user changes, so progress appears right after sign-in.
useEffect(() => {
if (!userId) return;
let cancelled = false;
quiz
.forPath(path)
@@ -40,9 +43,10 @@ export function QuizButton({
return () => {
cancelled = true;
};
}, [path, user?.id]);
}, [path, userId]);
if (!card) return null;
// A card left over from before sign-out is ignored rather than cleared.
if (!card || !user) return null;
const done = card.my.state === "completed";
return (
+7 -3
View File
@@ -6,7 +6,8 @@
* - "tile": a card that leads the search page's "Start here" row.
* - "banner": a full-width row for the homepage, under sādhana / vāṇī.
*
* Renders nothing until there is at least one published quiz; with
* Signed-in readers only, like quizzes themselves. Renders nothing until
* there is at least one published quiz; with
* `pendingOnly` it also hides once every quiz has been finished, so the
* homepage only nudges when there's something left to do.
*/
@@ -28,9 +29,11 @@ export function QuizzesCTA({
className?: string;
}) {
const { user } = useAuth();
const userId = user?.id;
const [cards, setCards] = useState<QuizCard[] | null>(null);
useEffect(() => {
if (!userId) return;
let cancelled = false;
quiz
.list()
@@ -44,9 +47,10 @@ export function QuizzesCTA({
cancelled = true;
};
// Refetch on sign-in/out: progress is per user.
}, [user?.id]);
}, [userId]);
if (!cards?.length) return null;
// Cards left over from before sign-out are ignored rather than cleared.
if (!user || !cards?.length) return null;
if (pendingOnly && cards.every((c) => c.my.state === "completed")) {
return null;