-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsets.html
More file actions
364 lines (308 loc) · 13.7 KB
/
sets.html
File metadata and controls
364 lines (308 loc) · 13.7 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
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="theme-color" content="#0f7e94">
<meta property="og:type" content="website">
<meta name="robots" content="index, follow">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="DC.format" content="text/html" scheme="DCTERMS.DCMIType">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta property="og:title" content="Flash Study">
<meta name="twitter:title" content="Flash Study">
<meta property="og:site_name" content="Flash Study">
<meta name="DC.publisher" content="Flash Study" scheme="DCTERMS.DCMIType">
<meta name="owner" content="Ilan Luciano">
<meta name="designer" content="Ilan Luciano">
<meta name="DC.creator" content="Ilan Luciano">
<meta name="url" content="https://flashstudy.org">
<meta property="og:url" content="https://flashstudy.org">
<meta name="twitter:url" content="https://flashstudy.org">
<meta name='description' content="An easy-to-use website for studying and note sharing">
<meta property="og:description" content="An easy-to-use website for studying and note sharing">
<meta name="twitter:description" content="An easy-to-use website for studying and note sharing">
<meta name="DC.description" content="An easy-to-use website for studying and note sharing" scheme="DCTERMS.DCMIType">
<meta name="subject" content="flash study, flashcards, studying, quizlet, notes, notes sharing, quizlet alternative">
<meta name="DC.subject" content="flash study, flashcards, studying, quizlet, notes, notes sharing, quizlet alternative" scheme="DCTERMS.DCMIType">
<meta name="keywords" content="flash study, flashcards, studying, quizlet, notes, notes sharing, quizlet alternative">
<title>Sets | Flash Study</title>
<link rel="icon" type="image/x-icon" href="favicon.png">
<link rel="stylesheet" href="main.css?10">
<style>
.set {
width: calc(25% - 39px);
margin-bottom: 20px;
margin: 10px;
border: var(--content-border);
padding: 8px;
display: inline-block;
padding-bottom: 10px;
text-align: center;
}
.set button {
margin: 3px;
}
.name {
font-size: 15pt;
overflow: hidden;
white-space: nowrap;
}
input {
border: var(--content-border);
padding: 10px;
color: var(--dark-color);
font-size: 11pt;
outline: none;
width: 200px;
background-color:transparent;
}
#search {
position: absolute;
text-align: center;
margin-top: 12px;
left: calc(50% - 20px);
transform: translate(-50%);
}
#search-icon {
position: absolute;
left: calc(50% + 120px);
transform: translate(-50%);
margin-top: 12px;
max-height: 24px;
padding: 6.2px;
border: var(--content-border);
cursor: pointer;
background-color: var(--accent-color);
}
#sets {
padding: 10px;
}
.set-heading {
font-size: 14pt;
margin-top: 90px;
margin-left: 20px;
padding: 0px 20px 0px 20px;
width: calc(100% - 85px);
border: var(--content-border);
height: 60px;
}
.set-heading p {
float: left;
}
#errors {
position: relative;
display: none;
left: calc(100% - 320px);
transform: translate(-50%);
}
#load {
float: right;
margin-top: 12px;
transform: translate(5px);
position: relative;
}
@media (max-width: 1000px) {
.set {
width: calc(50% - 39px);
}
}
@media (max-width: 500px) {
.set {
width: calc(100% - 39px);
}
}
@media (max-width: 650px) {
.set-heading {
height: 160px;
text-align: center;
}
.set-heading p {
float: none;
}
#search {
margin-top: -5px;
}
#search-icon {
margin-top: -5px;
}
#load {
margin-top: 50px;
float: none;
}
}
</style>
</head>
<body>
<header>
<img src="logo.png" onclick="window.open('index.html', '_self');">
<div>
<a href="sets.html">Sets</a>
<div class="underline underlined"></div>
</div>
<div>
<a href="notes.html">Notes</a>
<div class="underline"></div>
</div>
<svg onclick="location.href = 'login.html'" id="profile" xmlns="http://www.w3.org/2000/svg" width="36" height="36" fill="currentColor" class="bi bi-person-fill" viewBox="0 0 16 16">
<path d="M3 14s-1 0-1-1 1-4 6-4 6 3 6 4-1 1-1 1zm5-6a3 3 0 1 0 0-6 3 3 0 0 0 0 6"/>
</svg>
<button onclick="dropdown();" id="new">Create</button>
<div id="dropdown" class="dropdown-content">
<a href="create-set.html">Create New Set</a>
<a href="create-note.html">Create New Note</a>
</div>
</header>
<div class="set-heading">
<p id="set-label">Popular Flash Sets</p>
<input id="search" type="text" placeholder="Search">
<svg onclick="search();" id="search-icon" xmlns="http://www.w3.org/2000/svg" width="26" height="26" fill="currentColor" class="bi bi-search" viewBox="0 0 16 16">
<path d="M11.742 10.344a6.5 6.5 0 1 0-1.397 1.398h-.001c.03.04.062.078.098.115l3.85 3.85a1 1 0 0 0 1.415-1.414l-3.85-3.85a1.007 1.007 0 0 0-.115-.1zM12 6.5a5.5 5.5 0 1 1-11 0 5.5 5.5 0 0 1 11 0z"/>
</svg>
<p id="errors">all sets are displayed</p>
<button id="load" onclick="loadMore();">Load More</button>
</div>
<div id="sets"></div>
<script src="main.js?v1"></script>
<script>
let setsPerPage = 8;
for (let i = 0; i < setsPerPage; i++) {
document.getElementById('sets').innerHTML += `
<div class="set" id="${i + 1}">
<p class="name">......</p>
<p>...</p>
<button onclick="">View</button>
</div>
`;
}
let setsLoaded = 0;
let queryLoaded;
window.addEventListener('load', async () => {
let profile = document.getElementById('profile');
let response = await fetcher(`/auth/check`);
let result = await response.text();
if (result == 'A token is required for authentication' || result == 'Invalid Token') {
// not logged into any account, proceed as normal
} else {
let json = JSON.parse(result);
profile.setAttribute('onclick', `location.href = 'profile.html'`);
}
loadPopular();
});
window.addEventListener('keypress', (e) => {
if (e.key == 'Enter' && document.activeElement == document.getElementById('search')) search();
});
async function search(e) {
let query = document.getElementById('search').value.trim();
let setLabel = document.getElementById('set-label');
let load = document.getElementById('load');
if (query == '') return loadPopular();
queryLoaded = query;
setLabel.innerText = query + ' Flash Sets';
load.onclick = loadMoreSearch;
setsLoaded = 0;
resetSets();
let setRes = await fetcher(`/sets/search`, { method: 'post', body: JSON.stringify({ order: 1, query: query }), headers: { 'Content-Type': 'application/json' }});
let setText = await setRes.text();
if (setRes.status == 201) {
if (setText == 'all sets are displayed') {
document.getElementById('sets').innerHTML += '<p style="text-align: center">there are no sets matching your search</p>';
} else {
let json = JSON.parse(setText);
for (set in json) {
setsLoaded += 1;
addSet(json[set].name, json[set].creator, json[set].id);
}
}
} else {
console.log(setText)
}
}
async function loadMore() {
let searched = document.getElementById('searched');
// load next setsPerPage popular flash sets
let res = await fetcher(`/sets/popular`, { method: 'post', body: JSON.stringify({ order: setsLoaded / setsPerPage + 1 }), headers: { 'Content-Type': 'application/json' }});
if (res.status == 201) {
let json = await res.json();
for (set in json) {
setsLoaded += 1;
addSet(json[set].name, json[set].creator, json[set].id);
}
if (json.length == 0) {
document.getElementById('errors').style.display = '';
setTimeout(() => {
document.getElementById('errors').style.display = 'none';
}, 1500);
return;
}
} else {
console.log(text)
}
}
async function loadMoreSearch() {
let searched = document.getElementById('searched');
// load next setsPerPage popular flash sets
let res = await fetcher(`/sets/search`, { method: 'post', body: JSON.stringify({ order: setsLoaded / setsPerPage + 1, query: queryLoaded }), headers: { 'Content-Type': 'application/json' }});
let text = await res.text();
if (res.status == 201) {
if (text == 'all sets are displayed') {
document.getElementById('errors').style.display = '';
setTimeout(() => {
document.getElementById('errors').style.display = 'none';
}, 1500);
return;
} else {
let json = JSON.parse(text);
for (set in json) {
setsLoaded += 1;
addSet(json[set].name, json[set].creator, json[set].id);
}
}
} else {
console.log(text)
}
}
function addSet(name, creator, id) {
let sets = document.getElementById('sets');
let setEle = document.createElement('div');
setEle.className = 'set';
setEle.id = setsLoaded;
let nameEle = document.createElement('p');
nameEle.className = 'name';
nameEle.innerText = name;
let creatorEle = document.createElement('p');
creatorEle.innerText = `Created By ${creator}`;
let viewButton = document.createElement('button');
viewButton.innerText = 'View';
viewButton.setAttribute('onclick', `location.assign('view-set.html?id=${id}');`);
setEle.appendChild(nameEle);
setEle.appendChild(creatorEle);
setEle.appendChild(viewButton);
sets.appendChild(setEle);
}
function resetSets() {
let sets = document.getElementById('sets');
sets.innerHTML = '';
}
async function loadPopular() {
let setLabel = document.getElementById('set-label');
let load = document.getElementById('load');
queryLoaded = '';
setsLoaded = 0;
setLabel.innerText = 'Popular Flash Sets';
load.onclick = loadMore;
// load popular flash sets
let res = await fetcher(`/sets/popular`, { method: 'post', body: JSON.stringify({ order: 1 }), headers: { 'Content-Type': 'application/json' }});
if (res.status == 201) {
let json = await res.json();
resetSets();
for (set in json) {
setsLoaded += 1;
addSet(json[set].name, json[set].creator, json[set].id);
}
} else {
console.log(text)
}
}
</script>
</body>
</html>