Skip to content

Commit

Permalink
Restructure Components: Move App into its own TruthTally component (#8)
Browse files Browse the repository at this point in the history
* Restructure app into its own Truth Tally component

* Created Component specific CSS file
  • Loading branch information
villanovachile authored Mar 12, 2023
1 parent d454696 commit 8e3a155
Show file tree
Hide file tree
Showing 13 changed files with 421 additions and 402 deletions.
105 changes: 7 additions & 98 deletions src/components/App.js
Original file line number Diff line number Diff line change
@@ -1,105 +1,14 @@
import React, { useState, useRef } from 'react';
import Header from './Header';
import ItemsList from './ItemsList';
import Stage from './Stage';
import Controls from './Controls';
import Results from './Results';
import LoadingSpinner from './LoadingSpinner';


//import logo from './logo.svg';


function App() {

const [items, setItems] = useState ([]);

const [gameState, setGameState] = useState('start');

const [gameCompleted, setGameCompleted] = useState(false);

const [loadingText, setLoadingText] = useState('');

const [pairs, setPairs] = useState([]);

const currentIndex = useRef(0);

const nextItemId = useRef(0);


const handleAddItem = (item) => {
nextItemId.current++

setItems(prevItems => [
...prevItems,
{
item,
score: 0,
id: nextItemId.current
}
]);
}


const handleRemoveItem = (id) => {
setItems(prevItems => prevItems.filter( p => p.id !== id ));
}





const updatePairsList = (a) => {
setPairs(a);
}

const props = {
items,
setItems,
gameState,
setGameState,
gameCompleted,
setGameCompleted,
loadingText,
setLoadingText,
pairs,
setPairs,
currentIndex,
nextItemId,
handleAddItem,
handleRemoveItem,
updatePairsList
};

import React from "react";
import TruthTally from "./TruthTally";
import Header from "./Header";

const App = () => {
return (

<div className="main-container">
<div className="main-container">
<Header />

<LoadingSpinner
{...props}
/>

<ItemsList
{...props}
/>

<Stage
{...props}
/>

<Results
{...props}
/>

<Controls
{...props}
/>


<TruthTally />
</div>
);
}
};

export default App;
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
77 changes: 77 additions & 0 deletions src/components/TruthTally/TruthTally.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import React, { useState, useRef } from "react";
import ItemsList from "./ItemsList";
import Stage from "./Stage";
import Controls from "./Controls";
import Results from "./Results";
import LoadingSpinner from "./LoadingSpinner";

function TruthTally() {
const [items, setItems] = useState([]);

const [gameState, setGameState] = useState("start");

const [gameCompleted, setGameCompleted] = useState(false);

const [loadingText, setLoadingText] = useState("");

const [pairs, setPairs] = useState([]);

const currentIndex = useRef(0);

const nextItemId = useRef(0);

const handleAddItem = (item) => {
nextItemId.current++;

setItems((prevItems) => [
...prevItems,
{
item,
score: 0,
id: nextItemId.current,
},
]);
};

const handleRemoveItem = (id) => {
setItems((prevItems) => prevItems.filter((p) => p.id !== id));
};

const updatePairsList = (a) => {
setPairs(a);
};

const props = {
items,
setItems,
gameState,
setGameState,
gameCompleted,
setGameCompleted,
loadingText,
setLoadingText,
pairs,
setPairs,
currentIndex,
nextItemId,
handleAddItem,
handleRemoveItem,
updatePairsList,
};

return (
<div className="truthtally-container">
<LoadingSpinner {...props} />

<ItemsList {...props} />

<Stage {...props} />

<Results {...props} />

<Controls {...props} />
</div>
);
}

export default TruthTally;
Loading

0 comments on commit 8e3a155

Please sign in to comment.