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

89 lines
2.5 KiB
JavaScript
Raw Normal View History

2026-01-06 16:23:17 +02:00
import Modal from 'src/components/modal/modal.vue'
2026-01-29 20:40:00 +02:00
import { useInstanceStore } from 'src/stores/instance.js'
2025-03-23 20:03:25 +02:00
import { useServerSideStorageStore } from 'src/stores/serverSideStorage'
2026-01-29 20:40:00 +02:00
import pleromaTanFoxMask from 'src/assets/pleromatan_apology_fox_mask.png'
import pleromaTanMask from 'src/assets/pleromatan_apology_mask.png'
2026-01-08 17:26:52 +02:00
import { library } from '@fortawesome/fontawesome-svg-core'
import { faTimes } from '@fortawesome/free-solid-svg-icons'
2026-01-06 16:22:52 +02:00
library.add(faTimes)
2022-08-02 00:37:48 +03:00
2022-08-04 22:09:42 +03:00
export const CURRENT_UPDATE_COUNTER = 1
2022-08-04 01:56:52 +03:00
2025-02-28 10:52:04 -05:00
const pleromaTan = '/static/pleromatan_apology.png'
const pleromaTanFox = '/static/pleromatan_apology_fox.png'
2022-08-04 01:56:52 +03:00
const UpdateNotification = {
2026-01-06 16:22:52 +02:00
data() {
2022-08-02 00:37:48 +03:00
return {
showingImage: false,
2022-08-04 01:56:52 +03:00
pleromaTanVariant: Math.random() > 0.5 ? pleromaTan : pleromaTanFox,
2026-01-06 16:22:52 +02:00
showingMore: false,
2022-08-02 00:37:48 +03:00
}
},
components: {
2026-01-06 16:22:52 +02:00
Modal,
2022-08-04 01:56:52 +03:00
},
computed: {
2026-01-06 16:22:52 +02:00
pleromaTanStyles() {
const mask =
this.pleromaTanVariant === pleromaTan
? pleromaTanMask
: pleromaTanFoxMask
2022-08-04 01:56:52 +03:00
return {
2026-01-06 16:22:52 +02:00
'shape-outside': 'url(' + mask + ')',
2022-08-04 01:56:52 +03:00
}
},
2026-01-06 16:22:52 +02:00
shouldShow() {
return (
!useInstanceStore().disableUpdateNotification &&
2022-08-08 02:14:09 +03:00
this.$store.state.users.currentUser &&
2026-01-06 16:22:52 +02:00
useServerSideStorageStore().flagStorage.updateCounter <
CURRENT_UPDATE_COUNTER &&
2025-03-23 20:03:25 +02:00
!useServerSideStorageStore().prefsStorage.simple.dontShowUpdateNotifs
2026-01-06 16:22:52 +02:00
)
},
2022-08-04 01:56:52 +03:00
},
methods: {
2026-01-06 16:22:52 +02:00
toggleShow() {
2022-08-04 01:56:52 +03:00
this.showingMore = !this.showingMore
},
2026-01-06 16:22:52 +02:00
neverShowAgain() {
2022-08-04 02:12:04 +03:00
this.toggleShow()
2026-01-06 16:22:52 +02:00
useServerSideStorageStore().setFlag({
flag: 'updateCounter',
value: CURRENT_UPDATE_COUNTER,
})
useServerSideStorageStore().setPreference({
path: 'simple.dontShowUpdateNotifs',
value: true,
})
2025-03-23 20:03:25 +02:00
useServerSideStorageStore().pushServerSideStorage()
2022-08-04 01:56:52 +03:00
},
2026-01-06 16:22:52 +02:00
dismiss() {
useServerSideStorageStore().setFlag({
flag: 'updateCounter',
value: CURRENT_UPDATE_COUNTER,
})
2025-03-23 20:03:25 +02:00
useServerSideStorageStore().pushServerSideStorage()
2026-01-06 16:22:52 +02:00
},
2022-08-04 01:56:52 +03:00
},
2026-01-06 16:22:52 +02:00
mounted() {
this.contentHeightNoImage = this.$refs.animatedText.scrollHeight
// Workaround to get the text height only after mask loaded. A bit hacky.
const newImg = new Image()
newImg.onload = () => {
2026-01-06 16:22:52 +02:00
setTimeout(() => {
this.showingImage = true
}, 100)
}
2026-01-06 16:22:52 +02:00
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