Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

origin #23

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "chrome",
"request": "launch",
"name": "Launch Chrome against localhost",
"url": "http://localhost:8080",
"webRoot": "${workspaceFolder}"
}
]
}
1 change: 1 addition & 0 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions src/components/App.js → src/__tests__/App.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react";
mport React from "react";
import Nav from "./Nav";

import hogs from "../porkers_data";
Expand All @@ -11,4 +11,4 @@ function App() {
);
}

export default App;
export default App;
31 changes: 31 additions & 0 deletions src/components/Filtersort.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import React from "react";

const FilterSort = ({ filterGreased, setFilterGreased, setSortType }) => {
return (
<div className="filter-sort">
<div className="filter">
<label>
<input
type="checkbox"
checked={filterGreased}
onChange={() => setFilterGreased(!filterGreased)}
/>
Greased Hogs
</label>
</div>

<div className="sort">
<label>
Sort by:
<select onChange={(e) => setSortType(e.target.value)}>
<option value="">Select</option>
<option value="name">Name</option>
<option value="weight">Weight</option>
</select>
</label>
</div>
</div>
);
};

export default FilterSort;
44 changes: 44 additions & 0 deletions src/components/Hogtile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import React, { useState } from "react";

function HogTile({ hog, hideHog }) {
const [showDetails, setShowDetails] = useState(false);

const toggleDetails = () => {
setShowDetails(!showDetails);
};

return (
<div className="ui eight wide column">
<div className="ui card">
<div className="image">
<img src={hog.image} alt={hog.name} />
</div>
<div className="content">
<h3 className="header">{hog.name}</h3>
<div className="meta">
<span className="date">Specialty: {hog.specialty}</span>
</div>
<div className="description">
{showDetails && (
<>
<p>Weight: {hog.weight}</p>
<p>Greased: {hog.greased ? "Yes" : "No"}</p>
<p>Highest Medal Achieved: {hog["highest medal achieved"]}</p>
</>
)}
</div>
</div>
<div className="extra content">
<button className="ui button" onClick={toggleDetails}>
{showDetails ? "Hide Details" : "Show Details"}
</button>
<button className="ui button red" onClick={() => hideHog(hog.name)}>
Hide Hog
</button>
</div>
</div>
</div>
);
}

export default HogTile;
97 changes: 97 additions & 0 deletions src/components/NewHogForm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import React, { useState } from "react";

const NewHogForm = ({ addNewHog }) => {
const [name, setName] = useState("");
const [specialty, setSpecialty] = useState("");
const [greased, setGreased] = useState(false);
const [weight, setWeight] = useState("");
const [medal, setMedal] = useState("");
const [image, setImage] = useState("");

const handleSubmit = (e) => {
e.preventDefault();
const newHog = { name, specialty, greased, weight, medal, image };
addNewHog(newHog);
// Clear the form after submission
setName("");
setSpecialty("");
setGreased(false);
setWeight("");
setMedal("");
setImage("");
};

return (
<form className="new-hog-form" onSubmit={handleSubmit}>
<h2>Add a New Hog</h2>
<div className="form-group">
<label htmlFor="name">Name:</label>
<input
type="text"
id="name"
value={name}
onChange={(e) => setName(e.target.value)}
required
/>
</div>

<div className="form-group">
<label htmlFor="specialty">Specialty:</label>
<input
type="text"
id="specialty"
value={specialty}
onChange={(e) => setSpecialty(e.target.value)}
required
/>
</div>

<div className="form-group">
<label htmlFor="greased">Greased:</label>
<input
type="checkbox"
id="greased"
checked={greased}
onChange={(e) => setGreased(e.target.checked)}
/>
</div>

<div className="form-group">
<label htmlFor="weight">Weight:</label>
<input
type="number"
id="weight"
value={weight}
onChange={(e) => setWeight(e.target.value)}
required
/>
</div>

<div className="form-group">
<label htmlFor="medal">Highest Medal Achieved:</label>
<input
type="text"
id="medal"
value={medal}
onChange={(e) => setMedal(e.target.value)}
required
/>
</div>

<div className="form-group">
<label htmlFor="image">Image URL:</label>
<input
type="text"
id="image"
value={image}
onChange={(e) => setImage(e.target.value)}
required
/>
</div>

<button type="submit" className="submit-button">Add Hog</button>
</form>
);
};

export default NewHogForm;