pleroma-fe/src/components/update_notification/update_notification.js

74 lines
2.3 KiB
JavaScript
Raw Normal View History

2022-08-02 00:37:48 +03:00
import Modal from 'src/components/modal/modal.vue'
import { library } from '@fortawesome/fontawesome-svg-core'
import pleromaTan from 'src/assets/pleromatan_apology.png'
import pleromaTanFox from 'src/assets/pleromatan_apology_fox.png'
import pleromaTanMask from 'src/assets/pleromatan_apology_mask.png'
import pleromaTanFoxMask from 'src/assets/pleromatan_apology_fox_mask.png'
2022-08-02 00:37:48 +03:00
import {
faTimes
} from '@fortawesome/free-solid-svg-icons'
library.add(
faTimes
)
2022-08-04 22:09:42 +03:00
export const CURRENT_UPDATE_COUNTER = 1
2022-08-04 01:56:52 +03:00
const UpdateNotification = {
2022-08-02 00:37:48 +03:00
data () {
return {
2022-08-04 01:56:52 +03:00
pleromaTanVariant: Math.random() > 0.5 ? pleromaTan : pleromaTanFox,
2022-08-04 02:12:04 +03:00
showingMore: false,
2022-08-04 01:56:52 +03:00
contentHeight: 0
2022-08-02 00:37:48 +03:00
}
},
components: {
Modal
2022-08-04 01:56:52 +03:00
},
computed: {
pleromaTanStyles () {
const mask = this.pleromaTanVariant === pleromaTan ? pleromaTanMask : pleromaTanFoxMask
2022-08-04 01:56:52 +03:00
return {
'shape-outside': 'url(' + mask + ')'
2022-08-04 01:56:52 +03:00
}
},
2022-08-08 12:17:32 +03:00
dynamicStyles () {
return {
'--____extraInfoGroupHeight': this.contentHeight + 'px'
}
},
2022-08-04 01:56:52 +03:00
shouldShow () {
return !this.$store.state.instance.disableUpdateNotification &&
2022-08-08 02:14:09 +03:00
this.$store.state.users.currentUser &&
this.$store.state.serverSideStorage.flagStorage.updateCounter < CURRENT_UPDATE_COUNTER &&
2022-08-04 01:56:52 +03:00
!this.$store.state.serverSideStorage.flagStorage.dontShowUpdateNotifs
}
},
methods: {
toggleShow () {
this.showingMore = !this.showingMore
},
neverShowAgain () {
2022-08-04 02:12:04 +03:00
this.toggleShow()
2022-08-04 22:09:42 +03:00
this.$store.commit('setFlag', { flag: 'updateCounter', value: CURRENT_UPDATE_COUNTER })
this.$store.commit('setFlag', { flag: 'dontShowUpdateNotifs', value: 1 })
this.$store.dispatch('pushServerSideStorage')
2022-08-04 01:56:52 +03:00
},
dismiss () {
this.$store.commit('setFlag', { flag: 'updateCounter', value: CURRENT_UPDATE_COUNTER })
2022-08-04 22:09:42 +03:00
this.$store.dispatch('pushServerSideStorage')
2022-08-04 01:56:52 +03:00
}
},
mounted () {
// Workaround to get the text height only after mask loaded. A bit hacky.
const newImg = new Image()
newImg.onload = () => {
setTimeout(() => {
this.contentHeight = this.$refs.animatedText.scrollHeight
}, 100)
}
newImg.src = this.pleromaTanVariant === pleromaTan ? pleromaTanMask : pleromaTanFoxMask
2022-08-02 00:37:48 +03:00
}
}
2022-08-04 01:56:52 +03:00
export default UpdateNotification