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)) return this.formatTimeOrDate(time, localeService.internalToBrowserLocale(this.$i18n.locale))
},
inactive () {
return this.announcement.inactive
} }
}, },
methods: { methods: {

View File

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

View File

@ -12,11 +12,13 @@ export const mutations = {
set(state, 'announcements', announcements) set(state, 'announcements', announcements)
}, },
setAnnouncementRead (state, { id, read }) { setAnnouncementRead (state, { id, read }) {
if (!state.announcements[id]) { const index = state.announcements.findIndex(a => a.id === id)
if (index < 0) {
return return
} }
set(state.announcements[id], 'read', read) set(state.announcements[index], 'read', read)
}, },
setFetchAnnouncementsTimer (state, timer) { setFetchAnnouncementsTimer (state, timer) {
set(state, 'fetchAnnouncementsTimer', announcements) set(state, 'fetchAnnouncementsTimer', announcements)
@ -31,9 +33,30 @@ const announcements = {
const currentUser = store.rootState.users.currentUser const currentUser = store.rootState.users.currentUser
const isAdmin = currentUser && currentUser.role === 'admin' const isAdmin = currentUser && currentUser.role === 'admin'
return (isAdmin const getAnnouncements = async () => {
? store.rootState.api.backendInteractor.adminFetchAnnouncements() if (!isAdmin) {
: store.rootState.api.backendInteractor.fetchAnnouncements()) 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 => { .then(announcements => {
store.commit('setAnnouncements', announcements) store.commit('setAnnouncements', announcements)
}) })