+ {#if typeof question.code === "string"}
+
+
+ handleCode(question.id, false)}
+ >
+
+
+
+ {/if}
+
+
{#each question.options as option}
{#if QUESTION_TYPE.RADIO === question.type}
@@ -101,24 +146,18 @@
{#if QUESTION_TYPE.TEXTAREA !== question.type}
-
-
+
+
-
- Add option
+ Add option
+
{/if}
{/each}
-
-
diff --git a/src/components/Course/components/Lecture/Homework/ViewMode.svelte b/src/components/Course/components/Lecture/Homework/ViewMode.svelte
index 24ca4a74..078f4f25 100644
--- a/src/components/Course/components/Lecture/Homework/ViewMode.svelte
+++ b/src/components/Course/components/Lecture/Homework/ViewMode.svelte
@@ -1,9 +1,14 @@
- Lesson 2 home exercises
- (mode = mode === MODES.edit ? MODES.view : MODES.edit)}
- />
+
+
(mode = mode === MODES.edit ? MODES.view : MODES.edit)}
+ />
+ {#if mode === MODES.edit}
+ (preview = !preview)}
+ />
+ {/if}
+
+
+ {#if mode === MODES.edit}
+
+ {/if}
{#if mode === MODES.edit}
{:else}
-
+
{/if}
diff --git a/src/components/Course/components/Lecture/Homework/store/index.js b/src/components/Course/components/Lecture/Homework/store/index.js
index cdb914bc..2e0922f5 100644
--- a/src/components/Course/components/Lecture/Homework/store/index.js
+++ b/src/components/Course/components/Lecture/Homework/store/index.js
@@ -11,19 +11,23 @@ export const questionnaire = writable({
questions: [
{
id: "react-founder",
- type: QUESTION_TYPE.CHECKBOX,
+ type: QUESTION_TYPE.RADIO,
title: "Who is the creator of React.js",
options: [
{
+ id: 1,
value: "Dan Abrahmov",
},
{
+ id: 2,
value: "Google",
},
{
+ id: 3,
value: "Facebook",
},
{
+ id: 4,
value: "Traversy Media",
},
],
@@ -32,17 +36,26 @@ export const questionnaire = writable({
id: "vue-founder",
type: QUESTION_TYPE.CHECKBOX,
title: "Who is the creator of Vue.js",
+ code: `const name = 'Josh Perez';\nconst element =
Hello, {name}
;\n\nReactDOM.render(\n
+ element,\,
+ document.getElementById('root')
+ )
+ `,
options: [
{
+ id: 1,
value: "Evan Vue",
},
{
+ id: 2,
value: "Mark Zukerberg",
},
{
+ id: 3,
value: "Prince Charles",
},
{
+ id: 4,
value: "Bill Gates",
},
],
@@ -53,34 +66,28 @@ export const questionnaire = writable({
title: "Who is the creator of Svelte.js",
options: [
{
+ id: 1,
value: "Hillary Svelte",
},
{
+ id: 2,
value: "Mircosoft",
},
{
+ id: 3,
value: "Elevate",
},
{
+ id: 4,
value: "Coding Train",
},
],
},
{
id: "angular-founder",
- type: QUESTION_TYPE.CHECKBOX,
+ type: QUESTION_TYPE.TEXTAREA,
title: "Who is the creator of Angular.js",
- options: [
- {
- value: "Laryy page",
- },
- {
- value: "Google",
- },
- {
- value: "Sales Force",
- },
- ],
+ value: "",
},
],
});
@@ -95,6 +102,7 @@ export function handleAddQuestion() {
{
...QUESTION_TEMPLATE,
id: questions.length + 1,
+ value: "",
options: [
{
id: 1,
@@ -120,7 +128,7 @@ export function handleAddOption(questionId) {
options: [
...question.options,
{
- id: question.options.length + 1,
+ id: question.options[question.options.length - 1].id + 1,
value: "",
},
],
@@ -143,6 +151,11 @@ export function handleRemoveOption(questionId, optionId) {
...q,
questions: questions.map((question) => {
if (question.id === questionId) {
+ console.log(
+ "filter",
+ optionId,
+ question.options.filter((option) => option.id !== optionId)
+ );
return {
...question,
options: [
@@ -170,3 +183,23 @@ export function handleRemoveQuestion(questionId) {
});
};
}
+
+export function handleCode(questionId, shouldAdd = true) {
+ questionnaire.update((q) => {
+ const { questions } = q;
+
+ return {
+ ...q,
+ questions: questions.map((question) => {
+ if (question.id === questionId) {
+ return {
+ ...question,
+ code: shouldAdd ? "" : undefined,
+ };
+ }
+
+ return question;
+ }),
+ };
+ });
+}
diff --git a/src/components/Dropdown/index.svelte b/src/components/Dropdown/index.svelte
new file mode 100644
index 00000000..8f93abca
--- /dev/null
+++ b/src/components/Dropdown/index.svelte
@@ -0,0 +1,54 @@
+
+
+
+
+
+ {#if open}
+
+ {#each options as option, index}
+
+ {/each}
+
+ {/if}
+
+
+
diff --git a/src/components/Form/Checkbox.svelte b/src/components/Form/Checkbox.svelte
index 3e94b258..0e61a982 100644
--- a/src/components/Form/Checkbox.svelte
+++ b/src/components/Form/Checkbox.svelte
@@ -6,7 +6,7 @@
export let isEditable = false;
-