This commit is contained in:
Maciej Caderek
2022-04-23 03:58:31 +02:00
parent 8462bb949a
commit 4e67a55a15
83 changed files with 692 additions and 167 deletions

View File

@@ -1,12 +1,31 @@
import { PiecesStyle } from "./../board/styles-pieces/piecesStyles";
import { boardNames } from "../board/styles-board/boardStyles";
import piecesStyles from "../board/styles-pieces/piecesStyles";
const fixBoardConfig = (boardConfig: { [key: string]: string }) => {
if (!boardNames.includes(boardConfig.boardStyle)) {
delete boardConfig.boardStyle;
}
if (!piecesStyles.includes(boardConfig.piecesStyle as PiecesStyle)) {
delete boardConfig.piecesStyle;
}
return boardConfig;
};
const loadConfig = () => {
const boardConfig = localStorage.getItem("boardConfig");
const gameConfig = localStorage.getItem("gameConfig");
const siteConfig = localStorage.getItem("siteConfig");
const recent = localStorage.getItem("recent");
return {
boardConfig: boardConfig === null ? {} : JSON.parse(boardConfig),
boardConfig:
boardConfig === null ? {} : fixBoardConfig(JSON.parse(boardConfig)),
gameConfig: gameConfig === null ? {} : JSON.parse(gameConfig),
siteConfig: siteConfig === null ? {} : JSON.parse(siteConfig),
recent: recent === null ? [] : JSON.parse(recent),
};
};

View File

@@ -1,6 +1,6 @@
import { state } from "../state";
const saveConfig = (type: "board" | "game" | "site") => {
const saveConfig = (type: "board" | "game" | "site" | "recent") => {
switch (type) {
case "board":
localStorage.setItem("boardConfig", JSON.stringify(state.boardConfig));
@@ -11,6 +11,9 @@ const saveConfig = (type: "board" | "game" | "site") => {
case "site":
localStorage.setItem("siteConfig", JSON.stringify(state.siteConfig));
break;
case "recent":
localStorage.setItem("recent", JSON.stringify(state.recent));
break;
}
};