From c2ed3fae56ddf32a443f4b6abf2b95c21638641a Mon Sep 17 00:00:00 2001 From: Pavel Djundik Date: Mon, 25 Nov 2019 21:37:51 +0200 Subject: [PATCH] Improve link preview loading --- client/components/LinkPreview.vue | 52 +++++++++++++++++++++++-------- client/css/style.css | 4 +++ 2 files changed, 43 insertions(+), 13 deletions(-) diff --git a/client/components/LinkPreview.vue b/client/components/LinkPreview.vue index 9637760f..41692ae9 100644 --- a/client/components/LinkPreview.vue +++ b/client/components/LinkPreview.vue @@ -1,5 +1,11 @@ @@ -126,6 +149,10 @@ export default { return this.isContentShown ? "Less" : "More"; }, imageMaxSize() { + if (!this.link.maxSize) { + return; + } + return friendlysize(this.link.maxSize); }, }, @@ -149,7 +176,7 @@ export default { destroyed() { // Let this preview go through load/canplay events again, // Otherwise the browser can cause a resize on video elements - this.link.canDisplay = false; + this.link.sourceLoaded = false; }, methods: { onPreviewUpdate() { @@ -158,26 +185,25 @@ export default { return; } - // Error don't have any media to render + // Error does not have any media to render if (this.link.type === "error") { this.onPreviewReady(); } // If link doesn't have a thumbnail, render it - if (this.link.type === "link" && !this.link.thumb) { - this.onPreviewReady(); + if (this.link.type === "link") { + this.handleResize(); + this.keepScrollPosition(); } }, onPreviewReady() { - this.$set(this.link, "canDisplay", true); + this.$set(this.link, "sourceLoaded", true); this.keepScrollPosition(); - if (this.link.type !== "link") { - return; + if (this.link.type === "link") { + this.handleResize(); } - - this.handleResize(); }, onThumbnailError() { // If thumbnail fails to load, hide it and show the preview without it diff --git a/client/css/style.css b/client/css/style.css index 2d86edcc..2bc2fd03 100644 --- a/client/css/style.css +++ b/client/css/style.css @@ -1467,6 +1467,10 @@ background on hover (unless active) */ transform: rotate(90deg); } +#chat .preview { + display: flex; /* Fix odd margin added by inline-flex in .toggle-content */ +} + #chat .toggle-content { background: #f6f6f6; border-radius: 5px;