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

65 lines
1.5 KiB
JavaScript
Raw Normal View History

2022-03-17 15:07:04 -04:00
import { mapState } from 'vuex'
2022-03-17 16:51:32 -04:00
import AnnouncementEditor from '../announcement_editor/announcement_editor.vue'
import localeService from '../../services/locale/locale.service.js'
const Announcement = {
2022-03-17 16:51:32 -04:00
components: {
AnnouncementEditor
},
data () {
return {
editing: false,
newAnnouncement: {
content: '',
startsAt: undefined,
endsAt: undefined
}
}
},
props: {
announcement: Object
},
computed: {
2022-03-17 15:07:04 -04:00
...mapState({
currentUser: state => state.users.currentUser
}),
content () {
return this.announcement.content
2022-03-17 14:01:45 -04:00
},
isRead () {
return this.announcement.read
2022-03-17 16:51:32 -04:00
},
startsAt () {
const time = this.announcement['starts_at']
if (!time) {
return
}
return this.formatTimeOrDate(time, localeService.internalToBrowserLocale(this.$i18n.locale))
},
endsAt () {
const time = this.announcement['ends_at']
if (!time) {
return
}
return this.formatTimeOrDate(time, localeService.internalToBrowserLocale(this.$i18n.locale))
2022-03-17 14:01:45 -04:00
}
},
methods: {
markAsRead () {
if (!this.isRead) {
return this.$store.dispatch('markAnnouncementAsRead', this.announcement.id)
}
2022-03-17 15:07:04 -04:00
},
deleteAnnouncement () {
return this.$store.dispatch('deleteAnnouncement', this.announcement.id)
2022-03-17 16:51:32 -04:00
},
formatTimeOrDate (time, locale) {
const d = new Date(time)
return this.announcement['all_day'] ? d.toLocaleDateString(locale) : d.toLocaleString(locale)
}
}
}
export default Announcement