Skip to content

Commit

Permalink
Add foods json
Browse files Browse the repository at this point in the history
  • Loading branch information
albin-karlsson committed Apr 5, 2024
1 parent 508d5c3 commit cac43e9
Show file tree
Hide file tree
Showing 10 changed files with 258 additions and 57 deletions.
135 changes: 135 additions & 0 deletions client/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 client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-scripts": "5.0.1",
"socket.io-client": "^4.7.5",
"web-vitals": "^2.1.4"
},
"scripts": {
Expand Down
1 change: 1 addition & 0 deletions client/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>Council of Foods</title>
<script src="/socket.io/socket.io.js"></script>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
Expand Down
15 changes: 12 additions & 3 deletions client/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,25 @@ function App() {
}

return (
<div className="App" style={backgroundStyle}>
<div
className="App"
style={backgroundStyle}
>
<Overlay isActive={isActiveOverlay && currentView !== "council"}>
{currentView === "landing" ? (
<Landing onContinueForward={continueForward} />
) : currentView === "welcome" ? (
<Welcome humanName={humanName} onContinueForward={continueForward} />
<Welcome
humanName={humanName}
onContinueForward={continueForward}
/>
) : currentView === "topics" ? (
<Topics onContinueForward={continueForward} />
) : currentView === "foods" ? (
<Foods topic={topic} onContinueForward={continueForward} />
<Foods
topic={topic}
onContinueForward={continueForward}
/>
) : (
<Council
options={{
Expand Down
17 changes: 15 additions & 2 deletions client/src/components/Council.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import React, { useState } from "react";
import React, { useState, useEffect } from "react";
import io from "socket.io-client";
import foodsData from "../foods.json";
import FoodItem from "./FoodItem";
import Overlay from "./Overlay";
import About from "./About";
Expand All @@ -12,6 +14,7 @@ import useWindowSize from "../hooks/useWindowSize";

function Council({ options }) {
const { foods } = options;
const { foodsData } = foodsData;
const [activeOverlay, setActiveOverlay] = useState(""); // Tracks which overlay to show
const { width: screenWidth } = useWindowSize();

Expand All @@ -26,6 +29,13 @@ function Council({ options }) {
alignItems: "center",
};

// Test socket
useEffect(() => {
const socket = io();

console.log(socket);
}, []);

function displayResetWarning() {
setActiveOverlay("reset");
}
Expand Down Expand Up @@ -72,7 +82,10 @@ function Council({ options }) {
<div style={{ height: "100%", width: "100%" }}>
<div className="wrapper">
{activeOverlay === "" && (
<div className="text-container" style={{ justifyContent: "end" }}>
<div
className="text-container"
style={{ justifyContent: "end" }}
>
<TextOutput />
</div>
)}
Expand Down
24 changes: 14 additions & 10 deletions client/src/components/FoodButton.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from "react";

function FoodButton({
foodName,
food,
onSelectFood,
onDeselectFood,
onMouseEnter,
Expand All @@ -11,14 +11,14 @@ function FoodButton({
}) {
const isModerator = onSelectFood === undefined;

const imageUrl = `/images/foods/${foodName}.png`;
const imageUrl = `/images/foods/${food.name}.png`;

function handleClickFood() {
if (!isModerator && (!selectLimitReached || isSelected)) {
if (!isSelected) {
onSelectFood?.(foodName);
onSelectFood?.(food);
} else {
onDeselectFood?.(foodName);
onDeselectFood?.(food);
}
}
}
Expand All @@ -32,6 +32,10 @@ function FoodButton({
display: "flex",
justifyContent: "center",
alignItems: "center",
cursor:
isModerator || (selectLimitReached && !isSelected)
? "default"
: "pointer",
border: isModerator
? "4px solid white"
: isSelected
Expand All @@ -45,22 +49,22 @@ function FoodButton({
width: "80%",
height: "80%",
objectFit: "cover",
cursor:
isModerator || (selectLimitReached && !isSelected)
? "default"
: "pointer",
borderRadius: "50%",
};

return (
<div
className="food-button"
onMouseEnter={() => onMouseEnter(foodName)}
onMouseEnter={onMouseEnter}
onMouseLeave={onMouseLeave}
style={buttonStyle}
onClick={handleClickFood}
>
<img src={imageUrl} alt={foodName} style={imageStyle} />
<img
src={imageUrl}
alt={food.name}
style={imageStyle}
/>
</div>
);
}
Expand Down
14 changes: 10 additions & 4 deletions client/src/components/FoodInfo.jsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
import React from "react";
import { capitalizeFirstLetter } from "../utils.js";

function FoodInfo({ foodName }) {
const capitalizedFoodName = capitalizeFirstLetter(foodName);
function FoodInfo({ food }) {
if (!food) {
return null;
}

console.log(food.name);

const capitalizedFoodName = capitalizeFirstLetter(food.name);

return (
<div>
<h2>{capitalizedFoodName}</h2>
<div>
<h4 className="italic">Lorem</h4>
<h4 className="italic">Variety: Lorem ipsum</h4>
<h4 className="italic">Origin: Lorem</h4>
<h4 className="italic">Variety: {food.variety}</h4>
<h4 className="italic">Origin: {food.origin}</h4>
</div>
<h4>
Lorem ipsum dolor, sit amet consectetur adipisicing elit.
Expand Down
Loading

0 comments on commit cac43e9

Please sign in to comment.