Ron Au commited on
Commit
2cfd477
1 Parent(s): d400a31

feat(ui): Scroll notes into view on first time

Browse files
source/ui/src/lib/Notes.svelte CHANGED
@@ -4,6 +4,8 @@ import { fade } from 'svelte/transition';
4
  import { audioBlob, notesImage, style } from './stores';
5
  import { styles } from './config.json';
6
 
 
 
7
  let currentTime: number;
8
  let duration: number;
9
  let paused = true;
@@ -29,6 +31,8 @@ onMount(() => {
29
  currentTime = 0;
30
  });
31
  }
 
 
32
  });
33
 
34
  afterUpdate((): void => {
@@ -57,46 +61,44 @@ const touchMove = (event: TouchEvent): void => {
57
  currentTime = (duration * (event.touches[0].clientX - left)) / (right - left);
58
  };
59
 
60
- const keyDown = (e: KeyboardEvent): void => {
61
- e.preventDefault();
62
 
63
- if (e.code === 'Space') {
64
  paused = !paused;
65
  }
66
- if (e.code === 'ArrowLeft') {
67
  currentTime = currentTime >= 1 ? currentTime - 1 : 0;
68
  }
69
- if (e.code === 'ArrowRight') {
70
  currentTime = currentTime <= duration - 1 ? currentTime + 1 : duration;
71
  }
72
  };
73
  </script>
74
 
75
- {#if $audioBlob}
76
- <section transition:fade>
77
- <img class="notes" src={$notesImage} alt="" bind:this={visualisation} />
78
- <div
79
- bind:this={player}
80
- class="player"
81
- style:width={imageWidth + 'px'}
82
- style:height={imageHeight + 'px'}
83
- on:mousemove={mouseMove}
84
- on:touchmove|preventDefault={touchMove}
85
- on:keydown={keyDown}
86
- on:click={() => (paused = !paused)}
87
- tabindex="0"
88
- >
89
- <audio bind:currentTime bind:duration bind:paused src={$audioBlob} />
90
- <div class="handle" style:transform="translate({imageWidth * (currentTime / duration)}px, -2%)" />
91
- {#if paused}
92
- <img class="play-button" src="static/play.svg" alt="Play button" draggable="false" transition:fade />
93
- {/if}
94
- </div>
95
- <a href={$audioBlob} download={`${styles[$style]} Composition - AI Guru ft. Hugging Face.wav`} class="download"
96
- >Download</a
97
- >
98
- </section>
99
- {/if}
100
 
101
  <style>
102
  section {
 
4
  import { audioBlob, notesImage, style } from './stores';
5
  import { styles } from './config.json';
6
 
7
+ let section: HTMLElement;
8
+
9
  let currentTime: number;
10
  let duration: number;
11
  let paused = true;
 
31
  currentTime = 0;
32
  });
33
  }
34
+
35
+ section.scrollIntoView({ behavior: 'smooth', block: 'start' });
36
  });
37
 
38
  afterUpdate((): void => {
 
61
  currentTime = (duration * (event.touches[0].clientX - left)) / (right - left);
62
  };
63
 
64
+ const keyDown = (event: KeyboardEvent): void => {
65
+ event.preventDefault();
66
 
67
+ if (event.code === 'Space') {
68
  paused = !paused;
69
  }
70
+ if (event.code === 'ArrowLeft') {
71
  currentTime = currentTime >= 1 ? currentTime - 1 : 0;
72
  }
73
+ if (event.code === 'ArrowRight') {
74
  currentTime = currentTime <= duration - 1 ? currentTime + 1 : duration;
75
  }
76
  };
77
  </script>
78
 
79
+ <section bind:this={section} transition:fade>
80
+ <img class="notes" src={$notesImage} alt="" bind:this={visualisation} />
81
+ <div
82
+ bind:this={player}
83
+ class="player"
84
+ style:width={imageWidth + 'px'}
85
+ style:height={imageHeight + 'px'}
86
+ on:mousemove={mouseMove}
87
+ on:touchmove|preventDefault={touchMove}
88
+ on:keydown={keyDown}
89
+ on:click={() => (paused = !paused)}
90
+ tabindex="0"
91
+ >
92
+ <audio bind:currentTime bind:duration bind:paused src={$audioBlob} />
93
+ <div class="handle" style:transform="translate({imageWidth * (currentTime / duration)}px, -2%)" />
94
+ {#if paused}
95
+ <img class="play-button" src="static/play.svg" alt="Play button" draggable="false" transition:fade />
96
+ {/if}
97
+ </div>
98
+ <a href={$audioBlob} download={`${styles[$style]} Composition - AI Guru ft. Hugging Face.wav`} class="download"
99
+ >Download</a
100
+ >
101
+ </section>
 
 
102
 
103
  <style>
104
  section {
source/ui/src/routes/index.svelte CHANGED
@@ -5,6 +5,7 @@ import TemperatureOptions from '$lib/TemperatureOptions.svelte';
5
  import ComposeButton from '$lib/ComposeButton.svelte';
6
  import Notes from '$lib/Notes.svelte';
7
  import Tokens from '$lib/Tokens.svelte';
 
8
  </script>
9
 
10
  <main>
@@ -25,8 +26,10 @@ import Tokens from '$lib/Tokens.svelte';
25
  <TemperatureOptions />
26
  </section>
27
  <ComposeButton />
28
- <Notes />
29
- <Tokens />
 
 
30
  </main>
31
 
32
  <style>
 
5
  import ComposeButton from '$lib/ComposeButton.svelte';
6
  import Notes from '$lib/Notes.svelte';
7
  import Tokens from '$lib/Tokens.svelte';
8
+ import { audioBlob } from '$lib/stores';
9
  </script>
10
 
11
  <main>
 
26
  <TemperatureOptions />
27
  </section>
28
  <ComposeButton />
29
+ {#if $audioBlob}
30
+ <Notes />
31
+ <Tokens />
32
+ {/if}
33
  </main>
34
 
35
  <style>