-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnotes.html
214 lines (211 loc) · 9.79 KB
/
notes.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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport"
content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<meta name="format-detection" content="telephone=no" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="MobileOptimized" content="176" />
<meta name="HandheldFriendly" content="True" />
<meta name="robots" content="noindex,nofollow" />
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"
integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous">
</script>
<title>
</title>
<script src="https://telegram.org/js/telegram-web-app.js?1">
</script>
<script src="js/index.js"></script>
<script>
const botArray = getQueryVariable('botId').split("/");
function deleteNotes(id) {
var retVal = confirm("Do you want to delete?");
if (retVal) {
var myHeaders = new Headers();
myHeaders.append("Content-Type", "application/json");
var raw = JSON.stringify({
id
}
);
var requestOptions = {
method: 'POST',
headers: myHeaders,
body: raw,
redirect: 'follow'
};
fetch(baseUrl + "/api/bot/removeNote", requestOptions)
.then(response => response.text())
.then(result => checkUserData())
.catch(error => console.log('error', error));
}
// prompt("Edit your note", "Hello world");
}
function checkUserData() {
fetch(checkUser, {
method: "post",
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
}
,
body: JSON.stringify({
"bot_id": botArray[0],
"host_chat_id": botArray[1],
"receiver_chat_id": botArray[2],
"username": initDataUnsafe?.user?.username
}
)
}
).then((response) => {
return response.json();
}
)
.then(res => {
document.getElementById("saveLink").classList.remove("disabled")
document.getElementById("meetingLink").value = ""
// document.querySelector('#locationData').innerHTML = JSON.stringify(res)
console.log(res?.notesAndReminder?.filter(d => d.type === "note")?.map(d => d.text))
const notes = res?.notesAndReminder?.filter(d => d.type === "note");
let innerData = ""
if (notes?.length) {
notes.forEach(d => {
innerData += `<li class="list-group-item">${d?.text}
<div class="text-right" style="text-align:right"><button type="button" onclick="editNotes(\'${d?.text}\',${d.id})" class="btn btn-info ">Edit</button><button type="button" style="background: #FF6D28 !important;border-color: #FF6D28; outline: 0; margin-left:15px" onClick="deleteNotes(${d.id})" class="btn btn-danger">Delete</button></div ></li>`.trim()
})
}
document.querySelector('#notesList').innerHTML = innerData
// alert(res.data)
if (!res?.data) {
document.getElementById("premiumDiv").style.display = '';
// window.location = "https://gajendrawits.github.io/telegram-frontend/premium.html"
return
}
document.getElementById("mainContainer").classList.add("d-flex")
// if (res?.meetingDetails?.intro_text) {
// document.getElementById("displayMeeting").style.display = '';
// document.querySelector('#displayMeetingText').value = res?.meetingDetails?.intro_text
// document.querySelector('#locationData').innerHTML = res?.meetingDetails?.meeting_link
// } else {
// document.getElementById("addMeetingWrapper").style.display = '';
// }
})
}
function editNotes(note, id) {
console.log(note)
// var retVal = confirm("Do you want to delete?");
var value = prompt("Edit your note", note);
if (value !== note) {
var myHeaders = new Headers();
myHeaders.append("Content-Type", "application/json");
var raw = JSON.stringify({
id,
"text": value
});
var requestOptions = {
method: 'POST',
headers: myHeaders,
body: raw,
redirect: 'follow'
};
fetch(baseUrl + "/api/bot/editNote", requestOptions)
.then(response => response.text())
.then(result => checkUserData())
.catch(error => console.log('error', error));
}
}
function signUp() {
window.location = baseUrl + "/"
}
async function saveLink() {
document.getElementById("saveLink").className += " " + "disabled";
const meetingLink = document.getElementById("meetingLink").value
if (!meetingLink) {
alert("Please add note text")
document.getElementById("saveLink").classList.remove("disabled")
return false
}
const res = await fetch(baseUrl + "/api/bot/addNotesReminder", {
method: "post",
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
//make sure to serialize your JSON body
body: JSON.stringify({
"bot_id": botArray[0],
"host_chat_id": botArray[1],
"receiver_chat_id": botArray[2],
"type": "note",
"text": meetingLink,
"count_down": 0
})
})
if (res.status === 200) {
checkUserData()
}
}
</script>
</head>
<body>
<img style="width: 20px; height: 20px; margin: 10px 5px;" src="./exit.png" alt="back" onclick="webviewClose()">
<section class="justify-content-center" style="height: 100vh; width:100%">
<div class="mb-3 px-2 flex-column mt-3" style="width:100%;display:none;" id="mainContainer">
<div class="text-center">
<img style="height: 40px; width: 40px;" src="./chapterx.png" alt="ChapterX">
</div>
<label for="text" class="form-label my-2">Write you note here ?
</label>
<textarea name="text" rows="3" class="form-control" id="meetingLink" placeholder="Eg. Tomorrow is holiday.">
</textarea>
<button id="saveLink" class="btn btn-success my-4"
style="background: #FF6D28 !important; width: 100%; border-color: #FF6D28; outline: 0;" ` type="submit"
onClick="saveLink()">Save Note
</button>
<ul class="list-group" id="notesList">
<li class="list-group-item">Cras justo odio
<div class="text-right" style="text-align:right">
<button type="button" class="btn btn-info">Edit
</button>
<button type="button" class="btn btn-danger">Delete
</button>
</div>
</li>
<li class="list-group-item">Dapibus ac facilisis in
</li>
<li class="list-group-item">Morbi leo risus
</li>
<li class="list-group-item">Porta ac consectetur ac
</li>
<li class="list-group-item">Vestibulum at eros
</li>
</ul>
</div>
<div id="premiumDiv" style="display: none;">
<!-- <img style="width: 20px; height: 20px; margin: 10px 5px;" src="./exit.png" alt="back" onclick="webviewClose()"> -->
<section class="d-flex justify-content-center text-center" style="height: 100vh; width:100%">
<div class="mb-3 px-2 d-flex flex-column mt-3" style="width:100%">
<div class="text-center">
<img style="height: 40px; width: 40px;" src="./chapterx.png" alt="ChapterX">
</div>
<p class="mt-2">Sign-up for an account to unlock premium 💎 features!
</p>
<button type="submit" class="btn btn-lg text-white my-4 " id="saveLink"
style="background: #FF6D28 !important; width: 100%; border-color: #FF6D28; outline: 0;"
type="submit" onClick="signUp()">Sign Up
</button>
</div>
</section>
</div>
</section>
</body>
<script>
Telegram.WebApp.ready();
const initData = Telegram.WebApp.initData || '';
const initDataUnsafe = Telegram.WebApp.initDataUnsafe || {
};
checkUserData()
</script>
</html>