add sound selector

This commit is contained in:
Mario Pesch
2021-12-13 15:35:25 +01:00
parent 59a226f22e
commit 258f0f0841
9 changed files with 110 additions and 3 deletions
+16
View File
@@ -2,6 +2,7 @@ import {
VISIT,
LANGUAGE,
RENDERER,
SOUNDS,
STATISTICS,
PLATFORM,
} from "../actions/types";
@@ -20,6 +21,14 @@ const initialPlatform = () => {
return getPlatform();
};
const initialSounds = () => {
if (window.localStorage.getItem("sounds")) {
return window.localStorage.getItem("sounds");
} else {
return "off";
}
};
const getPlatform = () => {
if (window.localStorage.getItem("platform")) {
return JSON.parse(window.localStorage.getItem("platform"));
@@ -62,6 +71,7 @@ const initialState = {
pageVisits: 0, // detect if previous URL was
language: initialLanguage(),
renderer: initialRenderer(),
sounds: initialSounds(),
statistics: initialStatistics(),
platform: initialPlatform(),
};
@@ -90,6 +100,12 @@ export default function foo(state = initialState, action) {
...state,
renderer: action.payload,
};
case SOUNDS:
window.localStorage.setItem("sounds", action.payload);
return {
...state,
sounds: action.payload,
};
case STATISTICS:
window.localStorage.setItem("statistics", action.payload);
return {