From a765d226b8c0dc86b2369bcf14e1b9340413f223 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Wed, 16 Jun 2021 11:26:39 +0200 Subject: [PATCH] Refactor default image wrapper Signed-off-by: Thomas Citharel --- js/src/components/Image/LazyImageWrapper.vue | 33 +++++++++++++------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/js/src/components/Image/LazyImageWrapper.vue b/js/src/components/Image/LazyImageWrapper.vue index 7c27f44b6..2c6f8a544 100644 --- a/js/src/components/Image/LazyImageWrapper.vue +++ b/js/src/components/Image/LazyImageWrapper.vue @@ -12,27 +12,38 @@ import { IMedia } from "@/types/media.model"; import { Component, Prop, Vue } from "vue-property-decorator"; import LazyImage from "../Image/LazyImage.vue"; +const DEFAULT_CARD_URL = "/img/mobilizon_default_card.png"; +const DEFAULT_BLURHASH = "MCHKI4El-P-U}+={R-WWoes,Iu-P=?R,xD"; +const DEFAULT_WIDTH = 630; +const DEFAULT_HEIGHT = 350; +const DEFAULT_PICTURE = { + url: DEFAULT_CARD_URL, + metadata: { + width: DEFAULT_WIDTH, + height: DEFAULT_HEIGHT, + blurhash: DEFAULT_BLURHASH, + }, +}; + @Component({ components: { LazyImage, }, }) export default class LazyImageWrapper extends Vue { - @Prop({ required: true, default: null }) - picture!: IMedia | null; + @Prop({ required: true }) + picture!: IMedia; get pictureOrDefault(): Partial { + if (this.picture === null) { + return DEFAULT_PICTURE; + } return { - url: - this?.picture === null - ? "/img/mobilizon_default_card.png" - : this?.picture?.url, + url: this?.picture?.url, metadata: { - width: this?.picture?.metadata?.width || 630, - height: this?.picture?.metadata?.height || 350, - blurhash: - this?.picture?.metadata?.blurhash || - "MCHKI4El-P-U}+={R-WWoes,Iu-P=?R,xD", + width: this?.picture?.metadata?.width, + height: this?.picture?.metadata?.height, + blurhash: this?.picture?.metadata?.blurhash, }, }; }