access profiles with username instead of id
This commit is contained in:
@ -5,21 +5,21 @@ class Profile
|
||||
/**
|
||||
* @param {Client} client
|
||||
*/
|
||||
constructor (client, id, username = undefined, avatar_url = undefined)
|
||||
constructor (client, username, id = undefined, avatar_url = undefined)
|
||||
{
|
||||
/**
|
||||
* @type {Client} client
|
||||
*/
|
||||
this.client = client;
|
||||
this.id = id;
|
||||
this.username = username;
|
||||
this.id = id;
|
||||
this.avatar_url = avatar_url;
|
||||
this.isBlocked = false;
|
||||
}
|
||||
|
||||
async init()
|
||||
{
|
||||
let response = await this.client._get(`/api/profiles/${this.id}`);
|
||||
let response = await this.client._get(`/api/profiles/${this.username}`);
|
||||
|
||||
if (response.status !== 200)
|
||||
return response.status;
|
||||
|
@ -20,14 +20,14 @@ class Profiles
|
||||
|
||||
let profiles = []
|
||||
response_data.forEach((profile) => {
|
||||
profiles.push(new Profile(this.client, profile.user_id, profile.username, profile.avatar_url))
|
||||
profiles.push(new Profile(this.client, profile.username, profile.user_id, profile.avatar_url))
|
||||
});
|
||||
return profiles;
|
||||
}
|
||||
|
||||
async getProfile(user_id)
|
||||
async getProfile(username)
|
||||
{
|
||||
let profile = new Profile(this.client, user_id);
|
||||
let profile = new Profile(this.client, username);
|
||||
if (await profile.init())
|
||||
return null;
|
||||
return profile;
|
||||
|
@ -68,7 +68,7 @@ const router = async(uri) => {
|
||||
|
||||
const routes = [
|
||||
{ path: "/", view: Dashboard },
|
||||
{ path: "/profiles/:id", view: ProfilePageView },
|
||||
{ path: "/profiles/:username", view: ProfilePageView },
|
||||
{ path: "/tournaments/create", view: TournamentCreateView },
|
||||
{ path: "/tournaments/:id", view: TournamentPageView },
|
||||
{ path: "/tournaments/", view: TournamentsView },
|
||||
|
@ -18,7 +18,7 @@ export default class extends AbstractAuthentificateView
|
||||
}
|
||||
|
||||
async display_avatar() {
|
||||
let profile = await client.profiles.getProfile(client.me.id);
|
||||
let profile = await client.profiles.getProfile(client.me.username);
|
||||
if (profile !== undefined || profile !== null) {
|
||||
if (document.getElementById("avatar") != undefined)
|
||||
document.getElementById("avatar").remove();
|
||||
|
@ -4,17 +4,16 @@ import { client } from "../index.js"
|
||||
export default class extends AbstractView {
|
||||
constructor(params) {
|
||||
super(params, "Profile ");
|
||||
this.user_id = params.id;
|
||||
this.username = params.username;
|
||||
}
|
||||
|
||||
async postInit()
|
||||
{
|
||||
let profile = await client.profiles.getProfile(this.user_id);
|
||||
|
||||
if (profile === null)
|
||||
this.profile = await client.profiles.getProfile(this.username);
|
||||
if (this.profile === null)
|
||||
return 404;
|
||||
this.userId = this.profile.id;
|
||||
|
||||
this.profile = await client.profiles.getProfile(this.user_id);
|
||||
this.info = document.getElementById("info");
|
||||
|
||||
// Username
|
||||
@ -39,16 +38,16 @@ export default class extends AbstractView {
|
||||
if (await client.isAuthentificate() === false)
|
||||
return;
|
||||
|
||||
if (client.me.id != this.user_id) {
|
||||
if (client.me.id != this.userId) {
|
||||
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);
|
||||
await client.profiles.block(this.userId);
|
||||
else
|
||||
await client.profiles.deblock(this.user_id);
|
||||
this.profile = await client.profiles.getProfile(this.user_id);
|
||||
await client.profiles.deblock(this.userId);
|
||||
this.profile = await client.profiles.getProfile(this.username);
|
||||
this.blockButton();
|
||||
};
|
||||
if (this.profile.isBlocked)
|
||||
|
Reference in New Issue
Block a user