2023-12-11 08:54:39 -05:00
|
|
|
import AbstractView from "./AbstractView.js";
|
2023-12-11 07:09:20 -05:00
|
|
|
import {client} from "../index.js";
|
2023-11-30 10:36:21 -05:00
|
|
|
|
2023-12-11 08:54:39 -05:00
|
|
|
export default class extends AbstractView {
|
2023-11-30 10:36:21 -05:00
|
|
|
constructor(params) {
|
|
|
|
super(params, "Search");
|
|
|
|
}
|
|
|
|
|
|
|
|
async postInit() {
|
|
|
|
|
2023-12-11 08:54:39 -05:00
|
|
|
let search = document.getElementById("form");
|
|
|
|
search.addEventListener("input", this.users)
|
|
|
|
|
|
|
|
this.users();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
async users() {
|
|
|
|
|
|
|
|
let search = document.getElementById("form").value;
|
|
|
|
|
2023-12-12 04:04:46 -05:00
|
|
|
let logged = await client.isAuthentificate();
|
2023-12-11 08:54:39 -05:00
|
|
|
|
|
|
|
let users = await client.profiles.all();
|
2023-11-30 10:36:21 -05:00
|
|
|
let list_users = document.getElementById('list_users');
|
2023-12-11 08:54:39 -05:00
|
|
|
list_users.innerHTML = "";
|
|
|
|
|
|
|
|
users.filter(user => user.username.startsWith(search) == true).forEach((user) => {
|
2023-11-30 10:36:21 -05:00
|
|
|
var new_user = document.createElement("li");
|
2023-12-11 08:54:39 -05:00
|
|
|
|
|
|
|
// username
|
|
|
|
let username = document.createElement("a");
|
|
|
|
username.href = `/profiles/${user.user_id}`;
|
|
|
|
username.appendChild(document.createTextNode(user.username));
|
|
|
|
new_user.appendChild(username);
|
2023-12-11 10:14:27 -05:00
|
|
|
|
|
|
|
// space
|
|
|
|
new_user.appendChild(document.createTextNode(" "));
|
|
|
|
|
|
|
|
// chat
|
2023-12-12 04:04:46 -05:00
|
|
|
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);
|
|
|
|
}
|
2023-12-11 08:54:39 -05:00
|
|
|
|
|
|
|
// break line
|
|
|
|
new_user.appendChild(document.createElement("br"));
|
|
|
|
|
|
|
|
// avatar
|
|
|
|
var img = document.createElement("img");
|
|
|
|
img.src = user.avatar_url;
|
|
|
|
new_user.appendChild(img);
|
|
|
|
|
2023-12-11 10:14:27 -05:00
|
|
|
|
2023-11-30 10:36:21 -05:00
|
|
|
list_users.appendChild(new_user);
|
2023-12-11 08:54:39 -05:00
|
|
|
});
|
2023-12-12 04:04:46 -05:00
|
|
|
//console.log(list_users);
|
2023-11-30 10:36:21 -05:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
async getHtml() {
|
|
|
|
return `
|
2023-12-11 08:54:39 -05:00
|
|
|
<link rel="stylesheet" href="/static/css/search.css">
|
2023-11-30 10:36:21 -05:00
|
|
|
|
2023-12-11 08:54:39 -05:00
|
|
|
<input id="form" type="text" name="message" placeholder="userbozo"/>
|
2023-11-30 10:36:21 -05:00
|
|
|
|
|
|
|
<div id="users">
|
|
|
|
<ul id="list_users">
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
`;
|
|
|
|
}
|
|
|
|
}
|