2023-02-14 03:41:09 +00:00
|
|
|
import { div, body, span, parse } from './main.js'
|
2023-02-12 19:11:50 +00:00
|
|
|
import { loadself, loaduserspage } from './api.js'
|
|
|
|
import { header, parseUser } from './components.js'
|
2023-01-26 22:29:16 +00:00
|
|
|
|
|
|
|
function render() {
|
2023-02-12 19:11:50 +00:00
|
|
|
|
|
|
|
let new_body =
|
|
|
|
body({},
|
2023-07-26 05:04:39 +00:00
|
|
|
...header(false, true, false, data.self.user_id),
|
2023-02-12 19:11:50 +00:00
|
|
|
div({id: 'users'},
|
|
|
|
...data.users.map(u => parseUser(u))
|
|
|
|
),
|
|
|
|
div({id: 'load'},
|
2023-02-14 03:41:09 +00:00
|
|
|
span({class: 'bold gtext', onclick: async () => {
|
2023-02-12 19:11:50 +00:00
|
|
|
let users = await load()
|
2023-01-26 22:29:16 +00:00
|
|
|
|
2023-02-12 19:11:50 +00:00
|
|
|
let el = document.getElementById("users")
|
|
|
|
for (const user of users) {
|
|
|
|
el.appendChild(parseUser(user))
|
|
|
|
}
|
|
|
|
}},
|
|
|
|
parse("Load more users")
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
2023-01-26 22:29:16 +00:00
|
|
|
|
2023-02-12 19:11:50 +00:00
|
|
|
document.body.replaceWith(new_body)
|
2023-01-26 22:29:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var page = 0
|
2023-02-12 19:11:50 +00:00
|
|
|
const data = {
|
|
|
|
users: [],
|
|
|
|
self: {}
|
2023-01-29 05:35:06 +00:00
|
|
|
}
|
|
|
|
|
2023-01-26 22:29:16 +00:00
|
|
|
async function load() {
|
2023-02-12 19:11:50 +00:00
|
|
|
|
2023-01-26 22:29:16 +00:00
|
|
|
const users = (await loaduserspage(page)).json
|
2023-02-12 19:11:50 +00:00
|
|
|
|
2023-01-26 22:29:16 +00:00
|
|
|
if (users.length === 0) {
|
2023-02-12 19:11:50 +00:00
|
|
|
document.getElementById('load').remove()
|
|
|
|
return []
|
2023-01-26 22:29:16 +00:00
|
|
|
} else {
|
|
|
|
page++
|
|
|
|
}
|
2023-01-29 05:35:06 +00:00
|
|
|
return users
|
|
|
|
}
|
|
|
|
|
|
|
|
async function init() {
|
2023-02-12 19:11:50 +00:00
|
|
|
|
|
|
|
let request = (await loadself());
|
2023-02-13 16:59:00 +00:00
|
|
|
if (request.json == undefined) {
|
|
|
|
location.href = '/login'
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-02-12 19:11:50 +00:00
|
|
|
data.self = request.json
|
|
|
|
|
|
|
|
const users = await load()
|
2023-01-26 22:29:16 +00:00
|
|
|
data.users.push(... users)
|
2023-02-12 19:11:50 +00:00
|
|
|
|
2023-01-26 22:29:16 +00:00
|
|
|
render()
|
|
|
|
}
|
|
|
|
|
2023-07-26 05:04:39 +00:00
|
|
|
init()
|