You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This document explains how to automatically load a set of questions into the application when it starts up. This is useful for populating the quiz with initial data without manual entry.
4
+
5
+
## How It Works
6
+
7
+
1.**Create the File**: In the `data/` directory, create a file named `predefined-questions.json`.
8
+
9
+
2.**File Format**: The file must contain a JSON array of question objects. Each object must have a `question_text` (string) and `answer_options` (an array of objects, each with a `text` property).
10
+
11
+
**Example `data/predefined-questions.json`:**
12
+
```json
13
+
[
14
+
{
15
+
"question_text": "What is your favorite color?",
16
+
"answer_options": [
17
+
{ "text": "Red" },
18
+
{ "text": "Green", "emoji": "💚" },
19
+
{ "text": "Blue" }
20
+
]
21
+
},
22
+
{
23
+
"question_text": "Which technology do you prefer?",
24
+
"answer_options": [
25
+
{ "text": "Frontend" },
26
+
{ "text": "Backend" }
27
+
]
28
+
}
29
+
]
30
+
```
31
+
32
+
3. **Processing**:
33
+
- When the application starts, it checks for the existence of `data/predefined-questions.json`.
34
+
- If found, it renames the file to `data/predefined-questions.json.processing` to prevent it from being processed again.
35
+
- It reads the questions from the `.processing` file and adds any questions that do not already exist (based on `question_text`) to the main `data/questions.json` file.
36
+
- After successful processing, the `.processing` file is deleted.
37
+
- If an error occurs (e.g., malformed JSON), the `.processing` file is left in place for manual inspection.
38
+
39
+
This ensures that predefined questions are loaded exactly once in an atomic and safe manner.
0 commit comments