ft_transcendence/frontend/static/js/views/ProfilePageView.js

63 lines
1.6 KiB
JavaScript
Raw Permalink Normal View History

import AbstractView from "./abstracts/AbstractView.js";
import { client } from "../index.js"
export default class extends AbstractView {
constructor(params) {
super(params, "Profile ");
this.user_id = params.id;
}
async postInit()
{
2023-12-20 17:48:52 -05:00
this.profile = await client.profiles.getProfile(this.user_id);
this.info = document.getElementById("info");
// Username
let username = document.createElement("a");
username.id = "username";
2023-12-20 17:48:52 -05:00
username.appendChild(document.createTextNode(this.profile.username));
this.info.appendChild(username);
2023-12-20 17:48:52 -05:00
this.info.appendChild(document.createElement("br"));
// Avatar
let avatar = document.createElement("img");
avatar.id = "avatar";
2023-12-20 17:48:52 -05:00
avatar.src = this.profile.avatar_url;
this.info.appendChild(avatar);
await this.blockButton();
}
2023-12-20 17:48:52 -05:00
async blockButton() {
// Block option
if (client.me.user_id != this.user_id) {
let block = document.getElementById("block") || document.createElement("a");
block.id = "block";
block.innerText = "";
block.onclick = async () => {
if (!this.profile.isBlocked)
await client.profiles.block(this.user_id);
else
await client.profiles.deblock(this.user_id);
this.profile = await client.profiles.getProfile(this.user_id);
this.blockButton();
};
if (this.profile.isBlocked)
block.appendChild(document.createTextNode("Deblock"));
else
block.appendChild(document.createTextNode("Block"));
this.info.appendChild(block);
}
}
async getHtml() {
return `
<link rel="stylesheet" href="/static/css/profile.css">
<div id="info">
</div>
`;
}
}