mirror of
https://github.com/stoatchat/for-legacy-web.git
synced 2026-03-07 09:25:27 +00:00
Settings: Link notification sounds to playSound.
Fix: Restore hooks.ts patch, additionally use numbers.
This commit is contained in:
@@ -4,28 +4,47 @@
|
||||
//
|
||||
// Replace references to SettingsContext with connectState in the future
|
||||
// if it does cause problems though.
|
||||
//
|
||||
// This now also supports Audio stuff.
|
||||
|
||||
import { Settings } from "../redux/reducers/settings";
|
||||
import { DEFAULT_SOUNDS, Settings, SoundOptions } from "../redux/reducers/settings";
|
||||
import { playSound, Sounds } from "../assets/sounds/Audio";
|
||||
import { connectState } from "../redux/connector";
|
||||
import defaultsDeep from "lodash.defaultsdeep";
|
||||
import { Children } from "../types/Preact";
|
||||
import { createContext } from "preact";
|
||||
import { useMemo } from "preact/hooks";
|
||||
|
||||
export const SettingsContext = createContext<Settings>({} as any);
|
||||
export const SoundContext = createContext<(sound: Sounds) => void>({} as any);
|
||||
|
||||
interface Props {
|
||||
children?: Children,
|
||||
settings: Settings
|
||||
}
|
||||
|
||||
function Settings(props: Props) {
|
||||
function Settings({ settings, children }: Props) {
|
||||
console.info(settings.notification);
|
||||
const play = useMemo(() => {
|
||||
const enabled: SoundOptions = defaultsDeep(settings.notification ?? {}, DEFAULT_SOUNDS);
|
||||
return (sound: Sounds) => {
|
||||
console.info('check if we can play sound', enabled[sound]);
|
||||
if (enabled[sound]) {
|
||||
playSound(sound);
|
||||
}
|
||||
};
|
||||
}, [ settings.notification ]);
|
||||
|
||||
return (
|
||||
<SettingsContext.Provider value={props.settings}>
|
||||
{ props.children }
|
||||
<SettingsContext.Provider value={settings}>
|
||||
<SoundContext.Provider value={play}>
|
||||
{ children }
|
||||
</SoundContext.Provider>
|
||||
</SettingsContext.Provider>
|
||||
)
|
||||
}
|
||||
|
||||
export default connectState(Settings, state => {
|
||||
export default connectState<Omit<Props, 'settings'>>(Settings, state => {
|
||||
return {
|
||||
settings: state.settings
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user