profile: wip
This commit is contained in:
parent
b2076fcd08
commit
523f4081fa
@ -3,44 +3,26 @@ import { client, lang } from "../index.js";
|
|||||||
|
|
||||||
export default class extends AbstractView {
|
export default class extends AbstractView {
|
||||||
constructor(params) {
|
constructor(params) {
|
||||||
super(params, decodeURI(params.username));
|
super(params, `${decodeURI(params.username)} - Profile`);
|
||||||
this.username = decodeURI(params.username);
|
this.username = decodeURI(params.username);
|
||||||
}
|
}
|
||||||
|
|
||||||
setTitle() {
|
setTitle() {
|
||||||
document.title = this.username;
|
document.title = `${this.username} - Profile`;
|
||||||
}
|
}
|
||||||
|
|
||||||
async postInit()
|
async postInit()
|
||||||
{
|
{
|
||||||
this.profile = await client.profiles.getProfile(this.username);
|
if (!this.profile)
|
||||||
|
|
||||||
if (this.profile === null)
|
|
||||||
return 404;
|
return 404;
|
||||||
this.user_id = this.profile.id;
|
|
||||||
|
|
||||||
this.info = document.getElementById("info");
|
this.userId = this.profile.id;
|
||||||
|
|
||||||
// Username
|
|
||||||
let username = document.createElement("a");
|
|
||||||
username.id = "username";
|
|
||||||
username.appendChild(document.createTextNode(this.username));
|
|
||||||
this.info.appendChild(username);
|
|
||||||
|
|
||||||
this.info.appendChild(document.createElement("br"));
|
|
||||||
|
|
||||||
// Avatar
|
|
||||||
let avatar = document.createElement("img");
|
|
||||||
avatar.id = "avatar";
|
|
||||||
avatar.src = this.profile.avatar_url;
|
|
||||||
this.info.appendChild(avatar);
|
|
||||||
|
|
||||||
await this.blockButton();
|
await this.blockButton();
|
||||||
|
|
||||||
await this.friendButton();
|
await this.friendButton();
|
||||||
|
|
||||||
client.notice.rewrite_profile = async () => {
|
client.notice.rewrite_profile = async () => {
|
||||||
let result = await this.profile.getFriend();
|
await this.profile.getFriend();
|
||||||
await this.profile.getBlock();
|
await this.profile.getBlock();
|
||||||
await this.friendButton();
|
await this.friendButton();
|
||||||
};
|
};
|
||||||
@ -51,19 +33,19 @@ export default class extends AbstractView {
|
|||||||
if (await client.isAuthenticated() === false)
|
if (await client.isAuthenticated() === false)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (client.me.id != this.user_id) {
|
if (client.me.id != this.userId) {
|
||||||
let block = document.getElementById("block");
|
let block = document.getElementById("block");
|
||||||
if (block == undefined) {
|
if (block == undefined) {
|
||||||
block = document.createElement("p");
|
block = document.createElement("p");
|
||||||
this.info.appendChild(block);
|
// this.info.appendChild(block);
|
||||||
}
|
}
|
||||||
|
|
||||||
block.id = "block";
|
block.id = "block";
|
||||||
block.onclick = async () => {
|
block.onclick = async () => {
|
||||||
if (!this.profile.isBlocked)
|
if (!this.profile.isBlocked)
|
||||||
await client.profiles.block(this.user_id);
|
await client.profiles.block(this.userId);
|
||||||
else
|
else
|
||||||
await client.profiles.deblock(this.user_id);
|
await client.profiles.deblock(this.userId);
|
||||||
this.profile = await client.profiles.getProfile(this.username);
|
this.profile = await client.profiles.getProfile(this.username);
|
||||||
|
|
||||||
this.blockButton();
|
this.blockButton();
|
||||||
@ -79,12 +61,12 @@ export default class extends AbstractView {
|
|||||||
if (await client.isAuthenticated() === false)
|
if (await client.isAuthenticated() === false)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (client.me.id != this.user_id) {
|
if (client.me.id != this.userId) {
|
||||||
let yes = document.getElementById("yes") || document.createElement("p");
|
let yes = document.getElementById("yes") || document.createElement("p");
|
||||||
let no = document.getElementById("no") || document.createElement("p");
|
let no = document.getElementById("no") || document.createElement("p");
|
||||||
let friend = document.getElementById("friend") || document.createElement("p");
|
let friend = document.getElementById("friend") || document.createElement("p");
|
||||||
|
|
||||||
if (client.notice.data.asker.includes(this.user_id)) {
|
if (client.notice.data.asker.includes(this.userId)) {
|
||||||
|
|
||||||
if (friend)
|
if (friend)
|
||||||
friend.remove();
|
friend.remove();
|
||||||
@ -92,18 +74,18 @@ export default class extends AbstractView {
|
|||||||
yes.id = "yes";
|
yes.id = "yes";
|
||||||
yes.textContent = lang.get('profileAcceptRequest', 'Accept Friend');
|
yes.textContent = lang.get('profileAcceptRequest', 'Accept Friend');
|
||||||
yes.onclick = async () => {
|
yes.onclick = async () => {
|
||||||
client.notice.accept_friend(this.user_id);
|
client.notice.accept_friend(this.userId);
|
||||||
};
|
};
|
||||||
|
|
||||||
no.id = "no";
|
no.id = "no";
|
||||||
no.textContent = lang.get('profileDenyRequest', 'Decline Friend');
|
no.textContent = lang.get('profileDenyRequest', 'Decline Friend');
|
||||||
no.onclick = async () => {
|
no.onclick = async () => {
|
||||||
client.notice.refuse_friend(this.user_id);
|
client.notice.refuse_friend(this.userId);
|
||||||
};
|
};
|
||||||
|
|
||||||
this.info.appendChild(yes);
|
// this.info.appendChild(yes);
|
||||||
this.info.appendChild(document.createTextNode(" "));
|
// this.info.appendChild(document.createTextNode(" "));
|
||||||
this.info.appendChild(no);
|
// this.info.appendChild(no);
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -114,9 +96,9 @@ export default class extends AbstractView {
|
|||||||
friend.id = "friend";
|
friend.id = "friend";
|
||||||
friend.onclick = async () => {
|
friend.onclick = async () => {
|
||||||
if (this.profile.isFriend)
|
if (this.profile.isFriend)
|
||||||
await client.notice.remove_friend(this.user_id);
|
await client.notice.remove_friend(this.userId);
|
||||||
else
|
else
|
||||||
await client.notice.ask_friend(this.user_id);
|
await client.notice.ask_friend(this.userId);
|
||||||
await client.profiles.getProfile(this.username);
|
await client.profiles.getProfile(this.username);
|
||||||
this.friendButton();
|
this.friendButton();
|
||||||
};
|
};
|
||||||
@ -125,16 +107,29 @@ export default class extends AbstractView {
|
|||||||
else {
|
else {
|
||||||
friend.textContent = lang.get('profileAddFriend', 'Ask Friend');
|
friend.textContent = lang.get('profileAddFriend', 'Ask Friend');
|
||||||
}
|
}
|
||||||
this.info.appendChild(friend);
|
// this.info.appendChild(friend);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async getHtml() {
|
async getHtml() {
|
||||||
return `
|
|
||||||
<link rel="stylesheet" href="/static/css/profile.css">
|
|
||||||
<div id="info">
|
|
||||||
|
|
||||||
|
this.profile = await client.profiles.getProfile(this.username);
|
||||||
|
if (!this.profile)
|
||||||
|
return '';
|
||||||
|
|
||||||
|
const logged = await client.isAuthenticated();
|
||||||
|
|
||||||
|
return `
|
||||||
|
<div class='mb-3' id='profileInfo'>
|
||||||
|
<h1>${this.username}</h1>
|
||||||
|
<a href=${this.profile.avatar_url} target='_blank'>
|
||||||
|
<img class='img-thumbnail' src=${this.profile.avatar_url} style='width:auto; max-height:20vh; min-height:10vh'>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<button class='btn btn-sm btn-success ${logged ? '' : 'd-none'}' id='addFriendButton'>Add Friend</button>
|
||||||
|
<button class='btn btn-sm btn-danger ${logged ? '' : 'd-none'}' id='removeFriendButton'>Remove Friend</button>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user