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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Scrubbed by Glitch 2022-10-04T02:06:26+0000
33 changes: 4 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,8 @@
Assignment 4 - Components
===

Due: October 4th, by 11:59 AM.

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
README
---

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
## Name-a-Rat

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?
http://a4-charles-snow.glitch.me

Unlike previous assignments, this assignment will be solely graded on whether or not you successfully complete it. Partial credit will be generously given.
I based this project off of a2. It's almost entirely the same, however I changed it to only use a rat name, as I thought that it improved the application. I think react is a useful tool, however on an app with this small of a scale I felt that setting up react takes significantly more work than not using it, and it hindered the development experience.
22 changes: 22 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "a4-csnow99",
"version": "1.0.0",
"description": "",
"main": "index.js",
"keywords": [],
"author": "",
"license": "ISC",
"scripts": {
"clean": "rm dist/bundle.js",
"start": "node server.js",
"build": "snowpack build"
},
"dependencies": {
"express": "^4.18.1",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"snowpack": "^3.8.8"
}
}
25 changes: 25 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const express = require( 'express' ),
app = express()

const names = []

app.use( express.json() )

// this will most likely be 'build' or 'public'
app.use( express.static( 'build' ) )

app.get( '/read', ( req, res ) => res.json( names ) )

app.post( '/add', ( req,res ) => {
names.push( req.body )
res.json( names )
})

app.post( '/change', function( req,res ) {
const idx = names.findIndex( v => v.name === req.body.name )
names[ idx ].completed = req.body.completed

res.sendStatus( 200 )
})

app.listen( 8080 )
6 changes: 6 additions & 0 deletions snowpack.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"mount": {
"dist": "/",
"src": "/"
}
}
88 changes: 88 additions & 0 deletions src/App.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import React from "react";



class Name extends React.Component {
// our .render() method creates a block of HTML using the .jsx format

render() {
const name = this.props.name
if(document.getElementById("ratname").value != ""){
const rats = document.getElementById("youname");
const adjes = ["funky", "furry", "spunky", "based", "wiggly", "rabid", "feral", "amphibious", "moist", "scrungy", "filthy", "bronchiatic", "clueless", "ditsy", "arthritic", "useless", "cute", "decorative", "assiduous", "gothic", "postmodern", "fully automatic", "scared", "skittish", "large", "tiny", "strategic", "colorblind", "gaslighting", "gatekeeping", "cringe", "sus", "rancid", "bedazzled", "confused", "sticky", "litigious", "stinky", "nutty"]
let adje = adjes[Math.floor(Math.random()*adjes.length)];
const nouns = ["fella", "friend", "pisser", "chef", "Charlie", "girlboss", "Bagungus", "ambassador", "microwave", "nurse", "spy", "loaf", "entertainer", "swifty", "garfhead", "furry", "guy", "professor", "hatrat", "mayor", "problem", "barrister", "mobster", "monster", "child", "Delta SkyPriority Gold Member", "Delta SkyPriority Silver Member", "credit card fraudster", "sinner", "snitch", "plumber", "rhat", "rat", "landlord", "vegetarian", "carnivore", "murderer", "true crime podcaster", "historian", "bandit", "smuggler", "morb", "amongus", "barista", "whippersnapper", "motivational speaker/juggler", "DJ", "game show host", "CS major", "singer", "puddle"]
let noun = nouns[Math.floor(Math.random() * nouns.length)];
let html =
`
<h1>You named this ` +
adje +
` little ` +
noun +
` <span style="color:red">` +
name +
`</span></h1>`;

rats.innerHTML = html
}

return <li>{name}</li>
}
}




// main component
class App extends React.Component {
constructor( props ) {
super( props )
// initialize our state
this.state = { names:[] }
this.load()
}

// load in our data from the server
load() {
fetch( '/read', { method:'get', 'no-cors':true })
.then( response => response.json() )
.then( json => {
this.setState({ names:json })
})
}

// render component HTML using JSX
render() {
return (
<div>
<h1> Name this rat!</h1>
<img src="https://cdn.glitch.global/52f17feb-e16b-457c-8290-455b85efab01/download.png?v=1664850939115" />
<br />
<input type="text" id="ratname" placeholder="Rat name here" />
<button onClick={ e => this.add( e )} id="button">Submit</button>
<h2 id="youname"></h2>
<p>Here's what other people named this rat:</p>
<ul>
{ this.state.names.map( (name,i) => <Name key={i} name={name.name} /> ) }
</ul>
</div>
);
}

add( evt ) {
const value = document.querySelector('input').value

fetch( '/add', {
method:'POST',
body: JSON.stringify({ name:value, completed:false }),
headers: { 'Content-Type': 'application/json' }
})
.then( response => response.json() )
.then( json => {
// changing state triggers reactive behaviors
this.setState({ names:json })
})
}
}

export default App;
28 changes: 28 additions & 0 deletions src/css/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
body {
font-family: 'Roboto', sans-serif;
}

img {
width: 25%;
height: auto;
}

.hiddenFrame{
height:1px;
width:1px;
opacity: 0;
}
.rats {
display: flex;
flex-direction: column;
row-gap: 0px;
}
.data:hover {
text-decoration: line-through;
}

p {
margin: 4px;
padding: 0;
}
/*Style your own assignment! This is fun! */
15 changes: 15 additions & 0 deletions src/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html>
<head>
<link
rel="stylesheet"
href="./css/style.css"
/>
<title>Name-a-Rat</title>
<meta charset="utf-8" />
</head>
<body>
<div id="app"></div>
<script type="module" src="index.js"></script>
</body>
</html>
6 changes: 6 additions & 0 deletions src/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import React from "react";
import ReactDOM from "react-dom";
import App from "./App";

var mountNode = document.getElementById("app");
ReactDOM.render(<App name="Jane" />, mountNode);
Empty file added src/js/scripts.js
Empty file.