-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(prompts): video prompt with dedicated settings (V4-1375)
- Loading branch information
1 parent
6b345a1
commit 0fbbfab
Showing
19 changed files
with
341 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
<template> | ||
<v-tabs-window-item key="options" value="options"> | ||
<v-row class="mb-3"> | ||
<v-col cols="12" md="6"> | ||
<v-text-field | ||
class="mb-4" | ||
hide-details="auto" | ||
:label="$t('survey-schemes.prompts.video-prompt.videoId')" | ||
:model-value="videoId" | ||
variant="outlined" | ||
@update:model-value="update('videoId', $event)" | ||
/> | ||
<v-text-field | ||
class="mb-4" | ||
hide-details="auto" | ||
:label="$t('survey-schemes.prompts.video-prompt.height')" | ||
:model-value="height" | ||
variant="outlined" | ||
@update:model-value="updateInteger('height', $event)" | ||
/> | ||
<v-text-field | ||
hide-details="auto" | ||
:label="$t('survey-schemes.prompts.video-prompt.width')" | ||
:model-value="width" | ||
variant="outlined" | ||
@update:model-value="updateInteger('width', $event)" | ||
/> | ||
</v-col> | ||
<v-col cols="12" md="6"> | ||
<v-switch | ||
hide-details="auto" | ||
:label="$t('survey-schemes.prompts.video-prompt.autoplay')" | ||
:model-value="autoplay" | ||
@update:model-value="update('autoplay', $event)" | ||
/> | ||
<v-switch | ||
hide-details="auto" | ||
:label="$t('survey-schemes.prompts.video-prompt.required')" | ||
:model-value="required" | ||
@update:model-value="update('required', $event)" | ||
/> | ||
</v-col> | ||
</v-row> | ||
</v-tabs-window-item> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import { defineComponent, type PropType } from 'vue'; | ||
import type { Prompts } from '@intake24/common/prompts'; | ||
import { basePrompt } from '../partials'; | ||
export default defineComponent({ | ||
name: 'VideoPrompt', | ||
mixins: [basePrompt], | ||
props: { | ||
videoId: { | ||
type: String as PropType<Prompts['video-prompt']['videoId']>, | ||
required: true, | ||
}, | ||
autoplay: { | ||
type: Boolean as PropType<Prompts['video-prompt']['autoplay']>, | ||
required: true, | ||
}, | ||
required: { | ||
type: Boolean as PropType<Prompts['video-prompt']['required']>, | ||
required: true, | ||
}, | ||
height: { | ||
type: Number as PropType<Prompts['video-prompt']['height']>, | ||
required: true, | ||
}, | ||
width: { | ||
type: Number as PropType<Prompts['video-prompt']['width']>, | ||
required: true, | ||
}, | ||
}, | ||
}); | ||
</script> | ||
|
||
<style lang="scss" scoped></style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
apps/survey/src/components/prompts/custom/video-prompt.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
<template> | ||
<component | ||
:is="customPromptLayout" | ||
v-bind="{ food, meal, prompt, section, isValid }" | ||
@action="updateAndAction" | ||
> | ||
<template #actions> | ||
<next :disabled="!isValid" @click="updateAndAction('next')" /> | ||
</template> | ||
<template #nav-actions> | ||
<next-mobile :disabled="!isValid" @click="updateAndAction('next')" /> | ||
</template> | ||
<div class="pa-4"> | ||
<div class="iframe-container"> | ||
<div ref="youtube" /> | ||
</div> | ||
</div> | ||
</component> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import { usePlayer } from '@vue-youtube/core'; | ||
import { computed, defineComponent, ref } from 'vue'; | ||
import { usePromptUtils } from '@intake24/survey/composables'; | ||
import createBasePrompt from '../createBasePrompt'; | ||
const playerStates = { | ||
'YT.PlayerState.UNSTARTED': -1, | ||
'YT.PlayerState.ENDED': 0, | ||
'YT.PlayerState.PLAYING': 1, | ||
'YT.PlayerState.PAUSED': 2, | ||
'YT.PlayerState.BUFFERING': 3, | ||
'YT.PlayerState.CUED': 5, | ||
} as const; | ||
export default defineComponent({ | ||
name: 'VideoPrompt', | ||
mixins: [createBasePrompt<'video-prompt'>()], | ||
props: { | ||
modelValue: { | ||
type: String, | ||
default: 'next', | ||
}, | ||
}, | ||
emits: ['action', 'update:modelValue'], | ||
setup(props, ctx) { | ||
const { action, customPromptLayout } = usePromptUtils(props, ctx); | ||
const youtube = ref(); | ||
const watched = ref(false); | ||
const { onStateChange } = usePlayer(props.prompt.videoId, youtube, { | ||
// cookie: false, | ||
playerVars: { | ||
autoplay: props.prompt.autoplay ? 1 : 0, | ||
controls: props.prompt.required ? 0 : 1, | ||
disablekb: props.prompt.required ? 1 : 0, | ||
origin: window.location.origin, | ||
rel: 0, | ||
}, | ||
height: props.prompt.height, | ||
width: props.prompt.width, | ||
}); | ||
onStateChange((event) => { | ||
const { data } = event; | ||
switch (data) { | ||
case playerStates['YT.PlayerState.ENDED']: | ||
watched.value = true; | ||
break; | ||
default: | ||
break; | ||
} | ||
}); | ||
const isValid = computed(() => !props.prompt.required || watched.value); | ||
const state = computed({ | ||
get() { | ||
return props.modelValue; | ||
}, | ||
set(value) { | ||
ctx.emit('update:modelValue', value); | ||
}, | ||
}); | ||
const updateAndAction = (type: string, ...args: [id?: string, params?: object]) => { | ||
state.value = type; | ||
action(type, ...args); | ||
}; | ||
return { | ||
customPromptLayout, | ||
isValid, | ||
state, | ||
updateAndAction, | ||
youtube, | ||
}; | ||
}, | ||
}); | ||
</script> | ||
|
||
<style lang="scss" scoped></style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.