|
1 | 1 | <script> |
2 | 2 | import { onMount } from "svelte"; |
| 3 | + import SveltePlayer from "svelte-player"; |
| 4 | + import { Card, CardBody } from "@sveltestrap/sveltestrap"; |
| 5 | + import { ElementType } from "$lib/helpers/enums"; |
3 | 6 |
|
4 | 7 | /** @type {boolean} */ |
5 | 8 | export let isMultiSelect = false; |
|
23 | 26 | /** @type {string[]} */ |
24 | 27 | let payloadAnswers = []; |
25 | 28 | /** @type {any[]} */ |
26 | | - let localOptions = []; |
| 29 | + let plainOptions = []; |
| 30 | + /** @type {any[]} */ |
| 31 | + let videoOptions = []; |
27 | 32 |
|
28 | 33 | onMount(() => { |
29 | 34 | reset(); |
30 | | - localOptions = collectOptions(options); |
| 35 | + collectOptions(options); |
31 | 36 | }); |
32 | 37 |
|
33 | 38 | /** @param {any[]} options */ |
34 | 39 | function collectOptions(options) { |
35 | | - const res = options?.filter(op => !!op.title && !!op.payload)?.map(op => { |
| 40 | + const innerOptions = options?.filter(op => !!op.title && !!op.payload) || []; |
| 41 | +
|
| 42 | + videoOptions = innerOptions?.filter(op => op.type == ElementType.Video); |
| 43 | + plainOptions = innerOptions?.filter(op => op.type != ElementType.Video)?.map(op => { |
36 | 44 | return { |
37 | 45 | title: op.title, |
38 | 46 | payload: op.payload, |
| 47 | + is_primary: op.is_primary, |
| 48 | + is_secondary: op.is_secondary, |
39 | 49 | isClicked: false |
40 | 50 | }; |
41 | 51 | }) || []; |
42 | | -
|
43 | | - return res; |
44 | 52 | } |
45 | 53 |
|
46 | 54 | /** |
|
54 | 62 | if (!isMultiSelect) { |
55 | 63 | innerConfirm(option?.title, option?.payload); |
56 | 64 | } else { |
57 | | - localOptions = localOptions.map((op, idx) => { |
| 65 | + plainOptions = plainOptions.map((op, idx) => { |
58 | 66 | if (idx === index) { |
59 | 67 | op.isClicked = !op.isClicked; |
60 | 68 | if (op.isClicked) { |
|
91 | 99 | } |
92 | 100 |
|
93 | 101 | function reset() { |
94 | | - localOptions = []; |
| 102 | + plainOptions = []; |
| 103 | + videoOptions = []; |
95 | 104 | titleAnswers = []; |
96 | 105 | payloadAnswers = []; |
97 | 106 | } |
98 | 107 |
|
99 | 108 | </script> |
100 | 109 |
|
101 | | -{#if localOptions.length > 0} |
| 110 | +{#if videoOptions.length > 0} |
| 111 | +<div> |
| 112 | + <div class="video-group-container"> |
| 113 | + {#each videoOptions as video, index} |
| 114 | + <Card class="video-element-card"> |
| 115 | + <CardBody> |
| 116 | + <div class="video-element-title"> |
| 117 | + {video.title} |
| 118 | + </div> |
| 119 | + <div class="video-element-player"> |
| 120 | + <SveltePlayer url={video.payload} controls /> |
| 121 | + </div> |
| 122 | + </CardBody> |
| 123 | + </Card> |
| 124 | + {/each} |
| 125 | + </div> |
| 126 | +</div> |
| 127 | +{/if} |
| 128 | +
|
| 129 | +{#if plainOptions.length > 0} |
102 | 130 | <div class="button-group-container"> |
103 | | - {#each localOptions as option, index} |
| 131 | + {#each plainOptions as option, index} |
104 | 132 | <button |
105 | | - class="btn btn-outline-primary btn-rounded btn-sm m-1" |
| 133 | + class={`btn btn-rounded btn-sm m-1 ${option.is_secondary ? 'btn-outline-secondary': 'btn-outline-primary'}`} |
106 | 134 | class:active={!!option.isClicked} |
107 | 135 | disabled={disableOption} |
108 | 136 | on:click={(e) => handleClickOption(e, option, index)} |
|
114 | 142 | <button |
115 | 143 | class="btn btn-outline-success btn-rounded btn-sm m-1" |
116 | 144 | name="confirm" |
117 | | - disabled={disableOption || localOptions.every(x => !!!x.isClicked)} |
| 145 | + disabled={disableOption || plainOptions.every(x => !!!x.isClicked)} |
118 | 146 | on:click={(e) => handleConfirm(e)} |
119 | 147 | > |
120 | 148 | {confirmBtnText || 'Continue'} |
|
0 commit comments