Mark inactive and active announcements for admin

This commit is contained in:
Tusooa Zhu 2022-03-17 17:32:16 -04:00 committed by tusooa
parent 1972e57ceb
commit 458ce54143
No known key found for this signature in database
GPG Key ID: 7B467EDE43A08224
3 changed files with 33 additions and 5 deletions

View File

@ -46,6 +46,9 @@ const Announcement = {
}
return this.formatTimeOrDate(time, localeService.internalToBrowserLocale(this.$i18n.locale))
},
inactive () {
return this.announcement.inactive
}
},
methods: {

View File

@ -35,6 +35,8 @@
v-if="currentUser"
class="btn button-default"
:class="{ toggled: isRead }"
:disabled="inactive"
:title="inactive ? $t('announcements.inactive_message') : ''"
@click="markAsRead"
>
{{ $t('announcements.mark_as_read_action') }}

View File

@ -12,11 +12,13 @@ export const mutations = {
set(state, 'announcements', announcements)
},
setAnnouncementRead (state, { id, read }) {
if (!state.announcements[id]) {
const index = state.announcements.findIndex(a => a.id === id)
if (index < 0) {
return
}
set(state.announcements[id], 'read', read)
set(state.announcements[index], 'read', read)
},
setFetchAnnouncementsTimer (state, timer) {
set(state, 'fetchAnnouncementsTimer', announcements)
@ -31,9 +33,30 @@ const announcements = {
const currentUser = store.rootState.users.currentUser
const isAdmin = currentUser && currentUser.role === 'admin'
return (isAdmin
? store.rootState.api.backendInteractor.adminFetchAnnouncements()
: store.rootState.api.backendInteractor.fetchAnnouncements())
const getAnnouncements = async () => {
if (!isAdmin) {
return store.rootState.api.backendInteractor.fetchAnnouncements()
}
const all = await store.rootState.api.backendInteractor.adminFetchAnnouncements()
const visible = await store.rootState.api.backendInteractor.fetchAnnouncements()
const visibleObject = visible.reduce((a, c) => {
a[c.id] = c
return a
}, {})
all.forEach(announcement => {
if (!visibleObject[announcement.id]) {
announcement.inactive = true
} else {
announcement.read = visibleObject[announcement.id].read
}
})
return all
}
return getAnnouncements()
.then(announcements => {
store.commit('setAnnouncements', announcements)
})