-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathview-set.html
More file actions
201 lines (168 loc) · 7.83 KB
/
view-set.html
File metadata and controls
201 lines (168 loc) · 7.83 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>loading...</title>
<link rel="icon" type="image/x-icon" href="favicon.png">
<link rel="stylesheet" href="main.css?12">
<style>
#main button {
margin: 5px;
}
table {
width: calc(100% - 20px);
margin-top: 20px;
padding: 10px;
text-align: left;
}
th {
font-size: 15pt;
padding: 5px 4px;
}
td {
padding: 8px 4px;
}
#main {
text-align: center;
max-width: 750px;
width: calc(100% - 37px);
min-height: 300px;
border: var(--content-border);
margin-left: 50%;
margin-top: 80px;
margin-bottom: 40px;
transform: translate(-50%);
}
#main p {
padding-left: 5px;
padding-right: 5px;
}
#title {
overflow: hidden;
width: calc(100vw - 190px);
white-space: nowrap;
}
#edit {
display: none;
}
</style>
</head>
<body>
<header>
<svg onclick="history.back()" id="back" xmlns="http://www.w3.org/2000/svg" width="40" height="40" fill="currentColor" class="bi bi-arrow-left-short" viewBox="0 0 16 16">
<path fill-rule="evenodd" d="M12 8a.5.5 0 0 1-.5.5H5.707l2.147 2.146a.5.5 0 0 1-.708.708l-3-3a.5.5 0 0 1 0-.708l3-3a.5.5 0 1 1 .708.708L5.707 7.5H11.5a.5.5 0 0 1 .5.5"/>
</svg>
<h1 id="title">...</h1>
<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" viewBox="0 0 16 16">
<path d="M8 8a3 3 0 1 0 0-6 3 3 0 0 0 0 6Zm2-3a2 2 0 1 1-4 0 2 2 0 0 1 4 0Zm4 8c0 1-1 1-1 1H3s-1 0-1-1 1-4 6-4 6 3 6 4Zm-1-.004c-.001-.246-.154-.986-.832-1.664C11.516 10.68 10.289 10 8 10c-2.29 0-3.516.68-4.168 1.332-.678.678-.83 1.418-.832 1.664h10Z"/>
</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 id="main">
<p>...</p>
<p>...</p>
<p>...</p>
<button onclick="">Flashcards</button>
<button onclick="">Questions</button>
<input id="copy" type="text" value="" style="display: none;">
<button onclick="copy()">Copy Share Link</button>
<button onclick="clone()">Clone Set</button>
<button id="edit" onclick="">Edit</button>
<p>...</p>
<table></table>
</div>
<script src="main.js?v1"></script>
<script>
const question = document.getElementById('main');
const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);
const id = urlParams.get('id');
if (!id) {
alert('invalid set id');
location.href = 'index.html';
}
window.addEventListener('load', async () => {
let response = await fetcher(`/sets/get/${id}`);
if (response.status == 201) {
let json = await response.json();
// update ui elements with data retrieved
document.getElementById('title').innerText = json.name;
document.title = json.name;
main.children[0].innerText = json.description;
main.children[1].innerText = `Created by ${json.creator}`;
main.children[2].innerText = `${json.completions || 0} completions`;
main.children[3].onclick = () => {
location.href = `flashcards.html?id=${id}`;
};
main.children[4].onclick = () => {
location.href = `study.html?id=${id}`;
};
document.getElementById('copy').value = `https://flashstudy.org/view-set.html?id=${id}`;
main.children[9].innerText = `${json.questions.length} questions`;
let table = main.children[10];
let row = document.createElement('tr');
let headingQ = document.createElement('th');
let headingA = document.createElement('th');
headingQ.innerText = json.q;
headingA.innerText = json.a;
row.appendChild(headingQ);
row.appendChild(headingA);
table.appendChild(row);
for (let i = 0; i < json.questions.length; i++) {
row = document.createElement('tr');
headingQ = document.createElement('td');
headingA = document.createElement('td');
headingQ.innerText = json.questions[i];
headingA.innerText = json.answers[i];
row.appendChild(headingQ);
row.appendChild(headingA);
table.appendChild(row);
}
// check auth and allow editing if user is owner
let authResponse = await fetcher(`/auth/check`);
let result = await authResponse.text();
if (result != 'A token is required for authentication' && result != 'Invalid Token') {
let authJson = JSON.parse(result);
if (authJson.username == json.creator) {
// user is owner of set, allow editing
let editButton = document.getElementById('edit');
editButton.style.display = 'inline-block';
editButton.onclick = () => {
location.href = `edit-set.html?id=${id}`;
};
}
}
} else {
// id given in urlparams is either invalid or server bug has occured
alert('invalid set id');
location.href = 'index.html';
}
});
function copy() {
let text = document.getElementById('copy');
text.select();
text.setSelectionRange(0, 99999);
navigator.clipboard.writeText(text.value);
document.getElementById('copy').innerText = 'copied.';
setTimeout(() => {
document.getElementById('copy').innerText = 'Copy Share Link';
}, 1000);
}
async function clone() {
let response = await fetcher(`/sets/clone`, { method: 'post', body: JSON.stringify({ setId: id }), headers: { 'Content-Type': 'application/json' }});
if (response.status == 201) {
let id = await response.text();
location.href = `edit-set.html?id=${id}`;
} else {
alert('Failed to clone set. You must be logged in to clone a set.');
}
}
</script>
</body>
</html>