Scratch space for learning atproto app development

Update tutorial for new behavior

Changed files
+13 -34
src
pages
+9 -28
TUTORIAL.md
···
The Atmosphere works the same way, except we're going to check `at://` instead of `https://`. Each user has a data repo under an `at://` URL. We'll crawl all the `at://`s in the Atmosphere for all the "status.json" records and aggregate them into our SQLite database.
-
> `at://` is the URL scheme of the AT Protocol.
## Step 1. Starting with our ExpressJS app
···
// If the user is signed in, get an agent which communicates with their server
const agent = await getSessionAgent(req, res, ctx)
if (!agent) {
-
return res.status(401).json({ error: 'Session required' })
}
// Construct their status record
···
})
} catch (err) {
logger.warn({ err }, 'failed to write record')
-
return res.status(500).json({ error: 'Failed to write record' })
}
res.status(200).json({})
···
```html
<!-- src/pages/home.ts -->
-
<div class="status-options">
-
${['👍', '🦋', '🥳', /*...*/].map(status => html`
-
<div class="status-option" data-value="${status}">
${status}
-
</div>`
-
)}
-
</div>
-
```
-
-
And write some client-side javascript to submit the status on click:
-
-
```javascript
-
/* src/pages/public/home.js */
-
Array.from(document.querySelectorAll('.status-option'), (el) => {
-
el.addEventListener('click', async (ev) => {
-
const res = await fetch('/status', {
-
method: 'POST',
-
headers: { 'content-type': 'application/json' },
-
body: JSON.stringify({ status: el.dataset.value }),
-
})
-
const body = await res.json()
-
if (!body?.error) {
-
location.reload()
-
}
-
})
-
})
```
And here we are!
···
The Atmosphere works the same way, except we're going to check `at://` instead of `https://`. Each user has a data repo under an `at://` URL. We'll crawl all the `at://`s in the Atmosphere for all the "status.json" records and aggregate them into our SQLite database.
+
> `at://` is the URL scheme of the AT Protocol. Under the hood it uses common tech like HTTP and DNS, but it adds all of the features we'll be using in this tutorial.
## Step 1. Starting with our ExpressJS app
···
// If the user is signed in, get an agent which communicates with their server
const agent = await getSessionAgent(req, res, ctx)
if (!agent) {
+
return res.status(401).type('html').send('<h1>Error: Session required</h1>')
}
// Construct their status record
···
})
} catch (err) {
logger.warn({ err }, 'failed to write record')
+
return res.status(500).type('html').send('<h1>Error: Failed to write record</h1>')
}
res.status(200).json({})
···
```html
<!-- src/pages/home.ts -->
+
<form action="/status" method="post" class="status-options">
+
${STATUS_OPTIONS.map(status => html`
+
<button class="status-option" name="status" value="${status}">
${status}
+
</button>
+
`)}
+
</form>
```
And here we are!
+4 -6
src/pages/home.ts
···
${STATUS_OPTIONS.map(
(status) =>
html`<button
-
class=${
-
myStatus?.status === status
-
? 'status-option selected'
-
: 'status-option'
-
}
name="status"
value="${status}"
>
${status}
-
</div>`
)}
</form>
${statuses.map((status, i) => {
···
${STATUS_OPTIONS.map(
(status) =>
html`<button
+
class=${myStatus?.status === status
+
? 'status-option selected'
+
: 'status-option'}
name="status"
value="${status}"
>
${status}
+
</button>`
)}
</form>
${statuses.map((status, i) => {