added a modifier to ffwd/rewind (ctrl) to take bigger steps. made progress bar clickable. added duration to modules

This commit is contained in:
2020-10-02 22:20:42 +02:00
parent ef1fecbce4
commit 373065dc43
4 changed files with 44 additions and 24 deletions

View File

@@ -33,6 +33,13 @@
} }
} }
const onRepositionInModule = event => {
const { percentage } = event.detail
const pos = $currentModule.start + ($currentModule.duration * percentage / 100)
console.log(pos)
jumpTo(pos)
}
onMount(() => positionUpdater()) onMount(() => positionUpdater())
const toggle = video => { const toggle = video => {
@@ -43,12 +50,18 @@
} }
} }
const jumpTo = pos => {
clearInterval(interval)
video.jumpTo(pos)
positionUpdater()
}
const handleKeyDown = e => { const handleKeyDown = e => {
const { key, code, ctrlKey } = e const { key, code, ctrlKey, shiftKey, altKey, metaKey } = e
if (e.shiftKey || e.altKey || e.metaKey) {
return if (shiftKey || altKey || metaKey) return
}
let amount = 5 const amount = ctrlKey ? 30 : 5
if (["j", "ArrowDown"].includes(key)) { if (["j", "ArrowDown"].includes(key)) {
e.preventDefault() e.preventDefault()
nextModule() nextModule()
@@ -60,20 +73,10 @@
toggle(video) toggle(video)
} else if (["l", "ArrowRight"].includes(key)) { } else if (["l", "ArrowRight"].includes(key)) {
e.preventDefault() e.preventDefault()
clearInterval(interval) jumpTo($position + amount)
if (ctrlKey) {
amount = 30
}
video.jumpTo($position + amount)
positionUpdater()
} else if (["h", "ArrowLeft"].includes(key)) { } else if (["h", "ArrowLeft"].includes(key)) {
e.preventDefault() e.preventDefault()
clearInterval(interval) jumpTo($position - amount)
if (ctrlKey) {
amount = 30
}
video.jumpTo($position - amount)
positionUpdater()
} }
} }
@@ -104,7 +107,7 @@
<main> <main>
<Youtube bind:this={video} videoId={DATA.uid} /> <Youtube bind:this={video} videoId={DATA.uid} />
<Modules on:selectModule={onSelectModule} modules={DATA.modules} /> <Modules on:repositionInModule={onRepositionInModule} on:selectModule={onSelectModule} modules={DATA.modules} />
</main> </main>
<style> <style>

View File

@@ -5,8 +5,8 @@
const dispatch = createEventDispatcher() const dispatch = createEventDispatcher()
export let module export let module
const duration = module.end - module.start let progressBar
const getProgress = pos => (pos - module.start) / duration * 100 const getProgress = pos => (pos - module.start) / module.duration * 100
let selected; let progress; let klass; let selected; let progress; let klass;
@@ -18,12 +18,28 @@
progress = null; progress = null;
klass = "" klass = ""
} }
const progressClick = e => {
// https://stackoverflow.com/a/28311723/4386191
const max = 160
const pos = e.pageX - progressBar.offsetLeft
let dual = Math.round(pos / max * 100)
if (dual > 100) {
console.log(dual)
dual = 100;
}
dispatch("repositionInModule", {percentage: dual})
}
</script> </script>
<div on:click={() => dispatch("selectModule", { module })} > <div on:click={() => dispatch("selectModule", { module })} >
<span class="{klass}">I want to {module.outcome}.</span> <span class="{klass}">I want to {module.outcome}.</span>
{#if progress} {#if progress}
<progress value={progress} max=100>Hi</progress> <progress bind:this={progressBar} on:click={progressClick} value={progress} max=100>Hi</progress>
{/if} {/if}
</div> </div>

View File

@@ -5,7 +5,7 @@
<span style="float: left"> <span style="float: left">
{#each modules as module} {#each modules as module}
<Module on:selectModule {module} /> <Module on:repositionInModule on:selectModule {module} />
{/each} {/each}
</span> </span>

View File

@@ -1,4 +1,5 @@
const add_indices = objects => objects.map((object, index) => ({...{index}, ...object})) const add_indices = objects => objects.map((object, index) => ({...{index}, ...object}))
const add_durations = objects => objects.map(object => ({...{duration: object.end - object.start}, ...object}))
const _modules = [ const _modules = [
{ {
@@ -58,7 +59,7 @@ const _modules = [
{ {
name: 'create a kedro project', name: 'create a kedro project',
start: 1038, start: 1038,
end: 1175, end: 2932,
outcome: 'create a new kedro project', outcome: 'create a new kedro project',
}, },
] ]
@@ -72,5 +73,5 @@ export default {
outcomes: [ outcomes: [
'I know how to use Kedro in a basic way.', 'I know how to use Kedro in a basic way.',
], ],
modules: add_indices(_modules) modules: add_durations(add_indices(_modules))
}; };