From c93f9d020b57f6f83c23b1fd80ebdb3b470c9a1f Mon Sep 17 00:00:00 2001 From: Pheuw1 Date: Thu, 16 Mar 2023 14:04:48 +0100 Subject: [PATCH] front channels --- .env_sample | 25 -------------- front/volume/src/components/Channels.svelte | 37 +++++++++++++++++---- front/volume/src/components/Chat.svelte | 5 ++- 3 files changed, 35 insertions(+), 32 deletions(-) delete mode 100644 .env_sample diff --git a/.env_sample b/.env_sample deleted file mode 100644 index 1e5aaa2..0000000 --- a/.env_sample +++ /dev/null @@ -1,25 +0,0 @@ -POSTGRES_HOST=postgres -POSTGRES_PORT=5432 -POSTGRES_USER=postgres_usr -POSTGRES_PASSWORD=postgres_pw -POSTGRES_DB=transcendence - -PGADMIN_DEFAULT_EMAIL=admin@pg.com -PGADMIN_DEFAULT_PASSWORD=admin - -MAIL_USER=vaganiwast@gmail.com -MAIL_PASSWORD= - -FRONT_FPS=144 - -HOST=localhost -FRONT_PORT=80 -BACK_PORT=3001 -HASH_SALT=10 - -JWT_SECRET=test -JWT_EXPIRATION_TIME=900 - -FT_OAUTH_CLIENT_ID= -FT_OAUTH_CLIENT_SECRET= -FT_OAUTH_CALLBACK_URL=http://$HOST:$BACK_PORT/log/inReturn diff --git a/front/volume/src/components/Channels.svelte b/front/volume/src/components/Channels.svelte index 8533cff..99eb56e 100644 --- a/front/volume/src/components/Channels.svelte +++ b/front/volume/src/components/Channels.svelte @@ -23,14 +23,18 @@ }); }; - let channels: Array = []; - onMount(async () => { + const getChannels = async () => { const res = await fetch(API_URL + "/channels", { credentials: "include", mode: "cors", }); if (res.ok) channels = await res.json(); - }); + }; + + let channels: Array = []; + onMount(async () => { + getChannels() + }); //--------------------------------------------------------------------------------/ @@ -46,11 +50,25 @@ //--------------------------------------------------------------------------------/ const createChannel = async () => { - const name = prompt("Enter a name for the new channel:"); + let name, friend; + if (channelMode === "direct") { + friend = prompt("Invite a friend to your channel:"); + const response = await fetch(API_URL + "/users/" + friend + "/byname", { + credentials: "include", + method: "GET", + mode: "cors",}); + if (!response.ok) { + alert("Error getting user infos"); + return + } + } + else name = prompt("Enter a name for the new channel:"); if (name) { let password = ""; - if (channelMode !== "direct") + if (channelMode === "private") password = prompt("Enter a password for the new channel:"); + if (friend !== undefined) name = "💬 " + $store.username + "/" + friend; + else name = "🚪 " + name; const response = await fetch(API_URL + "/channels", { credentials: "include", method: "POST", @@ -62,7 +80,8 @@ name: name, owner: $store.ftId, password: password, - isPrivate: channelMode === "private", + isPrivate: channelMode === "private" || channelMode === "direct", + direct: friend, }), }); if (response.ok) { @@ -70,6 +89,12 @@ } else { alert("Error creating channel"); } + const res = await fetch(API_URL + "/channels", { + credentials: "include", + mode: "cors", + }); + if (res.ok) channels = await res.json(); + getChannels() } }; diff --git a/front/volume/src/components/Chat.svelte b/front/volume/src/components/Chat.svelte index 7e90efc..67fee85 100644 --- a/front/volume/src/components/Chat.svelte +++ b/front/volume/src/components/Chat.svelte @@ -33,7 +33,10 @@ }); onDestroy(() => { - socket.emit("leaveChannel"); + io.emit("LeaveChanel", async (response) => { + console.log(response.status); + }); + io.disconnect(); }); //--------------------------------------------------------------------------------/