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

a4-jake-olsen #38

Open
wants to merge 2 commits into
base: main
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
134 changes: 134 additions & 0 deletions App.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
import React from 'react';

// main component
class App extends React.Component {
constructor(props) {
super(props);
// Initialize state
this.state = {
todos: [],
task: '',
priority: '',
deleteTask: ''
};
}

//Way to load data
componentDidMount() {
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({ todos: json });
});
}

render() {
return (
<div className="App">
<h1>To-Do List</h1>
<table id="tasksTable" border="1" style={{ marginTop: '20px', borderCollapse: 'collapse', width: '80%' }}>
<thead>
<tr>
<th>Task</th>
<th>Priority</th>
<th>Created At</th>
<th>Deadline</th>
</tr>
</thead>
<tbody>
{this.state.todos.map((todo, i) => (
<tr key={i}>
<td>{todo.task}</td>
<td>{todo.priority}</td>
<td>{new Date(todo.created_at).toLocaleString()}</td>
<td>{todo.deadline}</td>
</tr>
))}
</tbody>
</table>

<h2>Add New Task</h2>
<form onSubmit={(e) => this.addTask(e)} id="addTaskForm">
<input
type="text"
value={this.state.task}
onChange={(e) => this.setState({ task: e.target.value })}
placeholder="Task Description"
required
/>
<input
type="number"
value={this.state.priority}
onChange={(e) => this.setState({ priority: e.target.value })}
placeholder="Priority (1-3)"
min="1"
max="3"
required
/>
<button type="submit">Add Task</button>
</form>

<h2>Delete Task</h2>
<form onSubmit={(e) => this.deleteTask(e)} id="deleteTaskForm">
<input
type="text"
value={this.state.deleteTask}
onChange={(e) => this.setState({ deleteTask: e.target.value })}
placeholder="Task Description to Delete"
required
/>
<button type="submit">Delete Task</button>
</form>
</div>
);
}


addTask(evt) {
evt.preventDefault();
const { task, priority } = this.state;

const newTask = {
task,
priority,
completed: false,
created_at: new Date().toISOString().split('T')[0], //Set the current date
};

fetch('/add', {
method: 'POST',
body: JSON.stringify(newTask),
headers: { 'Content-Type': 'application/json' },
})
.then(response => response.json())
.then(json => {
this.setState({ todos: json, task: '', priority: '' });
});
}


deleteTask(evt) {
evt.preventDefault();
const { deleteTask } = this.state;

fetch('/delete', {
method: 'POST',
body: JSON.stringify({ task: deleteTask }),
headers: { 'Content-Type': 'application/json' },
})
.then(response => response.json())
.then(json => {
this.setState({
todos: json,
deleteTask: ''
});
});
}
}

export default App;
32 changes: 4 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,9 @@
Assignment 4 - Components
===

Due: September 30th, by 11:59 AM.
## To-DO List

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.
Jake Olsen: https://a4-jake-olsen.glitch.me/

[Svelte Tutorial](https://github.com/cs-4241-2024/cs-4241-2024.github.io/blob/main/using.svelte.md)
[React Tutorial](https://github.com/cs-4241-2024/cs-4241-2024.github.io/blob/main/using.react.md)
From assignment 3 I kept most things the same. The big changes were just integrating with React and Vite-Express which was all done within the code itself and not the UI. Within the UI I made the table smaller but still overall the same functionality. When it came to integrating with React, that was rather difficult for me but after watching many tutorials and reading about React it made it much simplier to integrate what I already had into a react format. I think I just found a lot of difficulty when it came to the login screen and also the to do list screen while also using the vite-express and react back end. I did try to implement the login without react but found it more confusing to try and use two different backends. I defintly could have been taking the wrong approach, but I am stil satisfied with what I have now and will do more research when it comes to the final project.

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.
I did discover and use the componentDidMount functionality within react vs useEffect purely because I thought the syntax was more straightforward and their functionality seemed similar enough to interchange the two. Again a reason that was purely for my ability to read my code a little easier. componentDidMount also seemed to be much more simple to use when dealing with simple data such as a to do list.
13 changes: 13 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>To-Do List</title>
<link rel="stylesheet" href="/main.css">
</head>
<body>
<div id="root"></div>
<script type="module" src="/index.jsx"></script>
</body>
</html>
10 changes: 10 additions & 0 deletions index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from 'react'
import ReactDOM from 'react-dom/client'
import App from './App.jsx'
import './main.css'

ReactDOM.createRoot( document.getElementById( 'root' ) ).render(
<React.StrictMode>
<App />
</React.StrictMode>,
)
76 changes: 76 additions & 0 deletions main.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
body {
font-family: 'Arial', sans-serif;
background-color: rgb(237, 235, 189);
margin: 20;
padding: 10;
display: flex;
flex-direction: column;
align-items: center;
height: 100vh;
}

/* Heading */
h1 {
color: #444;
margin-bottom: 20px;
}

/* Task table styling */
table {
width: 100%;
border-collapse: collapse;
border: 1;
margin-bottom: 20px;
}

thead th {
background-color: rgb(70, 65, 45);
color: white;
padding: 10px;
}

tbody tr {
background-color: #f9f9f9;
border-bottom: 1px solid #ddd;
}

tbody tr:nth-child(even) {
background-color: #f1f1f1;
}

tbody td {
padding: 10px;
text-align: center;
}

/* Form input styling */
form input[type="text"],
form input[type="number"] {
padding: 10px;
width: 100%;
margin: 10px 0;
border: 1px solid #ddd;
border-radius: 5px;
box-sizing: border-box;
}

button {
background-color: rgb(70, 65, 45);
color: white;
border: none;
padding: 10px 20px;
border-radius: 5px;
cursor: pointer;
width: 100%;
margin-top: 10px;
}

button:hover {
background-color: rgb(39, 37, 26);
}

/* Form headings */
h2 {
margin-top: 30px;
color: #555;
}
16 changes: 16 additions & 0 deletions node_modules/.bin/esbuild

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

17 changes: 17 additions & 0 deletions node_modules/.bin/esbuild.cmd

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

28 changes: 28 additions & 0 deletions node_modules/.bin/esbuild.ps1

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

16 changes: 16 additions & 0 deletions node_modules/.bin/loose-envify

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

17 changes: 17 additions & 0 deletions node_modules/.bin/loose-envify.cmd

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

Loading