diff --git a/patches/0009-show-audio-controls-and-speed.diff b/patches/0009-show-audio-controls-and-speed.diff new file mode 100644 index 0000000..c892969 --- /dev/null +++ b/patches/0009-show-audio-controls-and-speed.diff @@ -0,0 +1,132 @@ +diff -Naur orig.orig/components/commons/Audio.jsx orig/components/commons/Audio.jsx +--- orig.orig/components/commons/Audio.jsx 1969-12-31 21:00:00.000000000 -0300 ++++ orig/components/commons/Audio.jsx 2021-10-15 16:28:48.809523282 -0300 +@@ -0,0 +1,76 @@ ++import { forwardRef, useState, useEffect } from 'react'; ++ ++// https://formidable.com/blog/2021/stores-no-context-api/ ++const createEmitter = () => { ++ const subscriptions = new Map(); ++ return { ++ emit: (v) => subscriptions.forEach(fn => fn(v)), ++ subscribe: (fn) => { ++ const key = Symbol(); ++ subscriptions.set(key, fn); ++ return () => subscriptions.delete(key); ++ }, ++ } ++}; ++ ++const createStore = (init) => { ++ // create an emitter ++ const emitter = createEmitter(); ++ ++ let store = null; ++ const get = () => store; ++ const set = (op) => ( ++ store = op(store), ++ // notify all subscriptions when the store updates ++ emitter.emit(store) ++ ); ++ store = init(get, set); ++ ++ const useStore = () => { ++ // intitialize component with latest store ++ const [localStore, setLocalStore] = useState(get()); ++ ++ // update our local store when the global ++ // store updates. ++ // ++ // emitter.subscribe returns a cleanup ++ // function, so react will clean this ++ // up on unmount. ++ useEffect(() => emitter.subscribe(setLocalStore), []); ++ return localStore; ++ }; ++ return useStore; ++}; ++ ++const useSpeed = createStore((get, set) => ({ ++ value: 1, ++ set: value => set((state) => ({ ...state, value })), ++})); ++ ++export const Audio = forwardRef((props, ref) => { ++ const [playing, setPlaying] = useState(false); ++ const { value, set } = useSpeed(); ++ ++ useEffect(() => { ++ ref.current.playbackRate = value ++ }, [value]) ++ ++ return ( ++