Advance don't merge
This commit is contained in:
parent
9b523f082f
commit
bc892bc157
9
frontend/static/js/api/chat/channel.js
Normal file
9
frontend/static/js/api/chat/channel.js
Normal file
@ -0,0 +1,9 @@
|
||||
class Channel {
|
||||
constructor(id, members, messages) {
|
||||
this.id = id;
|
||||
this.members = members;
|
||||
this.messages = messages;
|
||||
}
|
||||
}
|
||||
|
||||
export {Channel}
|
19
frontend/static/js/api/chat/channels.js
Normal file
19
frontend/static/js/api/chat/channels.js
Normal file
@ -0,0 +1,19 @@
|
||||
class Channels {
|
||||
constructor(client) {
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
async createChannel(users_id) {
|
||||
console.log(users_id);
|
||||
let response = await this.client._post("/api/chat/", {
|
||||
users_id:users_id
|
||||
});
|
||||
|
||||
let data = await response.json();
|
||||
if (data == "Channel already exist")
|
||||
return null;
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
export {Channels}
|
@ -11,7 +11,6 @@ import { Client } from "./api/client.js";
|
||||
import AbstractRedirectView from "./views/AbstractRedirectView.js";
|
||||
import MeView from "./views/MeView.js";
|
||||
import ProfilePageView from "./views/profiles/ProfilePageView.js";
|
||||
import ProfilesView from "./views/profiles/ProfilesView.js";
|
||||
|
||||
let client = new Client(location.protocol + "//" + location.host)
|
||||
|
||||
@ -36,7 +35,6 @@ const navigateTo = async (uri) => {
|
||||
const router = async (uri) => {
|
||||
const routes = [
|
||||
{ path: "/", view: Dashboard },
|
||||
{ path: "/profiles", view: ProfilesView},
|
||||
{ path: "/profiles/:id", view: ProfilePageView },
|
||||
{ path: "/settings", view: Settings },
|
||||
{ path: "/login", view: LoginView },
|
||||
|
@ -1,6 +1,6 @@
|
||||
import AbstractAuthentifiedView from "./AbstractAuthentifiedView.js";
|
||||
import AbstractView from "./AbstractView.js";
|
||||
|
||||
export default class extends AbstractAuthentifiedView {
|
||||
export default class extends AbstractView {
|
||||
constructor(params) {
|
||||
super(params, "Chat");
|
||||
|
||||
|
@ -19,7 +19,7 @@ export default class extends AbstractView {
|
||||
|
||||
let search = document.getElementById("form").value;
|
||||
|
||||
let logged = client.isAuthentificate();
|
||||
let logged = await client.isAuthentificate();
|
||||
|
||||
let users = await client.profiles.all();
|
||||
let list_users = document.getElementById('list_users');
|
||||
@ -38,10 +38,21 @@ export default class extends AbstractView {
|
||||
new_user.appendChild(document.createTextNode(" "));
|
||||
|
||||
// chat
|
||||
let chat = document.createElement("a");
|
||||
chat.href = `/chat`
|
||||
chat.appendChild(document.createTextNode("Chat"));
|
||||
new_user.appendChild(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"));
|
||||
@ -54,7 +65,7 @@ export default class extends AbstractView {
|
||||
|
||||
list_users.appendChild(new_user);
|
||||
});
|
||||
console.log(list_users);
|
||||
//console.log(list_users);
|
||||
|
||||
}
|
||||
|
||||
|
@ -26,4 +26,4 @@ export default class extends AbstractView {
|
||||
<a id="username"></a>
|
||||
`;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,40 +0,0 @@
|
||||
import AbstractView from "../AbstractView.js";
|
||||
import { client } from "../../index.js"
|
||||
|
||||
export default class extends AbstractView {
|
||||
constructor(params) {
|
||||
super(params, "Profiles");
|
||||
}
|
||||
|
||||
async postInit()
|
||||
{
|
||||
let profiles = await client.profiles.all()
|
||||
let profile_list_element = document.getElementById("profile-list")
|
||||
|
||||
profiles.forEach((profile) => {
|
||||
let profile_element = document.createElement("div");
|
||||
profile_element.className = "item";
|
||||
|
||||
let avatar = document.createElement("img");
|
||||
avatar.src = profile.avatar_url;
|
||||
|
||||
let username = document.createElement("a");
|
||||
username.href = `/profiles/${profile.user_id}`;
|
||||
username.appendChild(document.createTextNode(profile.username));
|
||||
|
||||
profile_element.appendChild(avatar);
|
||||
profile_element.appendChild(username);
|
||||
|
||||
profile_list_element.appendChild(profile_element)
|
||||
});
|
||||
}
|
||||
|
||||
async getHtml() {
|
||||
return `
|
||||
<link rel="stylesheet" href="/static/css/profiles/profiles.css">
|
||||
<div id="profile-list">
|
||||
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user