-
Notifications
You must be signed in to change notification settings - Fork 413
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2259 from viv2005ek/main
task planner
- Loading branch information
Showing
3 changed files
with
199 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
|