Add connected state
This commit is contained in:
parent
3300276c27
commit
a229138ca6
@ -45,19 +45,16 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="chat-content">
|
<div class="chat-content">
|
||||||
<div class="chat">
|
<div class="chat">
|
||||||
<div
|
<div class="show-more">
|
||||||
v-if="channel.messages.length > 0"
|
|
||||||
ref="loadMoreButton"
|
|
||||||
:disabled="channel.historyLoading"
|
|
||||||
class="show-more show"
|
|
||||||
@click="onShowMoreClick"
|
|
||||||
>
|
|
||||||
<button
|
<button
|
||||||
v-if="channel.historyLoading"
|
ref="loadMoreButton"
|
||||||
class="btn">Loading…</button>
|
:disabled="channel.historyLoading || !$root.connected"
|
||||||
<button
|
class="btn"
|
||||||
v-else
|
@click="onShowMoreClick"
|
||||||
class="btn">Show older messages</button>
|
>
|
||||||
|
<span v-if="channel.historyLoading">Loading…</span>
|
||||||
|
<span v-else>Show older messages</span>
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<MessageList :channel="channel"/>
|
<MessageList :channel="channel"/>
|
||||||
</div>
|
</div>
|
||||||
|
@ -11,10 +11,12 @@
|
|||||||
v-model="channel.pendingMessage"
|
v-model="channel.pendingMessage"
|
||||||
:placeholder="getInputPlaceholder(channel)"
|
:placeholder="getInputPlaceholder(channel)"
|
||||||
:aria-label="getInputPlaceholder(channel)"
|
:aria-label="getInputPlaceholder(channel)"
|
||||||
|
:disabled="!$root.connected"
|
||||||
class="mousetrap"
|
class="mousetrap"
|
||||||
@keyup.enter="onSubmit"
|
@keyup.enter="onSubmit"
|
||||||
/>
|
/>
|
||||||
<span
|
<span
|
||||||
|
v-if="$root.connected"
|
||||||
id="submit-tooltip"
|
id="submit-tooltip"
|
||||||
class="tooltipped tooltipped-w tooltipped-no-touch"
|
class="tooltipped tooltipped-w tooltipped-no-touch"
|
||||||
aria-label="Send message">
|
aria-label="Send message">
|
||||||
|
@ -1080,7 +1080,6 @@ background on hover (unless active) */
|
|||||||
}
|
}
|
||||||
|
|
||||||
#chat .show-more {
|
#chat .show-more {
|
||||||
display: none;
|
|
||||||
padding: 10px;
|
padding: 10px;
|
||||||
padding-top: 15px;
|
padding-top: 15px;
|
||||||
padding-bottom: 0;
|
padding-bottom: 0;
|
||||||
|
@ -28,8 +28,8 @@ socket.on("init", function(data) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$("#connection-error").removeClass("shown");
|
$("#connection-error").removeClass("shown");
|
||||||
$(".show-more button, #input").prop("disabled", false);
|
|
||||||
$("#submit").show();
|
vueApp.connected = true;
|
||||||
|
|
||||||
if (lastMessageId < 0) {
|
if (lastMessageId < 0) {
|
||||||
if (data.token) {
|
if (data.token) {
|
||||||
|
@ -7,19 +7,12 @@ const {vueApp, findChannel} = require("../vue");
|
|||||||
|
|
||||||
socket.on("more", function(data) {
|
socket.on("more", function(data) {
|
||||||
let chan = $("#chat #chan-" + data.chan);
|
let chan = $("#chat #chan-" + data.chan);
|
||||||
const type = chan.data("type");
|
|
||||||
chan = chan.find(".messages");
|
chan = chan.find(".messages");
|
||||||
|
|
||||||
// get the scrollable wrapper around messages
|
// get the scrollable wrapper around messages
|
||||||
const scrollable = chan.closest(".chat");
|
const scrollable = chan.closest(".chat");
|
||||||
const heightOld = chan.height() - scrollable.scrollTop();
|
const heightOld = chan.height() - scrollable.scrollTop();
|
||||||
|
|
||||||
// If there are no more messages to show, just hide the button and do nothing else
|
|
||||||
if (!data.messages.length) {
|
|
||||||
scrollable.find(".show-more").removeClass("show");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const channel = findChannel(data.chan);
|
const channel = findChannel(data.chan);
|
||||||
|
|
||||||
if (!channel) {
|
if (!channel) {
|
||||||
|
@ -10,9 +10,10 @@ const socket = io({
|
|||||||
reconnection: !$(document.body).hasClass("public"),
|
reconnection: !$(document.body).hasClass("public"),
|
||||||
});
|
});
|
||||||
|
|
||||||
$("#connection-error").on("click", function() {
|
module.exports = socket;
|
||||||
$(this).removeClass("shown");
|
|
||||||
});
|
const {vueApp} = require("./vue");
|
||||||
|
const {requestIdleCallback} = require("./utils");
|
||||||
|
|
||||||
socket.on("disconnect", handleDisconnect);
|
socket.on("disconnect", handleDisconnect);
|
||||||
socket.on("connect_error", handleDisconnect);
|
socket.on("connect_error", handleDisconnect);
|
||||||
@ -42,17 +43,13 @@ socket.on("authorized", function() {
|
|||||||
function handleDisconnect(data) {
|
function handleDisconnect(data) {
|
||||||
const message = data.message || data;
|
const message = data.message || data;
|
||||||
|
|
||||||
|
vueApp.connected = false;
|
||||||
|
|
||||||
$("#loading-page-message, #connection-error").text(`Waiting to reconnect… (${message})`).addClass("shown");
|
$("#loading-page-message, #connection-error").text(`Waiting to reconnect… (${message})`).addClass("shown");
|
||||||
$(".show-more button, #input").prop("disabled", true);
|
|
||||||
$("#submit").hide();
|
|
||||||
$("#upload").hide();
|
|
||||||
|
|
||||||
// If the server shuts down, socket.io skips reconnection
|
// If the server shuts down, socket.io skips reconnection
|
||||||
// and we have to manually call connect to start the process
|
// and we have to manually call connect to start the process
|
||||||
if (socket.io.skipReconnect) {
|
if (socket.io.skipReconnect) {
|
||||||
const utils = require("./utils");
|
requestIdleCallback(() => socket.connect(), 2000);
|
||||||
utils.requestIdleCallback(() => socket.connect(), 2000);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = socket;
|
|
||||||
|
@ -21,6 +21,7 @@ Vue.filter("roundBadgeNumber", roundBadgeNumber);
|
|||||||
const vueApp = new Vue({
|
const vueApp = new Vue({
|
||||||
el: "#viewport",
|
el: "#viewport",
|
||||||
data: {
|
data: {
|
||||||
|
connected: false,
|
||||||
appName: document.title,
|
appName: document.title,
|
||||||
activeChannel: null,
|
activeChannel: null,
|
||||||
networks: [],
|
networks: [],
|
||||||
|
Loading…
Reference in New Issue
Block a user