From 759e69ed072e5b653fe6f755e35a6c0b20e397bb Mon Sep 17 00:00:00 2001 From: Pavel Djundik Date: Mon, 1 Oct 2018 17:08:46 +0300 Subject: [PATCH] Handle default preview state after loading --- client/components/LinkPreview.vue | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/client/components/LinkPreview.vue b/client/components/LinkPreview.vue index 965c5f75..56548748 100644 --- a/client/components/LinkPreview.vue +++ b/client/components/LinkPreview.vue @@ -138,12 +138,12 @@ export default { }, watch: { "link.type"() { + this.updateShownState(); this.onPreviewUpdate(); }, }, created() { - const shouldOpenByDefault = this.link.type === "link" ? this.$root.settings.links : this.$root.settings.media; - this.link.shown = this.link.shown && shouldOpenByDefault; + this.updateShownState(); }, mounted() { this.$root.$on("resize", this.handleResize); @@ -204,6 +204,28 @@ export default { this.showMoreButton = this.$refs.content.offsetWidth >= this.$refs.container.offsetWidth; }); }, + updateShownState() { + let defaultState = true; + + switch (this.link.type) { + case "error": + defaultState = this.link.error === "image-too-big" ? this.$root.settings.media : this.$root.settings.links; + break; + + case "loading": + defaultState = false; + break; + + case "link": + defaultState = this.$root.settings.links; + break; + + default: + defaultState = this.$root.settings.media; + } + + this.link.shown = this.link.shown && defaultState; + }, }, };