-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
164 lines (146 loc) · 4.47 KB
/
index.html
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
<!DOCTYPE html>
<html>
<head>
<style>
.node {
position: relative;
padding: 10px;
border: 1px solid #000;
border-radius: 10px;
margin: 10px;
cursor: pointer;
display: flex;
flex-direction: column;
align-items: flex-start;
}
.node button {
padding: 5px;
margin: 5px;
background-color: #009900;
color: #ffffff;
border: none;
border-radius: 5px;
cursor: pointer;
font-weight: bold;
font-size: 12px;
width: 25px;
height: 25px;
display: flex;
justify-content: center;
align-items: center;
}
.note-title {
white-space: pre-wrap;
overflow: hidden;
text-overflow: ellipsis;
display: flex;
align-items: center;
}
.note-title span {
font-weight: bold;
margin-right: 10px;
}
.note-content {
border: 1px solid #000;
border-radius: 5px;
padding: 5px;
width: auto;
min-width: 100px;
}
.children {
display: flex;
flex-direction: column;
align-items: flex-start;
margin-top: 10px;
margin-left: 30px;
}
#controls {
position: fixed;
bottom: 0;
width: 100%;
display: flex;
justify-content: center;
padding: 10px;
background: #ccc;
}
.button-container {
display: flex;
align-items: center;
margin-left: -5px; /* Adjust the value to move the buttons to the left */
}
.button-container button {
background-color: #009900;
color: #ffffff;
border: none;
border-radius: 5px;
cursor: pointer;
font-weight: bold;
padding: 5px 10px;
margin-right: 5px;
}
</style>
</head>
<body>
<div id="root"></div>
<div id="controls">
<button onclick="createRootNoteBlock()">Add Root Note</button>
</div>
<script src="https://www.gstatic.com/firebasejs/9.0.0/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/9.0.0/firebase-firestore.js"></script>
<script>
const firebaseConfig = {
apiKey: "AIzaSyDvXCkb2zol2OAkJh5XRgMWCqXZNpuxf8A",
authDomain: "note-app-bc1c8.firebaseapp.com",
projectId: "note-app-bc1c8",
storageBucket: "note-app-bc1c8.appspot.com",
messagingSenderId: "137319797999",
appId: "1:137319797999:web:7466ab88111aae1a2cb71a",
measurementId: "G-CJSPMCTWJT"
};
firebase.initializeApp(firebaseConfig);
const db = firebase.firestore();
async function loadNotes() {
const snapshot = await db.collection("notes").get();
snapshot.forEach((doc) => {
const noteData = doc.data();
createNoteBlock(noteData.title, noteData.content, document.getElementById("root"), doc.id);
});
}
async function createRootNoteBlock() {
const noteTitle = prompt("Enter your note title:");
const noteContent = prompt("Enter your note content:");
const docRef = await db.collection("notes").add({
title: noteTitle || "New note",
content: noteContent || "",
});
createNoteBlock(noteTitle || "New note", noteContent || "", document.getElementById("root"), docRef.id);
}
function createNoteBlock(noteTitle, noteContent, parentElement, id) {
const noteBlock = document.createElement("div");
noteBlock.id = id;
noteBlock.classList.add("node");
noteBlock.innerHTML = `
<div class="button-container">
<button onclick="event.stopPropagation(); createRootNoteBlock();">+</button>
<button onclick="event.stopPropagation(); deleteNoteBlock('${id}');">x</button>
</div>
<div class="note-title" contenteditable="true" onkeydown="handleTitleKeydown(event)" onpaste="handleTitlePaste(event)" onblur="updateTitle('${id}', this.textContent)"><span>${noteTitle}</span></div>
<div class="note-content" contenteditable="true" onblur="updateContent('${id}', this.textContent)">${noteContent}</div>
<div class="children"></div>
`;
parentElement.appendChild(noteBlock);
}
async function deleteNoteBlock(id) {
await db.collection("notes").doc(id).delete();
document.getElementById(id).remove();
}
async function updateTitle(id, newTitle) {
await db.collection("notes").doc(id).update({title: newTitle});
}
async function updateContent(id, newContent) {
await db.collection("notes").doc(id).update({content: newContent});
}
loadNotes();
</script>
</body>
</html>