Skip to content

Commit

Permalink
Merge pull request #2259 from viv2005ek/main
Browse files Browse the repository at this point in the history
task planner
  • Loading branch information
iamrahulmahato authored Nov 8, 2024
2 parents bd8f2b7 + fcba509 commit 8cc3126
Show file tree
Hide file tree
Showing 3 changed files with 199 additions and 0 deletions.
35 changes: 35 additions & 0 deletions Task Planner/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Task Planner</title>
<link rel="stylesheet" href="style.css">
</head>

<body>
<div id="app">
<h1>Task Planner</h1>
<form id="task-form">
<label for="task-title">Task Title</label>
<input type="text" id="task-title" placeholder="Enter your task title" required>

<label for="task-desc">Description</label>
<textarea id="task-desc" placeholder="Task description (optional)"></textarea>

<label for="task-date">Due Date</label>
<input type="date" id="task-date" required>

<label for="task-time">Alarm Time</label>
<input type="time" id="task-time" placeholder="Set alarm time (optional)">

<button type="submit">Add Task</button>
</form>

<div id="task-list"></div>
</div>
<script src="script.js"></script>
</body>

</html>
78 changes: 78 additions & 0 deletions Task Planner/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
document.addEventListener("DOMContentLoaded", () => {
const form = document.getElementById("task-form");
const taskList = document.getElementById("task-list");
let editMode = false;
let editId = null;

function loadTasks() {
const tasks = JSON.parse(localStorage.getItem("tasks")) || [];
taskList.innerHTML = "";
tasks.forEach((task) => displayTask(task));
}

function saveAllTasks(tasks) {
localStorage.setItem("tasks", JSON.stringify(tasks));
}

function saveTask(task) {
const tasks = JSON.parse(localStorage.getItem("tasks")) || [];
if (editMode) {
const index = tasks.findIndex((t) => t.id === editId);
if (index !== -1) {
tasks[index] = task;
}
editMode = false;
editId = null;
} else {
tasks.push(task);
}
saveAllTasks(tasks);
}

function displayTask(task) {
const taskItem = document.createElement("div");
taskItem.className = "task";
taskItem.innerHTML = `
<h3>${task.title}</h3>
<p>${task.description}</p>
<p>Due: ${task.date}</p>
<button onclick="editTask('${task.id}')">Edit</button>
<button onclick="deleteTask('${task.id}')">Delete</button>
`;
taskList.appendChild(taskItem);
}

window.editTask = function (id) {
const tasks = JSON.parse(localStorage.getItem("tasks")) || [];
const task = tasks.find((t) => t.id === id);
if (task) {
document.getElementById("task-title").value = task.title;
document.getElementById("task-desc").value = task.description;
document.getElementById("task-date").value = task.date;
editMode = true;
editId = id;
}
};

window.deleteTask = function (id) {
const tasks = JSON.parse(localStorage.getItem("tasks")) || [];
const updatedTasks = tasks.filter((task) => task.id !== id);
saveAllTasks(updatedTasks);
loadTasks();
};

form.addEventListener("submit", (e) => {
e.preventDefault();
const task = {
id: editMode ? editId : Date.now().toString(),
title: document.getElementById("task-title").value,
description: document.getElementById("task-desc").value,
date: document.getElementById("task-date").value,
};
saveTask(task);
loadTasks();
form.reset();
});

loadTasks();
});
86 changes: 86 additions & 0 deletions Task Planner/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}

body {
font-family: Arial, sans-serif;
background: linear-gradient(135deg, teal 0%, #367588 100%);
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
}

#app {
background-color: #fff;
border-radius: 8px;
box-shadow: 0px 4px 20px rgba(0, 0, 0, 0.2);
width: 100%;
max-width: 500px;
padding: 20px;
}

form {
display: flex;
flex-direction: column;
}

form label {
font-weight: bold;
margin: 8px 0 4px;
}

form input, form textarea, form button {
padding: 10px;
border: 1px solid #ddd;
border-radius: 5px;
margin-bottom: 15px;
}

form button {
background-color: #ff7f50;
color: #fff;
font-weight: bold;
cursor: pointer;
transition: background-color 0.3s;
}

form button:hover {
background-color: #ff6347;
}

.task {
background: #f5f5f5;
border-left: 5px solid #ff7f50;
margin: 10px 0;
padding: 15px;
border-radius: 5px;
}

.task h3 {
color: #333;
margin-bottom: 5px;
}

.task button {
background: transparent;
border: none;
cursor: pointer;
color: #ff6347;
font-weight: bold;
margin-left: 5px;
transition: color 0.3s;
}

.task button:hover {
color: #ff4500;
}

@media (max-width: 600px) {
#app {
padding: 15px;
}
}

0 comments on commit 8cc3126

Please sign in to comment.