Skip to content

Commit

Permalink
feat: use localStorage to save volume slider position
Browse files Browse the repository at this point in the history
  • Loading branch information
mateusfg7 committed Aug 22, 2022
1 parent 1bcd29d commit 8275964
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/components/VolumeController/index.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,27 @@
import React, { useState } from 'react'
import React, { useEffect, useState } from 'react'

export interface IVolumeController {
state: boolean
soundNameOnLocalStorage: string
handleSoundVolume: (volume: number) => void
}

export const VolumeController: React.FC<IVolumeController> = ({
state,
soundNameOnLocalStorage,
handleSoundVolume
}) => {
const [rangeValue, setRangeValue] = useState(1000)

useEffect(() => {
if (typeof window !== 'undefined') {
const storageValue = localStorage.getItem(
`${soundNameOnLocalStorage}-volume`
)
if (storageValue) setRangeValue(JSON.parse(storageValue) * 1000)
}
}, [])

return (
<div
className={`w-full h-max relative group ${
Expand Down

0 comments on commit 8275964

Please sign in to comment.