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