New game button

This commit is contained in:
Jeremie Pardou-Piquemal 2020-06-24 22:22:50 +02:00 committed by Jérémie Pardou-Piquemal
parent cc67a28903
commit 35144ad7bd
2 changed files with 15 additions and 4 deletions

View file

@ -70,6 +70,14 @@ export const GameController = ({ availableItemList, boardConfig }) => {
[c2c] [c2c]
); );
const newGame = React.useCallback(() => {
loadGame({
items: [],
availableItems: [],
board: { size: 1000, scale: 0.5 },
});
}, [loadGame]);
const loadTikTok = React.useCallback(() => { const loadTikTok = React.useCallback(() => {
tiktok.availableItems = []; tiktok.availableItems = [];
loadGame(tiktok); loadGame(tiktok);
@ -141,6 +149,7 @@ export const GameController = ({ availableItemList, boardConfig }) => {
return ( return (
<LeftPane> <LeftPane>
<Title onClick={logGame}>{t("Games")}</Title> <Title onClick={logGame}>{t("Games")}</Title>
<button onClick={newGame}>New Game</button>
<button onClick={loadTestGame}>Test Game</button> <button onClick={loadTestGame}>Test Game</button>
<button onClick={loadTikTok}>TikTok</button> <button onClick={loadTikTok}>TikTok</button>
<button onClick={loadCard}>Card</button> <button onClick={loadCard}>Card</button>

View file

@ -1,4 +1,4 @@
import React from "react"; import React, { memo } from "react";
import { useItems } from "../components/Board/Items"; import { useItems } from "../components/Board/Items";
import { nanoid } from "nanoid"; import { nanoid } from "nanoid";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
@ -14,7 +14,7 @@ const itemTemplates = {
dice: {}, dice: {},
}; };
const NewItem = ({ type }) => { const NewItem = memo(({ type }) => {
const { t } = useTranslation(); const { t } = useTranslation();
const { pushItem } = useItems(); const { pushItem } = useItems();
@ -35,7 +35,9 @@ const NewItem = ({ type }) => {
{t(type)} {t(type)}
</button> </button>
); );
}; });
NewItem.displayName = "NewItem";
const NewItems = () => { const NewItems = () => {
return ( return (
@ -49,4 +51,4 @@ const NewItems = () => {
); );
}; };
export default NewItems; export default memo(NewItems);