Skip to content
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
3 changes: 3 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
USER=cjdean
PASS=M9QMl1Rmlqr7ideW
HOST="cs4241-a3.rlnw1nu.mongodb.net"
34 changes: 5 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,9 @@
Assignment 4 - Components
===
Cooper Dean
http://a4-dooober.glitch.me

Due: October 4th, by 11:59 AM.
## Custom pokemon v3
This application allows users to create a pokemon by giving it a name, description, and types. The server then generates the pokemon's weaknesses, resistances, and immunities and returns all of the user's pokemon in a table. The only major change from v2 (assignment 3) was the removal of the button that showed how to use the app, since the CSS framework did not fully support react and I did not want to try to find a workaround.

For this assignment you will re-implement the client side portion of *either* A2 or A3 using either React or Svelte components. If you choose A3 you only need to use components for the data display / updating; you can leave your login UI as is.

[Svelte Tutorial](https://github.com/cs4241-21a/cs4241-21a.github.io/blob/main/using_svelte.md)
[React Tutorial](https://github.com/cs4241-21a/cs4241-21a.github.io/blob/main/using_react.md)

This project can be implemented on any hosting service (Glitch, DigitalOcean, Heroku etc.), however, you must include all files in your GitHub repo so that the course staff can view them.

Deliverables
---

Do the following to complete this assignment:

1. Implement your project with the above requirements.
3. Test your project to make sure that when someone goes to your main page on Glitch/Heroku/etc., it displays correctly.
4. Ensure that your project has the proper naming scheme `a4-firstname-lastname` so we can find it.
5. Fork this repository and modify the README to the specifications below. Be sure to add *all* project files.
6. Create and submit a Pull Request to the original repo. Name the pull request using the following template: `a4-firstname-lastname`.

Sample Readme (delete the above when you're ready to submit, and modify the below so with your links and descriptions)
---

## Your Web Application Title

your hosting link e.g. http://a4-charlieroberts.glitch.me

Include a very brief summary of your project here and what you changed / added to assignment #3. Briefly (3–4 sentences) answer the following question: did the new technology improve or hinder the development experience?

Unlike previous assignments, this assignment will be solely graded on whether or not you successfully complete it. Partial credit will be generously given.
The use of React improved the development experience. It made it much easier to implement the frontend, and it also made the frontend more readable. If I were to make further improvements, I would attempt to fix any bugs that occured due to switching to React and split each component into their own file.
247 changes: 247 additions & 0 deletions build/App.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,247 @@
import React from "./_snowpack/pkg/react.js";
import "./uikit-3.15.9/css/uikit.min.css.proxy.js";
import "./style.css.proxy.js";
import pikachu from "./images/pikachu.jpg.proxy.js";
import vaporeon from "./images/vaporeon.jpg.proxy.js";
class App extends React.Component {
constructor(props) {
super(props);
this.state = {pokemon: []};
this.load();
}
load = () => {
console.log("getting data");
fetch("/data", {
method: "GET",
headers: {
"Content-Type": "application/json"
}
}).then((response) => response.json()).then((json) => {
this.setState({pokemon: json});
console.log(this.state.pokemon);
});
};
render() {
return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("section", {
className: "uk-section-small"
}, /* @__PURE__ */ React.createElement("header", {
className: "uk-flex uk-flex-around"
}, /* @__PURE__ */ React.createElement("img", {
className: "uk-height-small uk-align-left",
src: pikachu,
alt: "Pikachu",
"data-uk-img": true
}), /* @__PURE__ */ React.createElement("h1", {
className: "uk-heading-medium uk-heading-divider"
}, "Create your own Pokemon!"), /* @__PURE__ */ React.createElement("img", {
className: "uk-height-small uk-align-right",
src: vaporeon,
alt: "Vaporeon",
"data-uk-img": true
}))), /* @__PURE__ */ React.createElement("section", {
className: "uk-section-small uk-width-large uk-align-center uk-margin-small"
}, /* @__PURE__ */ React.createElement("h2", {
className: "uk-modal-title"
}, "How to use this application"), /* @__PURE__ */ React.createElement("p", null, "Create a pokemon by submitting the form below"), /* @__PURE__ */ React.createElement("p", null, "Edit a pokemon by submitting the form with the same name as the pokemon you want to edit"), /* @__PURE__ */ React.createElement("p", null, "Delete a pokemon by clicking it in the table below")), /* @__PURE__ */ React.createElement("section", {
className: "uk-width-large uk-align-center uk-margin-small"
}, /* @__PURE__ */ React.createElement(Form, {
load: this.load
})), /* @__PURE__ */ React.createElement("h2", null, "Pokemon List"), /* @__PURE__ */ React.createElement("table", {
id: "table",
className: "uk-table"
}, /* @__PURE__ */ React.createElement("thead", null, /* @__PURE__ */ React.createElement("tr", {
className: "hrow"
}, /* @__PURE__ */ React.createElement("th", null, "Name"), /* @__PURE__ */ React.createElement("th", null, "Description"), /* @__PURE__ */ React.createElement("th", null, "1st Type"), /* @__PURE__ */ React.createElement("th", null, "2nd Type"), /* @__PURE__ */ React.createElement("th", null, "Weaknesses"), /* @__PURE__ */ React.createElement("th", null, "Resistances"), /* @__PURE__ */ React.createElement("th", null, "Immunities"))), /* @__PURE__ */ React.createElement("tbody", null, this.state.pokemon.map((pokemon) => /* @__PURE__ */ React.createElement(Pokemon, {
key: pokemon._id,
name: pokemon.name,
description: pokemon.description,
type1: pokemon.type1,
type2: pokemon.type2,
weaknesses: pokemon.weaknesses,
resistances: pokemon.resistances,
immunities: pokemon.immunities,
load: this.load
})))));
}
}
class Form extends React.Component {
constructor(props) {
super(props);
this.state = {
name: "",
description: "",
type1: "",
type2: "None"
};
this.handleChange = this.handleChange.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
}
handleChange(event) {
const target = event.target;
const value = target.value;
const name = target.name;
this.setState({
[name]: value
});
}
handleSubmit(event) {
event.preventDefault();
console.log(this.state);
fetch("/submit", {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(this.state)
});
this.props.load();
}
render() {
return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("form", {
className: "uk-form-horizontal",
id: "form",
onSubmit: this.handleSubmit
}, /* @__PURE__ */ React.createElement("label", {
className: "uk-form-label",
htmlFor: "name"
}, "What is your Pokemon's name?"), /* @__PURE__ */ React.createElement("section", {
className: "uk-margin uk-form-controls"
}, /* @__PURE__ */ React.createElement("input", {
value: this.state.name,
onChange: this.handleChange,
className: "uk-input",
type: "text",
name: "name",
maxLength: "20",
required: true
})), /* @__PURE__ */ React.createElement("label", {
className: "uk-form-label",
htmlFor: "description"
}, "Describe your Pokemon"), /* @__PURE__ */ React.createElement("section", {
className: "uk-margin uk-form-controls"
}, /* @__PURE__ */ React.createElement("textarea", {
value: this.state.description,
onChange: this.handleChange,
className: "uk-textarea",
name: "description"
})), /* @__PURE__ */ React.createElement("label", {
className: "uk-form-label"
}, "Choose your Pokemon's types"), /* @__PURE__ */ React.createElement("section", {
className: "uk-margin uk-form-controls"
}, /* @__PURE__ */ React.createElement("select", {
value: this.state.type1,
onChange: this.handleChange,
className: "uk-select",
name: "type1",
id: "type1",
required: true
}, /* @__PURE__ */ React.createElement("option", {
value: ""
}, "Choose a type"), /* @__PURE__ */ React.createElement("option", {
value: "Normal"
}, "Normal"), /* @__PURE__ */ React.createElement("option", {
value: "Fighting"
}, "Fighting"), /* @__PURE__ */ React.createElement("option", {
value: "Flying"
}, "Flying"), /* @__PURE__ */ React.createElement("option", {
value: "Poison"
}, "Poison"), /* @__PURE__ */ React.createElement("option", {
value: "Ground"
}, "Ground"), /* @__PURE__ */ React.createElement("option", {
value: "Rock"
}, "Rock"), /* @__PURE__ */ React.createElement("option", {
value: "Bug"
}, "Bug"), /* @__PURE__ */ React.createElement("option", {
value: "Ghost"
}, "Ghost"), /* @__PURE__ */ React.createElement("option", {
value: "Steel"
}, "Steel"), /* @__PURE__ */ React.createElement("option", {
value: "Fire"
}, "Fire"), /* @__PURE__ */ React.createElement("option", {
value: "Water"
}, "Water"), /* @__PURE__ */ React.createElement("option", {
value: "Grass"
}, "Grass"), /* @__PURE__ */ React.createElement("option", {
value: "Electric"
}, "Electric"), /* @__PURE__ */ React.createElement("option", {
value: "Psychic"
}, "Psychic"), /* @__PURE__ */ React.createElement("option", {
value: "Ice"
}, "Ice"), /* @__PURE__ */ React.createElement("option", {
value: "Dragon"
}, "Dragon"), /* @__PURE__ */ React.createElement("option", {
value: "Dark"
}, "Dark"), /* @__PURE__ */ React.createElement("option", {
value: "Fairy"
}, "Fairy")), /* @__PURE__ */ React.createElement("select", {
value: this.state.type2,
onChange: this.handleChange,
className: "uk-select",
name: "type2",
id: "type2"
}, /* @__PURE__ */ React.createElement("option", {
value: "None"
}, "None"), /* @__PURE__ */ React.createElement("option", {
value: "Normal"
}, "Normal"), /* @__PURE__ */ React.createElement("option", {
value: "Fighting"
}, "Fighting"), /* @__PURE__ */ React.createElement("option", {
value: "Flying"
}, "Flying"), /* @__PURE__ */ React.createElement("option", {
value: "Poison"
}, "Poison"), /* @__PURE__ */ React.createElement("option", {
value: "Ground"
}, "Ground"), /* @__PURE__ */ React.createElement("option", {
value: "Rock"
}, "Rock"), /* @__PURE__ */ React.createElement("option", {
value: "Bug"
}, "Bug"), /* @__PURE__ */ React.createElement("option", {
value: "Ghost"
}, "Ghost"), /* @__PURE__ */ React.createElement("option", {
value: "Steel"
}, "Steel"), /* @__PURE__ */ React.createElement("option", {
value: "Fire"
}, "Fire"), /* @__PURE__ */ React.createElement("option", {
value: "Water"
}, "Water"), /* @__PURE__ */ React.createElement("option", {
value: "Grass"
}, "Grass"), /* @__PURE__ */ React.createElement("option", {
value: "Electric"
}, "Electric"), /* @__PURE__ */ React.createElement("option", {
value: "Psychic"
}, "Psychic"), /* @__PURE__ */ React.createElement("option", {
value: "Ice"
}, "Ice"), /* @__PURE__ */ React.createElement("option", {
value: "Dragon"
}, "Dragon"), /* @__PURE__ */ React.createElement("option", {
value: "Dark"
}, "Dark"), /* @__PURE__ */ React.createElement("option", {
value: "Fairy"
}, "Fairy"))), /* @__PURE__ */ React.createElement("input", {
className: "uk-button uk-button-primary uk-align-center",
type: "submit"
})));
}
}
class Pokemon extends React.Component {
constructor(props) {
super(props);
this.handleDelete = this.handleDelete.bind(this);
}
handleDelete() {
fetch("/delete", {
method: "DELETE",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(this.props)
});
this.props.load();
}
render() {
return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("tr", {
onClick: this.handleDelete
}, /* @__PURE__ */ React.createElement("td", null, this.props.name), /* @__PURE__ */ React.createElement("td", null, this.props.description), /* @__PURE__ */ React.createElement("td", null, this.props.type1), /* @__PURE__ */ React.createElement("td", null, this.props.type2), /* @__PURE__ */ React.createElement("td", null, this.props.weaknesses), /* @__PURE__ */ React.createElement("td", null, this.props.resistances), /* @__PURE__ */ React.createElement("td", null, this.props.immunities)));
}
}
export default App;
Loading