Skip to content

Commit

Permalink
Add React Router (#9)
Browse files Browse the repository at this point in the history
* Added router and CSS

* re-ordered some components, made CSS changes, added 404 page

* Added alt text to image on Error404 component
  • Loading branch information
villanovachile authored Mar 13, 2023
1 parent 8e3a155 commit 3d30eba
Show file tree
Hide file tree
Showing 13 changed files with 168 additions and 70 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,6 @@
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Local Netlify folder
.netlify
61 changes: 61 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"@testing-library/user-event": "^13.5.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.9.0",
"react-scripts": "5.0.1",
"web-vitals": "^2.1.4"
},
Expand Down
1 change: 1 addition & 0 deletions public/_redirects
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* /index.html 200
7 changes: 6 additions & 1 deletion src/components/App.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import React from "react";
import { Routes, Route } from "react-router-dom";
import TruthTally from "./TruthTally";
import Header from "./Header";
import Error404 from "./Error404";

const App = () => {
return (
<div className="main-container">
<Header />
<TruthTally />
<Routes>
<Route path="/" element={<TruthTally />} />
<Route path="/*" element={<Error404 />} />
</Routes>
</div>
);
};
Expand Down
19 changes: 19 additions & 0 deletions src/components/Error404.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import React from "react";
import { NavLink } from "react-router-dom";

const Error404 = () => {
return (
<div className="error404-div">
<h1>Error 404</h1>
<img
src={require("../images/logo192.png")}
alt="Truth Tally logo"
width="100px"
></img>
<h2>Not Found</h2>
<NavLink to="/">Start a new list</NavLink>
</div>
);
};

export default Error404;
13 changes: 4 additions & 9 deletions src/components/Header.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import React from 'react';

import React from "react";

const Header = () => {
return (
<header>
Truth Tally
</header>
);
}
return <header>Truth Tally's</header>;
};

export default Header;
export default Header;
44 changes: 19 additions & 25 deletions src/components/TruthTally/ItemsList.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,24 @@
import React from 'react';
import Item from './Item';
import AddItemForm from './AddItemForm';
import React from "react";
import Item from "./Item";
import AddItemForm from "./AddItemForm";

const ItemsList = ({items, handleAddItem, gameState, handleRemoveItem}) => {

if (gameState === 'start') {
const ItemsList = ({ items, handleAddItem, gameState, handleRemoveItem }) => {
if (gameState === "start") {
return (
<div className="items-list">

<AddItemForm
handleAddItem={handleAddItem}
items={items}
/>
{items.map(item =>
<Item
item={item.item}
handleRemoveItem={handleRemoveItem}
score={item.score}
id={item.id}
key={item.id.toString()}
/>
)}

</div>
<div className="items-list">
<AddItemForm handleAddItem={handleAddItem} items={items} />
{items.map((item) => (
<Item
item={item.item}
handleRemoveItem={handleRemoveItem}
score={item.score}
id={item.id}
key={item.id.toString()}
/>
))}
</div>
);
}
}
};

export default ItemsList;
export default ItemsList;
4 changes: 2 additions & 2 deletions src/components/TruthTally/TruthTally.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@ function TruthTally() {
<div className="truthtally-container">
<LoadingSpinner {...props} />

<ItemsList {...props} />
<Controls {...props} />

<Stage {...props} />

<Results {...props} />

<Controls {...props} />
<ItemsList {...props} />
</div>
);
}
Expand Down
41 changes: 26 additions & 15 deletions src/components/TruthTally/index.css
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
.truthtally-container {
background: #ffffff;
background: white;
min-width: 375px;
max-width: 700px;
width: 100%;
display: flex;
flex-direction: column;
flex: 0 0 auto;
margin: auto;
box-shadow: 0 2px 0 rgb(119, 0, 0);
overflow: hidden;
border: 1px;
border-style: solid;
overflow-y: scroll;
justify-content: flex-start;
}

.items-list {
flex-grow: 1;
}

.list-item {
Expand All @@ -16,16 +26,13 @@
font-size: 1.2em;
border-bottom: solid 2px #eeeeee;
letter-spacing: 2px;
color: #2f2366;
}

.list-item:hover .remove-item {
visibility: visible;
}

.list-item {
color: #2f2366;
}

.player-item {
flex-grow: 1;
line-height: 3.5em;
Expand Down Expand Up @@ -166,16 +173,17 @@
}
}

/* Mobile View */

@media screen and (max-width: 768px) {
.truthtally-container {
width: 100%;
height: 100%;
box-shadow: none;
border-radius: 0;
border: none;
display: flex;
flex-direction: column;
flex: 1;
flex-grow: 1;
}

.list-item {
Expand All @@ -185,12 +193,9 @@
}

.items-list {
flex: 1 1 auto;
display: flex;
flex-direction: column;
overflow-y: scroll;
justify-content: left;
align-items: center;
justify-content: flex-end;
}

.player-item {
Expand All @@ -217,18 +222,18 @@
}

.stage-container {
height: auto;
flex-direction: column;
padding: 10px;
flex: 1 1 auto;
display: flex;
justify-content: center;
align-items: center;

height: 100px;
}

.item-card {
width: 100%;
min-height: 60px;
margin-bottom: 10px;
font-size: 1.8em;
padding: 0px;
Expand Down Expand Up @@ -283,10 +288,10 @@
flex: 1 1 auto;
display: flex;
flex-direction: column;
overflow-y: scroll;
justify-content: left;
align-items: center;
width: 100%;
flex-grow: 1;
}

li {
Expand Down Expand Up @@ -314,4 +319,10 @@
font-weight: bold;
margin-top: 10px;
}
.controls {
padding: 10px;
background-color: rgb(119, 0, 0);
display: flex;
justify-content: center;
}
}
Binary file added src/images/logo192.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 3d30eba

Please sign in to comment.