aboutsummaryrefslogtreecommitdiff
path: root/src/components/status_popover/status_popover.js
blob: 91b64f72fc979498d4f66677325eb14fa2b83179 (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
36
37
38
39
40
41
42
43
import { find } from 'lodash'

const StatusPopover = {
  name: 'StatusPopover',
  props: [
    'statusId'
  ],
  data () {
    return {
      preview: null,
      popperOptions: {
        modifiers: {
          preventOverflow: { padding: { top: 50 }, boundariesElement: 'viewport' }
        }
      }
    }
  },
  components: {
    Status: () => import('../status/status.vue')
  },
  methods: {
    enter () {
      const id = this.statusId
      const statuses = this.$store.state.statuses.allStatuses

      if (!this.preview) {
        // if we have the status somewhere already
        this.preview = find(statuses, { id })
        // or if we have to fetch it
        if (!this.preview) {
          this.$store.state.api.backendInteractor.fetchStatus({ id }).then((status) => {
            this.preview = status
            this.$nextTick(this.$refs.popper.updatePopper)
          })
        }
      } else if (this.preview.id !== id) {
        this.preview = find(statuses, 'id')
      }
    }
  }
}

export default StatusPopover