aboutsummaryrefslogtreecommitdiff
path: root/src/components/link-preview/link-preview.js
blob: 444aafbe879076fe1a9499562797e4d10c886df3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
const LinkPreview = {
  name: 'LinkPreview',
  props: [
    'card',
    'size',
    'nsfw'
  ],
  data () {
    return {
      imageLoaded: false
    }
  },
  computed: {
    useImage () {
      // Currently BE shoudn't give cards if tagged NSFW, this is a bit paranoid
      // as it makes sure to hide the image if somehow NSFW tagged preview can
      // exist.
      return this.card.image && !this.nsfw && this.size !== 'hide'
    },
    useDescription () {
      return this.card.description && /\S/.test(this.card.description)
    }
  },
  created () {
    if (this.useImage) {
      const newImg = new Image()
      newImg.onload = () => {
        this.imageLoaded = true
      }
      newImg.src = this.card.image
    }
  }
}

export default LinkPreview