Skip to content

Commit

Permalink
feat: volume control in solidjs
Browse files Browse the repository at this point in the history
  • Loading branch information
tannineo committed Oct 2, 2023
1 parent 927e7c1 commit ee654e3
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/components/Metronome.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { p$stressFirstBeat } from '../store/stressFirstBeat'
import PatternSelection from './metronome/PatternSelection'
import Player from './metronome/Player'
import BPMPreset from './metronome/BPMPreset'
import Volume from './metronome/Volume'

const Metronome = () => {
const metronomeStatus = useStore($metronomeStatus)
Expand Down Expand Up @@ -60,6 +61,8 @@ const Metronome = () => {
</div>

<PatternSelection />

<Volume />
</div>
)
}
Expand Down
1 change: 1 addition & 0 deletions src/components/MetronomeExtraPanel.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/** @jsxImportSource react */
// WARN deprecated, Solid does not work well on Astro

import { useStore } from '@nanostores/react'
import { MAX_VOLUME, MIN_VOLUME } from '../consts'
Expand Down
35 changes: 35 additions & 0 deletions src/components/metronome/Volume.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/** @jsxImportSource solid-js */

import { createEffect } from 'solid-js'
import { useStore } from '@nanostores/solid'

import { MAX_VOLUME, MIN_VOLUME } from '../../consts'
import { actionSetVolume, p$volume } from '../../store/volume'
import { changeVolume } from '../../sounds'

const Volume = () => {
const volume = useStore(p$volume)

createEffect(() => {
changeVolume(volume())
})

return (
<div class='w-full max-w-lg flex flex-col rounded-md p-4 text-shironeri'>
<label>Volume:</label>

<input
class='w-full'
value={volume()}
type='range'
min={MIN_VOLUME}
max={MAX_VOLUME}
onChange={e => {
actionSetVolume(parseInt(e.target.value))
}}
></input>
</div>
)
}

export default Volume
2 changes: 1 addition & 1 deletion src/pages/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ import MetronomeExtraPanel from '../components/MetronomeExtraPanel.tsx'
<Metronome client:only='solid-js' />

<!-- WARN cannot pass callbacks to Astro Islands, might be that functions cannot be serialized -->
<MetronomeExtraPanel client:only='react' />
<!-- <MetronomeExtraPanel client:only='react' /> -->
</BaseLayout>

0 comments on commit ee654e3

Please sign in to comment.