Scratch space for learning atproto app development
1Array.from(document.querySelectorAll('.status-option'), (el) => {
2 el.addEventListener('click', async (ev) => {
3 setError('')
4
5 if (el.dataset.authed !== '1') {
6 window.location = '/login'
7 return
8 }
9
10 const res = await fetch('/status', {
11 method: 'POST',
12 headers: { 'content-type': 'application/json' },
13 body: JSON.stringify({ status: el.dataset.value }),
14 })
15 const body = await res.json()
16 if (body?.error) {
17 setError(body.error)
18 } else {
19 location.reload()
20 }
21 })
22})
23
24function setError(str) {
25 const errMsg = document.querySelector('.error')
26 if (str) {
27 errMsg.classList.add('visible')
28 errMsg.textContent = str
29 } else {
30 errMsg.classList.remove('visible')
31 }
32}