mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-10-24 23:49:06 +08:00
fix(client): set fcc-sound value in local storage (#48762)
This commit is contained in:
@@ -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 })
|
||||
);
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user