
- New way to manage profiles with url -> /profil/username Django - modification of the user info query
76 lines
3.1 KiB
JavaScript
76 lines
3.1 KiB
JavaScript
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* main.js :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2024/09/19 23:08:31 by edbernar #+# #+# */
|
|
/* Updated: 2024/09/23 00:59:35 by edbernar ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
import { createNotification as CN } from "/static/javascript/notification/main.js";
|
|
import { waitForUserInfo } from "/static/javascript/typeResponse/typeUserInfo.js";
|
|
import { showPrivateChat } from "/static/javascript/liveChat/showPrivateChat.js";
|
|
import { LiveChat, showChatMenu } from "/static/javascript/liveChat/main.js";
|
|
import { userMeInfo } from "/static/javascript/typeResponse/typeLogin.js";
|
|
import { sendRequest } from "/static/javascript/websocket.js";
|
|
import { pageRenderer } from '/static/javascript/main.js'
|
|
|
|
class ProfilPage
|
|
{
|
|
static create(user)
|
|
{
|
|
const username = document.getElementsByTagName('h2')[0];
|
|
const pfp = document.getElementsByClassName('profile-image')[0];
|
|
const banner = document.getElementsByClassName('background-card')[0];
|
|
const githubButton = document.getElementById('github');
|
|
const discordButton = document.getElementById('discord');
|
|
const convButton = document.getElementById('newConv');
|
|
|
|
LiveChat.create();
|
|
if (typeof(user) == 'string')
|
|
sendRequest("get_user_info", {username: user});
|
|
else
|
|
sendRequest("get_user_info", {id: user});
|
|
waitForUserInfo().then((userInfo) => {
|
|
if (userInfo == null)
|
|
{
|
|
pageRenderer.changePage('homePage');
|
|
return ;
|
|
}
|
|
if (typeof(user) != 'string')
|
|
history.replaceState({}, document.title, window.location.pathname + '/' + userInfo.username);
|
|
username.innerText = userInfo.username + ' (status not implemented)';
|
|
pfp.style.backgroundImage = `url("${userInfo.pfp}")`
|
|
pfp.style.backgroundSize = "cover";
|
|
pfp.style.backgroundRepeat = "no-repeat";
|
|
banner.style.backgroundImage = `url("${userInfo.banner}")`
|
|
banner.style.backgroundSize = "cover";
|
|
banner.style.backgroundRepeat = "no-repeat";
|
|
if (userInfo.id == userMeInfo.id)
|
|
{
|
|
pfp.innerHTML = `<div id='editPenPfpBg'><img class='editPenPfp' src='/static/img/profilPage/editPen.png'/></div>`
|
|
banner.innerHTML = `<img class='editPen' src='/static/img/profilPage/editPen.png'/>`
|
|
}
|
|
if (userInfo.id != userMeInfo.id)
|
|
{
|
|
convButton.addEventListener('click', () => {
|
|
showChatMenu();
|
|
showPrivateChat({id: userInfo.id, name: userInfo.username});
|
|
});
|
|
}
|
|
else
|
|
convButton.remove();
|
|
});
|
|
}
|
|
|
|
static dispose()
|
|
{
|
|
LiveChat.dispose();
|
|
}
|
|
|
|
}
|
|
|
|
export { ProfilPage }; |