2023-01-29 05:35:06 +00:00
|
|
|
function swap(value) {
|
|
|
|
let postsb = document.getElementById("profilepostbutton");
|
|
|
|
let aboutb = document.getElementById("profileaboutbutton");
|
|
|
|
let posts = document.getElementById("posts");
|
|
|
|
let about = document.getElementById("about");
|
|
|
|
if (value) {
|
|
|
|
postsb.classList.add("selected")
|
|
|
|
aboutb.classList.remove("selected")
|
|
|
|
about.classList.add("hidden")
|
|
|
|
posts.classList.remove("hidden")
|
|
|
|
} else {
|
|
|
|
postsb.classList.remove("selected")
|
|
|
|
aboutb.classList.add("selected")
|
|
|
|
about.classList.remove("hidden")
|
|
|
|
posts.classList.add("hidden")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-26 22:29:16 +00:00
|
|
|
function render() {
|
|
|
|
const html = `
|
|
|
|
<div id="top">
|
|
|
|
<div id="banner">
|
|
|
|
<div>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div id="info">
|
|
|
|
<div class="face">
|
|
|
|
|
|
|
|
</div>
|
|
|
|
<div class="infodata">
|
|
|
|
<span class="bold ltext">${data.user.firstname + ' ' + data.user.lastname}</span>
|
|
|
|
<span class="gtext">Joined ${parseDate(new Date(data.user.date))}</span>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="fullline" style="width: 80em; margin-bottom: 0;"></div>
|
|
|
|
<div class="profilebuttons">
|
2023-01-29 05:35:06 +00:00
|
|
|
<button id="profilepostbutton" class="${posts ? 'selected' : ''}" onclick="swap(true)">
|
2023-01-26 22:29:16 +00:00
|
|
|
Posts
|
|
|
|
</button>
|
2023-01-29 05:35:06 +00:00
|
|
|
<button id="profileaboutbutton" class="${posts ? '' : 'selected'}" onclick="swap(false)">
|
2023-01-26 22:29:16 +00:00
|
|
|
About
|
|
|
|
</button>
|
2023-01-28 07:51:34 +00:00
|
|
|
<div style="flex: 20"></div>
|
|
|
|
${ isself ? `<button class="logout" onclick="logout_button()">Logout</button>` : ''}
|
2023-01-26 22:29:16 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
`
|
|
|
|
|
2023-01-29 05:35:06 +00:00
|
|
|
append(html)
|
2023-01-26 22:29:16 +00:00
|
|
|
|
|
|
|
const postsh = `
|
|
|
|
<div id="posts" class="${posts ? '' : 'hidden'}">
|
|
|
|
${data.posts.map(p => parsePost(p)).join('')}
|
|
|
|
</div>
|
|
|
|
`
|
|
|
|
|
2023-01-29 05:35:06 +00:00
|
|
|
append(postsh)
|
2023-01-26 22:29:16 +00:00
|
|
|
|
|
|
|
const about = `
|
|
|
|
<div id="about" class="post ${posts ? 'hidden' : ''}">
|
|
|
|
<span class="bold ltext">About</span>
|
|
|
|
<div class="data">
|
|
|
|
<span class="gtext bold">Name: ${data.user.firstname + ' ' + data.user.lastname}</span>
|
|
|
|
<span class="gtext bold">Email: ${data.user.email}</span>
|
|
|
|
<span class="gtext bold">Gender: ${data.user.gender}</span>
|
2023-01-28 07:51:34 +00:00
|
|
|
<span class="gtext bold">Birthday: ${parseMonth(data.user.month) + ' ' + data.user.day + ', ' + data.user.year}</span>
|
2023-01-26 22:29:16 +00:00
|
|
|
<span class="gtext bold">User ID: ${data.user.user_id}</span>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
`
|
|
|
|
|
2023-01-29 05:35:06 +00:00
|
|
|
append(about)
|
2023-01-26 22:29:16 +00:00
|
|
|
}
|
|
|
|
|
2023-01-28 07:51:34 +00:00
|
|
|
async function logout_button() {
|
|
|
|
const response = await logout()
|
|
|
|
if (response.status != 200) return;
|
|
|
|
location.href = '/login'
|
|
|
|
}
|
|
|
|
|
2023-01-26 22:29:16 +00:00
|
|
|
var posts = true
|
2023-01-28 07:51:34 +00:00
|
|
|
var isself = false
|
2023-01-26 22:29:16 +00:00
|
|
|
|
|
|
|
async function load() {
|
|
|
|
header(false, false)
|
|
|
|
|
|
|
|
var params = {};
|
|
|
|
for (const [key, value] of new URLSearchParams(location.search)) {
|
|
|
|
params[key] = value
|
|
|
|
}
|
|
|
|
|
2023-01-29 05:35:06 +00:00
|
|
|
data.user = (await loadself()).json;
|
|
|
|
data.users[data.user.user_id] = data.user
|
2023-01-28 07:51:34 +00:00
|
|
|
let id;
|
|
|
|
|
|
|
|
if (params.id !== undefined && !isNaN(params.id)) {
|
|
|
|
|
|
|
|
id = parseInt(params.id);
|
|
|
|
} else {
|
2023-01-29 05:35:06 +00:00
|
|
|
id = data.user.user_id
|
2023-01-28 07:51:34 +00:00
|
|
|
}
|
|
|
|
|
2023-01-29 05:35:06 +00:00
|
|
|
isself = id === data.user.user_id
|
2023-01-28 07:51:34 +00:00
|
|
|
|
2023-01-26 22:29:16 +00:00
|
|
|
const posts = (await loadusersposts(id)).json
|
|
|
|
data.posts.push(... posts)
|
2023-01-29 05:35:06 +00:00
|
|
|
const batch = []
|
2023-01-26 22:29:16 +00:00
|
|
|
for (const post of posts) {
|
|
|
|
for(const comment of post.comments) {
|
|
|
|
if (data.users[comment[0]] !== undefined) continue
|
|
|
|
if (batch.includes(comment[0])) continue
|
|
|
|
batch.push(comment[0])
|
|
|
|
}
|
|
|
|
if (data.users[post.user_id] !== undefined) continue
|
|
|
|
if (batch.includes(post.user_id)) continue
|
|
|
|
batch.push(post.user_id)
|
|
|
|
}
|
2023-01-29 05:35:06 +00:00
|
|
|
const users = batch.length == 0 ? [] : (await loadusers(batch)).json
|
2023-01-26 22:29:16 +00:00
|
|
|
for (const user of users) {
|
|
|
|
data.users[user.user_id] = user
|
|
|
|
}
|
|
|
|
render()
|
|
|
|
}
|
|
|
|
|
|
|
|
load()
|