aboutsummaryrefslogtreecommitdiff
path: root/src/components/sticker_picker/sticker_picker.js
blob: b06384e5f18003cdeea8d227e59a09219e869192 (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
44
45
46
47
48
49
50
51
52
/* eslint-env browser */
import statusPosterService from '../../services/status_poster/status_poster.service.js'
import TabSwitcher from '../tab_switcher/tab_switcher.jsx'

const StickerPicker = {
  components: {
    TabSwitcher
  },
  data () {
    return {
      meta: {
        stickers: []
      },
      path: ''
    }
  },
  computed: {
    pack () {
      return this.$store.state.instance.stickers || []
    }
  },
  methods: {
    clear () {
      this.meta = {
        stickers: []
      }
    },
    pick (sticker, name) {
      const store = this.$store
      // TODO remove this workaround by finding a way to bypass reuploads
      fetch(sticker)
        .then((res) => {
          res.blob().then((blob) => {
            const file = new File([blob], name, { mimetype: 'image/png' })
            const formData = new FormData()
            formData.append('file', file)
            statusPosterService.uploadMedia({ store, formData })
              .then((fileData) => {
                this.$emit('uploaded', fileData)
                this.clear()
              }, (error) => {
                console.warn("Can't attach sticker")
                console.warn(error)
                this.$emit('upload-failed', 'default')
              })
          })
        })
    }
  }
}

export default StickerPicker