From 344e2df0367e5ea9d102f9314ac32034914dbc12 Mon Sep 17 00:00:00 2001 From: Jack Date: Fri, 9 Oct 2020 23:38:06 +0100 Subject: [PATCH] url invite working, showing url in the room --- public/css/style.scss | 16 +++++++++++++++- public/index.html | 3 ++- public/js/account.js | 2 +- public/js/script.js | 15 ++++++++++----- public/js/tribe.js | 20 +++++++++++++++++++- 5 files changed, 47 insertions(+), 9 deletions(-) diff --git a/public/css/style.scss b/public/css/style.scss index 892bf8bf6..1aa3c10c9 100644 --- a/public/css/style.scss +++ b/public/css/style.scss @@ -2306,7 +2306,10 @@ key { .lobby{ display: grid; grid-template-areas: "currentsettings currentsettings" - "chat userlist"; + "chat userlist" + "inviteLink inviteLink"; + gap: 2rem; + grid-template-columns: 3fr 1fr; .title{ color: var(--sub-color); } @@ -2315,7 +2318,10 @@ key { } .chat{ grid-area: chat; + gap: 1rem; .messages{ + height: 200px; + overflow-y: scroll; .systemMessage{ color: var(--sub-color); } @@ -2328,6 +2334,14 @@ key { } } } + .input input{ + width: 100%; + } + } + .inviteLink{ + grid-area: inviteLink; + text-align: center; + color: var(--sub-color); } .userlist{ grid-area: userlist; diff --git a/public/index.html b/public/index.html index 1e3e7a240..ada50919e 100644 --- a/public/index.html +++ b/public/index.html @@ -3030,6 +3030,7 @@
users
+ @@ -3111,6 +3112,7 @@ + @@ -3120,5 +3122,4 @@ - diff --git a/public/js/account.js b/public/js/account.js index 73eb40335..8e671567a 100644 --- a/public/js/account.js +++ b/public/js/account.js @@ -256,7 +256,7 @@ firebase.auth().onAuthStateChanged(function (user) { } else { console.log('user is not logged in'); } - if ($(".pageTribe").hasClass('active') && !MP.socket.connected) { + if (!MP.socket.connected) { if (MP.state === -1) { mp_init(); } diff --git a/public/js/script.js b/public/js/script.js index b9f28d0b1..70f1d9b47 100644 --- a/public/js/script.js +++ b/public/js/script.js @@ -4882,11 +4882,16 @@ $(document).ready(() => { if (window.location.pathname === "/account") { history.replaceState("/", null, "/"); } else if (window.location.pathname !== "/") { - let page = window.location.pathname.replace("/", ""); - changePage(page); - } - if (/\/tribe\/.+/.test(window.location.pathname)) { - MP.autoJoin = window.location.pathname.split('/')[2]; + if (/\/tribe_.+/.test(window.location.pathname)) { + changePage('tribe'); + let code = window.location.pathname.split('/')[1]; + code = code.substring(5); + code = "room" + code; + MP.autoJoin = code; + } else { + let page = window.location.pathname.replace("/", ""); + changePage(page); + } } }); }); diff --git a/public/js/tribe.js b/public/js/tribe.js index b6694b732..840108d57 100644 --- a/public/js/tribe.js +++ b/public/js/tribe.js @@ -29,6 +29,12 @@ function mp_refreshUserList() { }) } +function resetLobby(){ + $(".pageTribe .lobby .userlist .list").empty(); + $(".pageTribe .lobby .chat .messages").empty(); + $(".pageTribe .lobby .inviteLink").text(''); +} + MP.socket.on('connect', (f) => { MP.state = 1; MP.reconnectionAttempts = 0; @@ -48,8 +54,16 @@ MP.socket.on('connect', (f) => { }) MP.socket.on('disconnect', (f) => { - MP.state = 1; + MP.state = -1; + MP.room = undefined; showNotification('Disconnected from Tribe', 1000); + resetLobby(); + $(".pageTribe div").addClass("hidden"); + $('.pageTribe .preloader').removeClass('hidden').css('opacity',1); + $(".pageTribe .preloader").html(` + +
Disconnected from tribe
+ `); }) MP.socket.on('connect_failed', (f) => { @@ -88,6 +102,8 @@ MP.socket.on('mp_room_joined', data => { //user is already in the room and somebody joined } else if(MP.state === 1) { //user is in prelobby and joined a room + let link = "www.monkey-type.com/tribe" + MP.room.id.substring(4); + $(".pageTribe .lobby .inviteLink").text(link); swapElements($(".pageTribe .prelobby"), $(".pageTribe .lobby"), 250, () => {MP.state = 10}); } }) @@ -103,6 +119,8 @@ MP.socket.on('mp_chat_message', data => { $(".pageTribe .lobby .chat .messages").append(`
${author}${data.message}
`); + let chatEl = $(".pageTribe .lobby .chat .messages"); + chatEl.animate({ scrollTop: $($(".pageTribe .lobby .chat .message")[0]).outerHeight() * 2 * $(".pageTribe .lobby .chat .messages .message").length }, 0); }) MP.socket.on('mp_system_message', data => {