-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
95 lines (68 loc) · 2.18 KB
/
Copy pathindex.js
File metadata and controls
95 lines (68 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import express from "express";
import bodyParser from "body-parser";
import os from "os";
const app = express()
const port = 3000;
app.use(bodyParser.urlencoded({ extended: true }))
app.use(express.static("public"))
const weekday = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
const d = new Date();
let day = weekday[d.getDay()];
let newitemlist = [];
let wnewitemlist = [];
let newitems;
let newitem;
let wnewitems;
let wnewitem;
let Path;
app.get("/", (req, res) => {
Path = req.path;
res.render("index.ejs", {
Dayname: day,
newitems: newitemlist
})
})
app.get("/work", (req, res) => {
Path = req.path;
res.render("work.ejs", {
wnewitems: wnewitemlist
})
})
app.post("/submit", (req, res) => {
const userInput = req.body.userInput;
if (Path === "/") {
// If the path is "/", do something.
newitemlist.push(userInput);
res.redirect("/");
} else if (Path === "/work") {
// If the path is "/work", do something else.
wnewitemlist.push(userInput);
res.redirect("/work");
} else {
// Handle other cases if needed.
res.status(404).send("Not Found");
}
});
app.post("/delete", (req, res) => {
if (Path === "/") {
const completedTasks = req.body.completedTasks; // Assuming your form sends an array of completed tasks
if (completedTasks) {
// Filter out the completed tasks from your newitemlist
newitemlist = newitemlist.filter(item => !completedTasks.includes(item));
// newitemlist = newitemlist.style.color = "red";
}
res.redirect("/");
}
if (Path === "/work") {
const completedTasks = req.body.completedTasks; // Assuming your form sends an array of completed tasks
if (completedTasks) {
// Filter out the completed tasks from your newitemlist
wnewitemlist = wnewitemlist.filter(item => !completedTasks.includes(item));
}
res.redirect("/work");
}
})
app.listen(port, function (err) {
if (err) console.log("Error in server setup")
console.log(`server is running on the port ${port}`);
})