86 lines
No EOL
1.8 KiB
JavaScript
86 lines
No EOL
1.8 KiB
JavaScript
import { div, body, a, parse } from './main.js'
|
|
import { loadself, loaduserspage } from './api.js'
|
|
import { header, parseUser } from './components.js'
|
|
|
|
function render() {
|
|
|
|
let new_body =
|
|
body({},
|
|
...header(false, true, data.self.user_id),
|
|
div({id: 'users'},
|
|
...data.users.map(u => parseUser(u))
|
|
),
|
|
div({id: 'load'},
|
|
a({class: 'bold gtext', onclick: async () => {
|
|
let users = await load()
|
|
|
|
let el = document.getElementById("users")
|
|
for (const user of users) {
|
|
el.appendChild(parseUser(user))
|
|
}
|
|
}},
|
|
parse("Load more users")
|
|
)
|
|
)
|
|
)
|
|
|
|
document.body.replaceWith(new_body)
|
|
}
|
|
|
|
var page = 0
|
|
const data = {
|
|
users: [],
|
|
self: {}
|
|
}
|
|
|
|
async function load() {
|
|
let request = await loadself()
|
|
|
|
if (request.status === 429) {
|
|
let new_body =
|
|
body({},
|
|
...header(false, true)
|
|
)
|
|
|
|
document.body.replaceWith(new_body)
|
|
throw new Error("Rate limited");
|
|
}
|
|
|
|
|
|
const self = request.json
|
|
|
|
header(false, true, self.user_id)
|
|
const users = (await loaduserspage(page)).json
|
|
|
|
if (users.length === 0) {
|
|
document.getElementById('load').remove()
|
|
return []
|
|
} else {
|
|
page++
|
|
}
|
|
return users
|
|
}
|
|
|
|
async function init() {
|
|
|
|
let request = (await loadself());
|
|
|
|
if (request.status === 429) {
|
|
let new_body =
|
|
body({},
|
|
...header(true, false, data.self.user_id)
|
|
)
|
|
|
|
document.body.replaceWith(new_body)
|
|
throw new Error("Rate limited");
|
|
}
|
|
|
|
data.self = request.json
|
|
|
|
const users = await load()
|
|
data.users.push(... users)
|
|
|
|
render()
|
|
}
|
|
|
|
init() |