WIP
This commit is contained in:
@@ -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),
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user