Yu Chen commited on
Commit
d78bc1b
·
1 Parent(s): 7bdfdfb

export article together with questions

Browse files
src/app/page.tsx CHANGED
@@ -366,6 +366,7 @@ export default function QuestionBuilder() {
366
  className="h-1/2"
367
  questions={questions}
368
  questionTypes={QUESTION_TYPES}
 
369
  selectedQuestions={selectedQuestions}
370
  onQuestionSelect={(questionId, selected) => {
371
  setSelectedQuestions(prev => {
 
366
  className="h-1/2"
367
  questions={questions}
368
  questionTypes={QUESTION_TYPES}
369
+ articleText={sourceArticle}
370
  selectedQuestions={selectedQuestions}
371
  onQuestionSelect={(questionId, selected) => {
372
  setSelectedQuestions(prev => {
src/components/question-output/QuestionList.tsx CHANGED
@@ -13,6 +13,7 @@ import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
13
  export interface QuestionListProps {
14
  questions: GeneratedQuestion[];
15
  questionTypes: QuestionType[];
 
16
  selectedQuestions?: Set<string>;
17
  onQuestionSelect?: (questionId: string, selected: boolean) => void;
18
  onQuestionEdit?: (question: GeneratedQuestion) => void;
@@ -33,6 +34,7 @@ export interface QuestionListProps {
33
  export default function QuestionList({
34
  questions,
35
  questionTypes,
 
36
  selectedQuestions = new Set(),
37
  onQuestionSelect,
38
  onQuestionEdit,
@@ -146,7 +148,7 @@ export default function QuestionList({
146
  }
147
 
148
  if (exportFormat === 'docx') {
149
- await exportQuestionsToDocx(questionsToExport, filename, includeAnswers);
150
  } else {
151
  // For now, just show a message that TXT export is not implemented
152
  alert('TXT export is not yet implemented. Please use DOCX format.');
 
13
  export interface QuestionListProps {
14
  questions: GeneratedQuestion[];
15
  questionTypes: QuestionType[];
16
+ articleText?: string;
17
  selectedQuestions?: Set<string>;
18
  onQuestionSelect?: (questionId: string, selected: boolean) => void;
19
  onQuestionEdit?: (question: GeneratedQuestion) => void;
 
34
  export default function QuestionList({
35
  questions,
36
  questionTypes,
37
+ articleText,
38
  selectedQuestions = new Set(),
39
  onQuestionSelect,
40
  onQuestionEdit,
 
148
  }
149
 
150
  if (exportFormat === 'docx') {
151
+ await exportQuestionsToDocx(questionsToExport, filename, includeAnswers, articleText);
152
  } else {
153
  // For now, just show a message that TXT export is not implemented
154
  alert('TXT export is not yet implemented. Please use DOCX format.');
src/lib/exportUtils.ts CHANGED
@@ -4,7 +4,8 @@ import { GeneratedQuestion } from '@/types/quiz';
4
  export async function exportQuestionsToDocx(
5
  questions: GeneratedQuestion[],
6
  filename: string = 'quiz-questions.docx',
7
- includeAnswers: boolean = true
 
8
  ) {
9
  // Create document
10
  const doc = new Document({
@@ -13,7 +14,7 @@ export async function exportQuestionsToDocx(
13
  children: [
14
  // Title
15
  new Paragraph({
16
- text: 'Quiz Questions',
17
  heading: HeadingLevel.HEADING_1,
18
  alignment: AlignmentType.CENTER,
19
  spacing: {
@@ -38,6 +39,32 @@ export async function exportQuestionsToDocx(
38
  after: 300
39
  }
40
  }),
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41
 
42
  // Questions
43
  ...questions.map((question, index) =>
 
4
  export async function exportQuestionsToDocx(
5
  questions: GeneratedQuestion[],
6
  filename: string = 'quiz-questions.docx',
7
+ includeAnswers: boolean = true,
8
+ article?: string
9
  ) {
10
  // Create document
11
  const doc = new Document({
 
14
  children: [
15
  // Title
16
  new Paragraph({
17
+ text: 'Quiz Export',
18
  heading: HeadingLevel.HEADING_1,
19
  alignment: AlignmentType.CENTER,
20
  spacing: {
 
39
  after: 300
40
  }
41
  }),
42
+
43
+ // Source Article Section (if provided)
44
+ ...(article && article.trim().length > 0
45
+ ? [
46
+ new Paragraph({
47
+ text: 'Source Article',
48
+ heading: HeadingLevel.HEADING_2,
49
+ spacing: { before: 300, after: 200 },
50
+ }),
51
+ ...article.split(/\n{2,}/).flatMap((block) => [
52
+ new Paragraph({
53
+ children: [new TextRun({ text: block.replace(/\n/g, ' '), size: 22 })],
54
+ spacing: { after: 150 },
55
+ }),
56
+ ]),
57
+ new Paragraph({
58
+ children: [new TextRun({ text: '─'.repeat(50), color: 'CCCCCC' })],
59
+ spacing: { before: 200, after: 200 },
60
+ }),
61
+ new Paragraph({
62
+ text: 'Questions',
63
+ heading: HeadingLevel.HEADING_2,
64
+ spacing: { before: 100, after: 200 },
65
+ }),
66
+ ]
67
+ : []),
68
 
69
  // Questions
70
  ...questions.map((question, index) =>