Skip to content

Commit 4ac33ec

Browse files
fpligermadhur-tandon
authored andcommitted
add todo app
1 parent cad5f86 commit 4ac33ec

File tree

6 files changed

+182
-0
lines changed

6 files changed

+182
-0
lines changed

todo/assets/css/examples.css

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
body {
2+
margin: 0;
3+
}
4+
5+
.pyscript {
6+
margin: 0.5rem;
7+
}
8+
9+
html {
10+
font-family:
11+
ui-sans-serif,
12+
system-ui,
13+
-apple-system,
14+
BlinkMacSystemFont,
15+
"Segoe UI",
16+
Roboto,
17+
"Helvetica Neue",
18+
Arial,
19+
"Noto Sans",
20+
sans-serif,
21+
"Apple Color Emoji",
22+
"Segoe UI Emoji",
23+
"Segoe UI Symbol",
24+
"Noto Color Emoji";
25+
line-height: 1.5;
26+
}
27+
28+
nav {
29+
position: sticky;
30+
width: 100%;
31+
top: 0;
32+
left: 0;
33+
z-index: 9999;
34+
}
35+
36+
.logo {
37+
padding-right: 10px;
38+
font-size: 28px;
39+
height: 30px;
40+
max-width: inherit;
41+
}
42+
43+
.title {
44+
text-decoration: none;
45+
text-decoration-line: none;
46+
text-decoration-style: initial;
47+
text-decoration-color: initial;
48+
font-weight: 400;
49+
font-size: 1.5em;
50+
line-height: 2em;
51+
white-space: nowrap;
52+
}
53+
54+
.app-header {
55+
display: flex;
56+
align-items: center;
57+
padding: 0.5rem 1rem;
58+
}

todo/assets/favicon.png

4.19 KB
Loading

todo/assets/logo.png

7.27 KB
Loading

todo/index.html

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<!doctype html>
2+
3+
<html>
4+
<head>
5+
<!-- Recommended meta tags -->
6+
<meta charset="UTF-8">
7+
<meta name="viewport" content="width=device-width,initial-scale=1.0">
8+
9+
<!-- PyScript CSS -->
10+
<link rel="stylesheet" href="https://pyscript.net/releases/2023.11.2/core.css">
11+
<!-- CSS for examples -->
12+
<link rel="stylesheet" href="./assets/css/examples.css" />
13+
14+
<!-- This script tag bootstraps PyScript -->
15+
<script type="module" src="https://pyscript.net/releases/2023.11.2/core.js"></script>
16+
17+
<title>Todo App</title>
18+
<link rel="icon" type="image/png" href="./assets/favicon.png" />
19+
20+
<style>
21+
.line-through {
22+
text-decoration: line-through;
23+
}
24+
</style>
25+
</head>
26+
27+
<body>
28+
<nav class="navbar" style="background-color: #000000">
29+
<div class="app-header">
30+
<a href="/">
31+
<img src="./assets/logo.png" class="logo" />
32+
</a>
33+
<a class="title" href="" style="color: #f0ab3c">Simple Clock</a>
34+
</div>
35+
</nav>
36+
37+
38+
<section class="pyscript">
39+
<main>
40+
<section>
41+
<div>
42+
<h1> To Do List </h1>
43+
</div>
44+
<div>
45+
<input id="new-task-content" type="text" />
46+
<button id="new-task-btn" type="submit" py-click="add_task">
47+
Add task
48+
</button>
49+
</div>
50+
51+
<py-list id="myList"></py-list>
52+
<div id="list-tasks-container"></div>
53+
54+
<template id="task-template">
55+
<section class="task py-li-element">
56+
<label for="flex items-center p-2 ">
57+
<input style="vertical-align: middle;" type="checkbox" />
58+
<p style="display: inline;"></p>
59+
</label>
60+
</section>
61+
</template>
62+
</section>
63+
</main>
64+
<script type="py" src="./main.py" async></script>
65+
</section>
66+
</body>
67+
</html>

todo/main.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
from datetime import datetime as dt
2+
3+
from pyscript import document
4+
5+
tasks = []
6+
7+
8+
def q(selector, root=document):
9+
return root.querySelector(selector)
10+
11+
12+
# define the task template that will be use to render new templates to the page
13+
task_template = q("#task-template").content.querySelector(".task")
14+
task_list = q("#list-tasks-container")
15+
new_task_content = q("#new-task-content")
16+
17+
18+
def add_task(e):
19+
# ignore empty task
20+
if not new_task_content.value:
21+
return None
22+
23+
# create task
24+
task_id = f"task-{len(tasks)}"
25+
task = {
26+
"id": task_id,
27+
"content": new_task_content.value,
28+
"done": False,
29+
"created_at": dt.now(),
30+
}
31+
32+
tasks.append(task)
33+
34+
# add the task element to the page as new node in the list by cloning from a
35+
# template
36+
task_html = task_template.cloneNode(True)
37+
task_html.id = task_id
38+
task_html_check = q("input", root=task_html)
39+
task_html_content = q("p", root=task_html)
40+
task_html_content.textContent = task["content"]
41+
task_list.append(task_html)
42+
43+
def check_task(evt=None):
44+
task["done"] = not task["done"]
45+
task_html_content.classList.toggle("line-through", task["done"])
46+
47+
new_task_content.value = ""
48+
task_html_check.onclick = check_task
49+
50+
51+
def add_task_event(e):
52+
if e.key == "Enter":
53+
add_task(e)
54+
55+
56+
new_task_content.onkeypress = add_task_event

todo/pyscript.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
name = "Todo App"

0 commit comments

Comments
 (0)