From d095488c74d9fc61cac095730e31a9519d28da3e Mon Sep 17 00:00:00 2001 From: Djeeberjr Date: Mon, 15 Nov 2021 22:15:38 +0100 Subject: [PATCH] elevated state to App --- src/components/AllDecks.tsx | 33 ++++++++++++++++++--------------- src/components/App.tsx | 16 +++++----------- 2 files changed, 23 insertions(+), 26 deletions(-) diff --git a/src/components/AllDecks.tsx b/src/components/AllDecks.tsx index 30b46eb..47946cc 100644 --- a/src/components/AllDecks.tsx +++ b/src/components/AllDecks.tsx @@ -1,46 +1,49 @@ -import React, { useState } from "react" +import React from "react" import RetakesConfig from "../types/RetakesConfig" import Side from "../types/Side" import CardComp from "./Card" import DeckComp from "./Deck" -const AllDecks: React.FC = () => { - const [retakesConfig,setRetakesConfig] = useState(new RetakesConfig()) +interface Props { + retakesConfig: RetakesConfig + onChange?: (newConfig: RetakesConfig)=>void +} +const AllDecks: React.FC = ({retakesConfig,onChange}) => { return (
setRetakesConfig(new RetakesConfig({...retakesConfig,...{ctPistol:newDeck}}))} /> + onChange={(newDeck)=> onChange?.(new RetakesConfig({...retakesConfig,...{ctPistol:newDeck}}))} /> setRetakesConfig(new RetakesConfig({...retakesConfig,...{tPistol:newDeck}}))} /> + onChange={(newDeck)=> onChange?.(new RetakesConfig({...retakesConfig,...{tPistol:newDeck}}))} /> setRetakesConfig(new RetakesConfig({...retakesConfig,...{ctUpgradedPistol:newDeck}}))} /> + onChange={(newDeck)=> onChange?.(new RetakesConfig({...retakesConfig,...{ctUpgradedPistol:newDeck}}))} /> setRetakesConfig(new RetakesConfig({...retakesConfig,...{tUpgradedPistol:newDeck}}))} /> + onChange={(newDeck)=> onChange?.(new RetakesConfig({...retakesConfig,...{tUpgradedPistol:newDeck}}))} /> setRetakesConfig(new RetakesConfig({...retakesConfig,...{ctLight:newDeck}}))} /> + onChange={(newDeck)=> onChange?.(new RetakesConfig({...retakesConfig,...{ctLight:newDeck}}))} /> setRetakesConfig(new RetakesConfig({...retakesConfig,...{tLight:newDeck}}))} /> + onChange={(newDeck)=> onChange?.(new RetakesConfig({...retakesConfig,...{tLight:newDeck}}))} /> setRetakesConfig(new RetakesConfig({...retakesConfig,...{ctFull:newDeck}}))} /> + onChange={(newDeck)=> onChange?.(new RetakesConfig({...retakesConfig,...{ctFull:newDeck}}))} /> setRetakesConfig(new RetakesConfig({...retakesConfig,...{tFull:newDeck}}))} /> + onChange={(newDeck)=> onChange?.(new RetakesConfig({...retakesConfig,...{tFull:newDeck}}))} />
setRetakesConfig(new RetakesConfig({...retakesConfig,...{ctEnemy:newCard}}))} /> + onChange={(newCard)=>onChange?.(new RetakesConfig({...retakesConfig,...{ctEnemy:newCard}}))} /> setRetakesConfig(new RetakesConfig({...retakesConfig,...{tEnemy:newCard}}))} /> + onChange={(newCard)=>onChange?.(new RetakesConfig({...retakesConfig,...{tEnemy:newCard}}))} />
setRetakesConfig(new RetakesConfig({...retakesConfig,...{ctBonus:newCard}}))} /> + onChange={(newCard)=>onChange?.(new RetakesConfig({...retakesConfig,...{ctBonus:newCard}}))} /> setRetakesConfig(new RetakesConfig({...retakesConfig,...{tBonus:newCard}}))} /> + onChange={(newCard)=>onChange?.(new RetakesConfig({...retakesConfig,...{tBonus:newCard}}))} />
) diff --git a/src/components/App.tsx b/src/components/App.tsx index 8a0d2f2..e5a8323 100644 --- a/src/components/App.tsx +++ b/src/components/App.tsx @@ -1,22 +1,16 @@ -import React from 'react'; +import React, { useState } from 'react'; +import RetakesConfig from '../types/RetakesConfig'; import AllDecks from './AllDecks'; import MenuBar from './MenuBar'; function App() { - // const [CTDeck,setCTDeck] = useState(new Deck( - // 2,new CardGroup( - // 2,new Card("AWE fake",false,false,Item.AWP,Item.DECOY), - // new Card("M4 Flash",true,true,Item.AK_47_M4,Item.FLASHBANG) - // ), - // new CardGroup( - // 3,new Card("One deag",true,false,Item.DESERT_EAGLE) - // ) - // )) + + const [retakesConfig,setRetakesConfig] = useState(new RetakesConfig()) return (
- + setRetakesConfig(newConfig)} />
); }