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-sophia-kalavantis #32

Open
wants to merge 1 commit 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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 8 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,12 @@
Assignment 4 - Components
===
## Assignment 4: To Do List with Priorities

Due: September 30th, by 11:59 AM.
http://a4-sophia-kalavantis.glitch.me

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.
For this project, I re-implemented my to-do list app from A2 using React components.
The main changes that I did were just breaking the original functionality into React components: App.js, TaskForm.js, TaskList.js, and Task.js.
Instead of manipulating the DOM like I did with the original main.js, React does all that work through the components, and the form elements are now inside TaskForm.js.
The index.html just has a simple div for React to render, and all DOM stuff is done by React now.

[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)
React gives a more structured way of organizing code but it hindered my development experience overall. The CSS that originally worked perfectly with HTML and JavaScript didn’t apply as well to the new components.
Also, more files are now in my codebase to essentially do the same tasks that I had before, which made the code more complex without really improving functionality.

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.
2,692 changes: 2,692 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

27 changes: 27 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "to-do-list",
"version": "1.0.0",
"description": "Simple to-do list app",
"main": "server.js",
"author": "Sophia Kalavantis",
"scripts": {
"start": "node server.js",
"build": "webpack"
},
"dependencies": {
"mime": "2.5.2",
"react": "^18.0.0",
"react-dom": "^18.0.0"
},
"devDependencies": {
"webpack": "^5.0.0",
"webpack-cli": "^4.0.0",
"babel-loader": "^8.0.0",
"@babel/core": "^7.0.0",
"@babel/preset-env": "^7.0.0",
"@babel/preset-react": "^7.0.0"
},
"engines": {
"node": ">=10.24.1"
}
}
40 changes: 40 additions & 0 deletions public/App.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import React, { useState, useEffect } from "react";
import TaskForm from "./TaskForm";
import TaskList from "./TaskList";

const App = () => {
const [tasks, setTasks] = useState([]);

useEffect(() => {
fetch("/tasks")
.then((response) => response.json())
.then((data) => setTasks(data));
}, []);

const addTask = (task) => {
fetch("/add", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(task),
})
.then((response) => response.json())
.then((newTask) => setTasks([...tasks, newTask]));
};

const clearTasks = () => {
fetch("/clear", { method: "POST" }).then(() => setTasks([]));
};

return (
<div className="app-container">
<h1>To-Do List</h1>
<TaskForm addTask={addTask} />
<TaskList tasks={tasks} />
<button onClick={clearTasks} className="clear-list">
Clear All Tasks
</button>
</div>
);
};

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

const Task = ({ task }) => {
return (
<div className="task-card">
<h3 className="task-title">{task.task}</h3>
<span className={`priority ${task.priority}`}>
{task.priority.charAt(0).toUpperCase() + task.priority.slice(1)}
</span>
<div className="dates">
<strong>Created At:</strong> {new Date(task.created_at).toLocaleString()}
<br />
<strong>Deadline:</strong> {new Date(task.deadline).toLocaleString()}
</div>
</div>
);
};

export default Task;
37 changes: 37 additions & 0 deletions public/TaskForm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import React, { useState } from "react";

const TaskForm = ({ addTask }) => {
const [taskText, setTaskText] = useState("");
const [priority, setPriority] = useState("low");

const handleSubmit = (e) => {
e.preventDefault();
if (taskText.trim()) {
addTask({
task: taskText,
priority: priority,
});
setTaskText("");
}
};

return (
<form onSubmit={handleSubmit}>
<input
type="text"
value={taskText}
onChange={(e) => setTaskText(e.target.value)}
placeholder="Enter a task"
required
/>
<select value={priority} onChange={(e) => setPriority(e.target.value)}>
<option value="low">Low</option>
<option value="medium">Medium</option>
<option value="high">High</option>
</select>
<button type="submit">Add Task</button>
</form>
);
};

export default TaskForm;
14 changes: 14 additions & 0 deletions public/TaskList.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React from "react";
import Task from "./Task";

const TaskList = ({ tasks }) => {
return (
<div>
{tasks.map((task, index) => (
<Task key={index} task={task} />
))}
</div>
);
};

export default TaskList;
Loading