fix(client): set fcc-sound value in local storage (#48762)

This commit is contained in:
Atir Nayab
2023-01-05 12:40:09 +05:30
committed by GitHub
parent 1cf977f06a
commit 9ad2fedf39
2 changed files with 12 additions and 9 deletions
+8 -1
View File
@@ -1,5 +1,5 @@
import { call, put, takeEvery } from 'redux-saga/effects';
import store from 'store';
import { getSessionUser, getUserProfile } from '../utils/ajax';
import {
fetchProfileForUserComplete,
@@ -19,6 +19,13 @@ function* fetchSessionUser() {
data: { user = {}, result = '', sessionMeta = {} }
} = yield call(getSessionUser);
const appUser = user[result] || {};
const [userId] = Object.keys(user);
const sound = user[userId].sound;
store.set('fcc-sound', sound);
yield put(
fetchUserComplete({ user: appUser, username: result, sessionMeta })
);
+4 -8
View File
@@ -62,20 +62,16 @@ type ToneStates = keyof typeof toneUrls;
export async function playTone(state: ToneStates): Promise<void> {
const playSound = !!store.get('fcc-sound');
if (playSound && toneUrls[state]) {
const tone = await import('tone');
const Tone = await import('tone');
if (tone.context.state !== 'running') {
tone.context.resume().catch(err => {
console.error('Error resuming audio context', err);
});
}
const player = new tone.Player(toneUrls[state]).toDestination();
const player = new Tone.Player(toneUrls[state]).toDestination();
const storedVolume = (store.get('soundVolume') as number) ?? 50;
const calculateDecibel = -60 * (1 - storedVolume / 100);
player.volume.value = calculateDecibel;
player.autostart = true;
await Tone.loaded();
player.start();
}
}