Share-link sets save into the class; flashcards up to 75
All checks were successful
Verify and publish V2 container / build-and-push (push) Successful in 28s
All checks were successful
Verify and publish V2 container / build-and-push (push) Successful in 28s
- Sets visitors generate show in the owner's Drafts while being written, then save into the class (and exam, for an exam link) automatically, as if approved. If the save fails, the draft waits in Drafts for review. - Deleting a share link keeps what was made on it; running jobs finish and save. - Visitor flashcard sets go up to 75 cards (default 30); quizzes stay at 50. - The visitor page links finished sets to the class items; the separate AI-set view is gone. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
e945f589ce
commit
76112cb4ae
8 changed files with 146 additions and 103 deletions
|
|
@ -1,7 +1,9 @@
|
|||
/**
|
||||
* Generating on a share link: visitors of a shared class or exam make their own NCLEX-style
|
||||
* quiz or flashcard set from its class materials, with only the choices that matter (how many,
|
||||
* how hard, which materials, med math). The owner's link allows a few sets a day.
|
||||
* how hard, which materials, med math). Finished sets are added to the class, so they appear
|
||||
* with the rest of the link; this section shows the ones being written and the latest ones.
|
||||
* The owner's link allows a few sets a day.
|
||||
*/
|
||||
import { useQuery, useQueryClient } from '@tanstack/react-query';
|
||||
import { BookOpen, ChevronRight, CircleAlert, FileText, Layers, Sparkles } from 'lucide-react';
|
||||
|
|
@ -25,10 +27,17 @@ export function SharedGenerate({ token, data }: { token: string; data: PublicCol
|
|||
});
|
||||
const [open, setOpen] = useState(false);
|
||||
const info = q.data;
|
||||
// A set that just finished is now part of the class: reload the link's materials.
|
||||
const readyKey = (info?.sets ?? []).filter((s) => s.status === 'ready').map((s) => s.id).join(',');
|
||||
useEffect(() => {
|
||||
if (readyKey) void qc.invalidateQueries({ queryKey: ['public', token, '', ''] });
|
||||
}, [readyKey, qc, token]);
|
||||
if (!info) return null;
|
||||
const left = (k: Kind) => Math.max(0, info.usage[k].limit - info.usage[k].used);
|
||||
const quizzes = info.sets.filter((s) => s.kind === 'quiz');
|
||||
const decks = info.sets.filter((s) => s.kind === 'deck');
|
||||
// Being written, failed, or made in the last day (older ones are simply part of the class).
|
||||
const recent = info.sets.filter((s) => s.status !== 'ready' || Date.now() - s.createdAt < 86_400_000);
|
||||
const quizzes = recent.filter((s) => s.kind === 'quiz');
|
||||
const decks = recent.filter((s) => s.kind === 'deck');
|
||||
|
||||
return (
|
||||
<section className="mt-7" aria-label="Practice made with AI">
|
||||
|
|
@ -43,7 +52,7 @@ export function SharedGenerate({ token, data }: { token: string; data: PublicCol
|
|||
Generate
|
||||
</Button>
|
||||
</div>
|
||||
{info.sets.length > 0 && (
|
||||
{recent.length > 0 && (
|
||||
<div className="card overflow-hidden">
|
||||
{[
|
||||
['quiz', 'Quizzes', quizzes] as const,
|
||||
|
|
@ -54,7 +63,7 @@ export function SharedGenerate({ token, data }: { token: string; data: PublicCol
|
|||
<section key={kind} aria-label={`AI-made ${heading.toLowerCase()}`}>
|
||||
<h3 className={cx('eyebrow flex items-center gap-2 border-b border-line bg-sunken/60 px-4 py-2 [&>svg]:size-3.5', n > 0 && 'border-t')}>
|
||||
{kind === 'quiz' ? <BookOpen /> : <Layers />}
|
||||
{heading} made with AI
|
||||
{heading} you made recently
|
||||
<span className="num font-normal">{list.length}</span>
|
||||
</h3>
|
||||
<ul className="divide-y divide-line">
|
||||
|
|
@ -64,13 +73,13 @@ export function SharedGenerate({ token, data }: { token: string; data: PublicCol
|
|||
{s.status === 'failed' ? <CircleAlert /> : s.status === 'generating' ? <Sparkles className="animate-pulse" /> : kind === 'quiz' ? <BookOpen /> : <Layers />}
|
||||
</span>
|
||||
);
|
||||
if (s.status !== 'ready') {
|
||||
if (s.status !== 'ready' || !s.itemId) {
|
||||
return (
|
||||
<li key={s.id} className="flex items-center gap-3 px-4 py-3.5">
|
||||
{icon}
|
||||
<span className="min-w-0 flex-1">
|
||||
<span className="block truncate text-[15px] font-medium">{s.title}</span>
|
||||
<span className={cx('text-xs', s.status === 'failed' ? 'text-bad' : 'text-ink-3')}>{s.status === 'failed' ? s.error : s.progressLabel || 'Starting…'}</span>
|
||||
<span className={cx('text-xs', s.status === 'failed' ? 'text-bad' : 'text-ink-3')}>{s.status === 'generating' ? s.progressLabel || 'Starting…' : s.error}</span>
|
||||
{s.status === 'generating' && <ProgressBar value={Math.max(0.04, s.progress)} className="mt-1.5 h-1" label={`Making ${s.title}`} />}
|
||||
</span>
|
||||
</li>
|
||||
|
|
@ -78,7 +87,7 @@ export function SharedGenerate({ token, data }: { token: string; data: PublicCol
|
|||
}
|
||||
return (
|
||||
<li key={s.id}>
|
||||
<Link to={`/s/${token}/ai/${s.id}`} className="flex items-center gap-3 px-4 py-3.5 hover:bg-ink/4">
|
||||
<Link to={`/s/${token}/${kind}/${s.itemId}`} className="flex items-center gap-3 px-4 py-3.5 hover:bg-ink/4">
|
||||
{icon}
|
||||
<span className="min-w-0 flex-1">
|
||||
<span className="block truncate text-[15px] font-medium">{s.title}</span>
|
||||
|
|
@ -167,7 +176,7 @@ function GenerateDialog({
|
|||
open={open}
|
||||
onOpenChange={(o) => !o && onClose()}
|
||||
title="Make your own practice"
|
||||
description="Written by AI from this link's class materials. It takes a minute or two; you can keep studying meanwhile."
|
||||
description="Written by AI from this link's class materials and added to the class when done. It takes a minute or two; you can keep studying meanwhile."
|
||||
footer={
|
||||
<>
|
||||
<Button variant="ghost" onClick={onClose}>
|
||||
|
|
|
|||
|
|
@ -393,7 +393,7 @@ export function ShareDialog({ target, onClose }: { target: { kind: ShareKind; id
|
|||
return res;
|
||||
})}
|
||||
label="Generate quizzes and flashcards"
|
||||
description={`Visitors can make NCLEX-style quizzes (up to 50 questions, 25% select-all, optional med math) and flashcards from the class materials. Up to ${generated?.usage.quiz.limit ?? 4} quizzes and ${generated?.usage.deck.limit ?? 2} flashcard sets a day on this link.`}
|
||||
description={`Visitors can make NCLEX-style quizzes (up to 50 questions, 25% select-all, optional med math) and flashcard sets (up to 75 cards) from the class materials. They are added to this ${target.kind === 'folder' ? 'exam' : 'class'} as if you made them. Up to ${generated?.usage.quiz.limit ?? 4} quizzes and ${generated?.usage.deck.limit ?? 2} flashcard sets a day on this link.`}
|
||||
/>
|
||||
{share.ai?.generate && generated && (
|
||||
<div className="space-y-2 rounded-lg bg-sunken/60 p-3 text-[13px]">
|
||||
|
|
@ -422,15 +422,19 @@ export function ShareDialog({ target, onClose }: { target: { kind: ShareKind; id
|
|||
{generated.sets.slice(0, 8).map((s) => (
|
||||
<li key={s.id} className="flex items-center gap-2">
|
||||
{s.kind === 'quiz' ? <BookOpen className="size-3.5 shrink-0 text-ink-3" /> : <Layers className="size-3.5 shrink-0 text-ink-3" />}
|
||||
<Link to={`/drafts/${s.id}`} onClick={onClose} className="min-w-0 flex-1 truncate font-medium text-ink-2 hover:text-ink hover:underline">
|
||||
<Link
|
||||
to={s.status === 'ready' && s.itemId ? `/${s.kind === 'quiz' ? 'quizzes' : 'decks'}/${s.itemId}` : `/drafts/${s.id}`}
|
||||
onClick={onClose}
|
||||
className="min-w-0 flex-1 truncate font-medium text-ink-2 hover:text-ink hover:underline"
|
||||
>
|
||||
{s.title}
|
||||
</Link>
|
||||
<span className="shrink-0 text-xs text-ink-3">{s.status === 'generating' ? 'Writing…' : plural(s.count, s.kind === 'quiz' ? 'question' : 'card')}</span>
|
||||
<span className="shrink-0 text-xs text-ink-3">{s.status === 'generating' ? 'Writing…' : s.status === 'review' ? 'In Drafts' : plural(s.count, s.kind === 'quiz' ? 'question' : 'card')}</span>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
{generated.sets.length > 0 && <p className="text-xs text-ink-3">Made by visitors. Open one to review it, save it to your library or discard it from the link.</p>}
|
||||
{generated.sets.length > 0 && <p className="text-xs text-ink-3">Made by visitors and added to your library; they stay if you delete the link.</p>}
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
|
|
|
|||
|
|
@ -92,12 +92,14 @@ export interface ShareGenerateUsage {
|
|||
deck: { used: number; limit: number };
|
||||
}
|
||||
|
||||
/** A quiz or flashcard set a visitor generated on a share link. */
|
||||
/** A quiz or flashcard set a visitor generated on a share link (saved into the class when done). */
|
||||
export interface SharedSet {
|
||||
id: string;
|
||||
kind: 'quiz' | 'deck';
|
||||
title: string;
|
||||
status: 'generating' | 'ready' | 'failed';
|
||||
/** ready: saved into the class as `itemId`. review: waiting in the owner's drafts. */
|
||||
status: 'generating' | 'ready' | 'review' | 'failed';
|
||||
itemId: string | null;
|
||||
progress: number;
|
||||
progressLabel: string;
|
||||
error: string;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue