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

56 lines
1.2 KiB
JavaScript
Raw Normal View History

2022-03-17 19:54:52 +01:00
import { mapState } from 'vuex'
import Announcement from '../announcement/announcement.vue'
2022-03-17 21:51:32 +01:00
import AnnouncementEditor from '../announcement_editor/announcement_editor.vue'
const AnnouncementsPage = {
components: {
Announcement,
2022-03-17 21:51:32 +01:00
AnnouncementEditor
},
2022-03-17 19:54:52 +01:00
data () {
return {
newAnnouncement: {
content: '',
startsAt: undefined,
endsAt: undefined,
allDay: false
2022-03-17 19:54:52 +01:00
},
posting: false,
error: undefined
}
},
2022-03-17 19:01:45 +01:00
mounted () {
this.$store.dispatch('fetchAnnouncements')
},
computed: {
2022-03-17 19:54:52 +01:00
...mapState({
currentUser: state => state.users.currentUser
}),
announcements () {
2022-03-17 19:01:45 +01:00
return this.$store.state.announcements.announcements
}
2022-03-17 19:54:52 +01:00
},
methods: {
postAnnouncement () {
this.posting = true
this.$store.dispatch('postAnnouncement', this.newAnnouncement)
.then(() => {
this.newAnnouncement.content = ''
this.startsAt = undefined
this.endsAt = undefined
})
2022-03-17 19:54:52 +01:00
.catch(error => {
this.error = error.error
})
.finally(() => {
this.posting = false
})
},
clearError () {
this.error = undefined
}
}
}
export default AnnouncementsPage