|
1 | 1 | <script lang="ts">
|
2 | 2 | import { onMount } from 'svelte';
|
3 |
| - import MCQ from '$lib/components/forms/interactive/viewers/MCQ.svelte'; |
4 |
| - import Note from '$lib/components/forms/interactive/viewers/Notes.svelte'; |
5 |
| - import ThreeDMaterial from '$lib/components/forms/interactive/viewers/ThreeDMaterial.svelte'; |
| 3 | + import { Input, Label, Button, Select } from 'flowbite-svelte'; |
| 4 | + import toast, { Toaster } from 'svelte-french-toast'; |
| 5 | + import { enhance } from '$app/forms'; |
6 | 6 |
|
7 | 7 | export let content: any[] = [];
|
8 | 8 | let currItem: any;
|
9 | 9 | let currIndex = 0;
|
| 10 | + let error: string; |
| 11 | + let selected: any; |
| 12 | + let id: string; |
10 | 13 |
|
11 | 14 | onMount(async () => {
|
12 | 15 | currItem = content[0];
|
|
27 | 30 | }
|
28 | 31 | }
|
29 | 32 |
|
| 33 | + function checkanswer() { |
| 34 | + if (selected == currItem.answer) { |
| 35 | + toast.success('Correct Answer'); |
| 36 | + } else { |
| 37 | + toast.error('Wrong Answer'); |
| 38 | + } |
| 39 | + } |
| 40 | +
|
| 41 | + function save() { |
| 42 | + const toastId = toast.loading('Answering question...'); |
| 43 | + return async ({ result }: any) => { |
| 44 | + if (result.type === 'success') { |
| 45 | + toast.dismiss(toastId); |
| 46 | + toast.success('Answered correctlly'); |
| 47 | + } else { |
| 48 | + error = result.data?.error; |
| 49 | + toast.dismiss(toastId); |
| 50 | + toast.error(error); |
| 51 | + } |
| 52 | + }; |
| 53 | + } |
| 54 | +
|
30 | 55 | $: currItem = content[currIndex];
|
31 | 56 | $: stepsAhead = Math.min(3, content.length - currIndex);
|
| 57 | + $: options = currItem.options; |
32 | 58 | </script>
|
33 | 59 |
|
| 60 | +<Toaster /> |
| 61 | + |
34 | 62 | <div class="space-y-4">
|
35 | 63 | <div class="flex flex-col items-center gap-4 sm:grid sm:grid-cols-12">
|
36 | 64 | <!-- Previous Button -->
|
|
96 | 124 | <div class="flex justify-center">
|
97 | 125 | <div class="w-full px-4 sm:px-0">
|
98 | 126 | {#if currItem.type == 'MCQ'}
|
99 |
| - <MCQ question={currItem} /> |
| 127 | + <main class="container mx-auto p-4 sm:w-[100vw]"> |
| 128 | + <div class="p-2 md:px-5 md:py-2"> |
| 129 | + <form method="POST" action="?/answerMCQ" use:enhance={save}> |
| 130 | + <div class="grid grid-cols-12 gap-6"> |
| 131 | + <div class="col-span-10"> |
| 132 | + <div> |
| 133 | + <p class="m-2 text-center text-3xl"> |
| 134 | + {currItem.question} |
| 135 | + </p> |
| 136 | + <p class="m-2 text-center text-xl text-gray-500"> |
| 137 | + {currItem.description} |
| 138 | + </p> |
| 139 | + <div class="mt-4"> |
| 140 | + {#each options as option, i} |
| 141 | + <p class="mb-2">Option {i + 1}</p> |
| 142 | + <div class="mb-6 grid grid-cols-12 gap-6"> |
| 143 | + <div class="col-span-11"> |
| 144 | + <p |
| 145 | + id="option-{currItem.id}-{i}" |
| 146 | + placeholder={option} |
| 147 | + class="mb-2 w-full" |
| 148 | + > |
| 149 | + {option} |
| 150 | + </p> |
| 151 | + </div> |
| 152 | + </div> |
| 153 | + {/each} |
| 154 | + </div> |
| 155 | + <Label> |
| 156 | + Select an answer: |
| 157 | + <Select class="m-2" bind:value={selected}> |
| 158 | + {#each currItem.options as option} |
| 159 | + <option value={option}>{option}</option> |
| 160 | + {/each} |
| 161 | + </Select> |
| 162 | + </Label> |
| 163 | + <Input type="hidden" id="answer" name="answer" value={selected} /> |
| 164 | + <Input type="hidden" id="id" name="id" value={id} /> |
| 165 | + <Button type="button" on:click={checkanswer} class="mt-4 w-full">Answer</Button> |
| 166 | + </div> |
| 167 | + </div> |
| 168 | + </div> |
| 169 | + </form> |
| 170 | + </div> |
| 171 | + </main> |
100 | 172 | {:else if currItem.type == 'Note'}
|
101 |
| - <Note note={currItem} /> |
| 173 | + <main class="container mx-auto px-2 py-4 sm:px-4 md:px-6 lg:px-8"> |
| 174 | + <div class="mx-auto w-full max-w-4xl"> |
| 175 | + <div class="flex flex-col items-center"> |
| 176 | + <div class="mb-4 w-full"> |
| 177 | + <h2 class="text-center text-xl font-semibold sm:text-2xl md:text-3xl"> |
| 178 | + {currItem.title} |
| 179 | + </h2> |
| 180 | + </div> |
| 181 | + <div class="w-full"> |
| 182 | + <div class="p-2 sm:p-3"> |
| 183 | + <section |
| 184 | + class="flex flex-col space-y-2 rounded-lg bg-gray-200 p-2 shadow-md ring dark:bg-gray-700" |
| 185 | + > |
| 186 | + <div class="w-full flex-1"> |
| 187 | + <iframe |
| 188 | + id="google-pdf-viewer" |
| 189 | + class="h-[50vh] w-full sm:h-[60vh] md:h-[70vh] lg:h-[80vh]" |
| 190 | + src={currItem.content} |
| 191 | + frameborder="0" |
| 192 | + title="Study Material" |
| 193 | + ></iframe> |
| 194 | + </div> |
| 195 | + </section> |
| 196 | + </div> |
| 197 | + </div> |
| 198 | + </div> |
| 199 | + </div> |
| 200 | + </main> |
102 | 201 | {:else if currItem.type == 'ThreeDMaterial'}
|
103 |
| - <ThreeDMaterial material={currItem} /> |
| 202 | + <main class="container mx-auto p-4 sm:w-[100vw]"> |
| 203 | + <div class="p-2 md:px-5 md:py-2"> |
| 204 | + <div class="grid grid-cols-12 justify-center gap-6 text-center"> |
| 205 | + <div class="col-span-10"> |
| 206 | + <div class="mb-6"> |
| 207 | + <h2 class="mb-2 text-2xl"> |
| 208 | + {currItem.title} |
| 209 | + </h2> |
| 210 | + </div> |
| 211 | + <div> |
| 212 | + <div class="flex justify-center p-3"> |
| 213 | + <section |
| 214 | + class="flex h-[100%] w-[100%] flex-col space-y-4 rounded-lg bg-gray-200 p-2 shadow-md ring dark:bg-gray-700" |
| 215 | + > |
| 216 | + <div class="flex-1"> |
| 217 | + <!-- Use it like any other HTML element --> |
| 218 | + <model-viewer |
| 219 | + class="h-[100vh] w-full flex-grow" |
| 220 | + alt={currItem.description} |
| 221 | + src={currItem.link} |
| 222 | + ar |
| 223 | + environment-image="/moon_1k.hdr" |
| 224 | + poster="/poster.svg" |
| 225 | + shadow-intensity="1" |
| 226 | + camera-controls |
| 227 | + touch-action="pan-y" |
| 228 | + > |
| 229 | + </model-viewer> |
| 230 | + </div> |
| 231 | + </section> |
| 232 | + </div> |
| 233 | + </div> |
| 234 | + </div> |
| 235 | + </div> |
| 236 | + </div> |
| 237 | + </main> |
104 | 238 | {/if}
|
105 | 239 | </div>
|
106 | 240 | </div>
|
|
0 commit comments