Changeset f1c50f9 in Klonkt for src/assets/js
- Timestamp:
- 07/25/2026 10:37:37 AM (7 weeks ago)
- Branches:
- main
- Children:
- 97bacf2
- Parents:
- 787e0d9
- Location:
- src/assets/js
- Files:
-
- 1 deleted
- 1 edited
-
guardian.js (modified) (4 diffs)
-
guardian2.js (deleted)
Legend:
- Unmodified
- Added
- Removed
-
src/assets/js/guardian.js
r787e0d9 rf1c50f9 114 114 row.appendChild(el('span', 'who grow', handleOf(w.other_uri, w.other_handle))); 115 115 row.appendChild(el('span', 'tag ok', T.active)); 116 var wave = el('button', 'small', T.wave || '๐ Wave'); 117 wave.addEventListener('click', function () { sendWave(w.other_uri, wave); }); 118 row.appendChild(wave); 116 119 var btn = el('button', 'quiet small', T.release); 117 120 btn.addEventListener('click', function () { remove(w.other_uri, btn); }); … … 123 126 } 124 127 128 function sendWave(uri, btn) { 129 btn.disabled = true; 130 fetch('/guardian/api/wave', { 131 method: 'POST', headers: { 'Content-Type': 'application/json' }, 132 body: JSON.stringify({ ward: uri, site: S.site }), 133 }).then(function (r) { return r.json(); }) 134 .then(function (j) { btn.disabled = false; btn.textContent = (j && j.ok) ? (T.waved || '๐ sent') : (T.wave || '๐ Wave'); }) 135 .catch(function () { btn.disabled = false; }); 136 } 137 125 138 function remove(uri, btn) { 126 139 btn.disabled = true; … … 133 146 function renderAll() { renderHelp(); renderPending(); renderWards(); } 134 147 148 // โโ 0. Wards' corner: read-only feed of your wards' posts โโโโโโโโโโโโโโโ 149 function renderFeed(items) { 150 var list = document.getElementById('feed-list'); 151 list.textContent = ''; 152 (items || []).forEach(function (p) { 153 var card = el('div', 'g-card feed'); 154 var head = el('div', 'row'); 155 head.appendChild(el('span', 'who grow', p.author)); 156 if (p.published) head.appendChild(el('span', 'g-when', when(p.published))); 157 card.appendChild(head); 158 var body = el('div', 'feed-body'); 159 if (p.cw) { 160 var d = document.createElement('details'); 161 var sum = document.createElement('summary'); sum.textContent = p.cw; d.appendChild(sum); 162 var inner = el('div'); inner.innerHTML = p.content || ''; d.appendChild(inner); 163 body.appendChild(d); 164 } else { 165 body.innerHTML = p.content || ''; // server-sanitized HTML (same as Berichten) 166 } 167 card.appendChild(body); 168 list.appendChild(card); 169 }); 170 show('feed-section', (items || []).length > 0); 171 } 172 173 function loadFeed() { 174 return fetch('/guardian/api/feed?site=' + encodeURIComponent(S.site)) 175 .then(function (r) { return r.json(); }) 176 .then(function (f) { if (f && !f.error) renderFeed(f.items); }) 177 .catch(function () { /* corner just stays hidden */ }); 178 } 179 180 // โโ 0b. Follow requests on your wards (ยง5.3) โโโโโโโโโโโโโโโโโโโโโโโโโโโโ 181 function answerFollow(id, decision, btn) { 182 if (btn) btn.disabled = true; 183 fetch('/guardian/api/follow/' + encodeURIComponent(id), { 184 method: 'POST', headers: { 'Content-Type': 'application/json' }, 185 body: JSON.stringify({ decision: decision, site: S.site }), 186 }).then(loadFollowReqs); 187 } 188 function renderFollowReqs(items) { 189 var list = document.getElementById('follow-list'); 190 list.textContent = ''; 191 (items || []).forEach(function (f) { 192 var card = el('div', 'g-card'); 193 var row = el('div', 'row'); 194 row.appendChild(el('span', 'who grow', f.follower + ' โ ' + f.ward)); 195 var ok = el('button', 'small', T.accept || 'Accept'); 196 ok.addEventListener('click', function () { answerFollow(f.id, 'approve', ok); }); 197 var no = el('button', 'quiet small', T.reject || 'Deny'); 198 no.addEventListener('click', function () { answerFollow(f.id, 'reject', no); }); 199 row.appendChild(ok); row.appendChild(no); 200 card.appendChild(row); 201 list.appendChild(card); 202 }); 203 show('follow-section', (items || []).length > 0); 204 } 205 function loadFollowReqs() { 206 return fetch('/guardian/api/follow-requests?site=' + encodeURIComponent(S.site)) 207 .then(function (r) { return r.json(); }) 208 .then(function (f) { if (f && !f.error) renderFollowReqs(f.items); }) 209 .catch(function () { /* stays hidden */ }); 210 } 211 135 212 function refresh() { 136 213 return fetch('/guardian/api/state?site=' + encodeURIComponent(S.site)) 137 214 .then(function (r) { return r.json(); }) 138 .then(function (s) { if (s && !s.error) { S = s; T = s.strings || T; renderAll(); } }); 215 .then(function (s) { if (s && !s.error) { S = s; T = s.strings || T; renderAll(); } }) 216 .then(loadFeed).then(loadFollowReqs); 139 217 } 140 218 … … 230 308 }); 231 309 232 renderAll(); pushState(); 310 renderAll(); pushState(); loadFeed(); loadFollowReqs(); 233 311 setInterval(refresh, 45000); // live-ish while open 234 312 } catch (e) {
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)