import AbstractView from "./AbstractView.js"; import {client} from "../index.js"; export default class extends AbstractView { constructor(params) { super(params, "Search"); } async postInit() { let search = document.getElementById("form"); search.addEventListener("input", this.users) this.users(); } async users() { let search = document.getElementById("form").value; let logged = await client.isAuthentificate(); let users = await client.profiles.all(); let list_users = document.getElementById('list_users'); list_users.innerHTML = ""; users.filter(user => user.username.startsWith(search) == true).forEach((user) => { var new_user = document.createElement("li"); // username let username = document.createElement("a"); username.href = `/profiles/${user.user_id}`; username.appendChild(document.createTextNode(user.username)); new_user.appendChild(username); // space new_user.appendChild(document.createTextNode(" ")); // chat if (logged) { let chat = document.createElement("a"); let array = [ client.me.user_id, user.user_id, ]; console.log(client.me.id); chat.addEventListener("click", async function(){ console.log("click"); await client.channels.createChannel([client.me.user_id , user.user_id]); }); //chat.href = `/chat` chat.appendChild(document.createTextNode("Chat")); new_user.appendChild(chat); } // break line new_user.appendChild(document.createElement("br")); // avatar var img = document.createElement("img"); img.src = user.avatar_url; new_user.appendChild(img); list_users.appendChild(new_user); }); //console.log(list_users); } async getHtml() { return `
`; } }