Update notifications page

- display more notifications by simplifying the table
- get sorting working
This commit is contained in:
mattwr18 2019-10-22 14:40:10 +02:00
parent 7cdc12f4b9
commit b79770469f
9 changed files with 71 additions and 90 deletions

View File

@ -13,7 +13,9 @@
<notification-list :notifications="displayedNotifications" @markAsRead="markAsRead" /> <notification-list :notifications="displayedNotifications" @markAsRead="markAsRead" />
</div> </div>
<ds-space centered> <ds-space centered>
<nuxt-link to="/notifications">{{ $t('notifications.page') }}</nuxt-link> <nuxt-link to="/notifications">
{{ $t('notifications.page') }}
</nuxt-link>
</ds-space> </ds-space>
</template> </template>
</dropdown> </dropdown>
@ -35,6 +37,7 @@ export default {
return { return {
displayedNotifications: [], displayedNotifications: [],
notifications: [], notifications: [],
nofiticationRead: null,
} }
}, },
props: { props: {
@ -75,15 +78,24 @@ export default {
} }
return countUnread return countUnread
}, },
updateNotifications() {
return this.notificationRead
},
}, },
apollo: { apollo: {
notifications: { notifications: {
query() { query() {
return notificationQuery(this.$i18n) return notificationQuery(this.$i18n)
}, },
variables() {
return {
read: false,
orderBy: 'updatedAt_desc',
}
},
pollInterval: NOTIFICATIONS_POLL_INTERVAL, pollInterval: NOTIFICATIONS_POLL_INTERVAL,
update(data) { update({ notifications }) {
const newNotifications = data.notifications.filter(newN => { const newNotifications = notifications.filter(newN => {
return !this.displayedNotifications.find(oldN => this.equalNotification(newN, oldN)) return !this.displayedNotifications.find(oldN => this.equalNotification(newN, oldN))
}) })
this.displayedNotifications = newNotifications this.displayedNotifications = newNotifications
@ -91,7 +103,7 @@ export default {
.sort((a, b) => { .sort((a, b) => {
return new Date(b.createdAt) - new Date(a.createdAt) return new Date(b.createdAt) - new Date(a.createdAt)
}) })
return data.notifications return notifications
}, },
error(error) { error(error) {
this.$toast.error(error.message) this.$toast.error(error.message)

View File

@ -51,8 +51,8 @@ export const notificationQuery = i18n => {
${commentFragment(lang)} ${commentFragment(lang)}
${postFragment(lang)} ${postFragment(lang)}
query { query($read: Boolean, $orderBy: NotificationOrdering) {
notifications(orderBy: updatedAt_desc) { notifications(read: $read, orderBy: $orderBy) {
read read
reason reason
createdAt createdAt

View File

@ -182,7 +182,7 @@
"createdAt": "Notification created at", "createdAt": "Notification created at",
"type": "Type", "type": "Type",
"user": "User", "user": "User",
"action": "Action" "content": "Content"
}, },
"search": { "search": {
"placeholder": "Search", "placeholder": "Search",

View File

@ -14,7 +14,7 @@
@click.prevent="toggleMenu()" @click.prevent="toggleMenu()"
> >
<ds-icon style="margin-right: 2px;" name="sort" /> <ds-icon style="margin-right: 2px;" name="sort" />
{{ 'All' }} {{ selected }}
<ds-icon style="margin-left: 2px" size="xx-small" name="angle-down" /> <ds-icon style="margin-left: 2px" size="xx-small" name="angle-down" />
</a> </a>
<ds-menu <ds-menu
@ -29,9 +29,9 @@
class="locale-menu-item" class="locale-menu-item"
:route="item.route" :route="item.route"
:parents="item.parents" :parents="item.parents"
@click.stop.prevent="sortNotifications(item.route.option, toggleMenu)" @click.stop.prevent="sortNotifications(item.route, toggleMenu)"
> >
{{ item.route.option }} {{ item.route.label }}
</ds-menu-item> </ds-menu-item>
</ds-menu> </ds-menu>
</dropdown> </dropdown>
@ -39,51 +39,12 @@
</ds-flex> </ds-flex>
<ds-space /> <ds-space />
<ds-table <ds-table
v-if="notifications && notifications.length" v-if="selectedNotifications && selectedNotifications.length"
:data="notifications" :data="selectedNotifications"
:fields="fields" :fields="fields"
id="notifications-table" class="notifications-table"
> >
<template slot="notifications" slot-scope="scope"> <template slot="user" slot-scope="scope">
<ds-space :class="{ read: scope.row.read, notification: true }" margin="small">
<client-only>
<ds-space margin-bottom="x-small">
<hc-user
:user="scope.row.from.author"
:date-time="scope.row.from.createdAt"
:trunc="35"
/>
</ds-space>
<ds-text class="reason-text-for-test" color="soft">
{{ $t(`notifications.reason.${scope.row.reason}`) }}
</ds-text>
</client-only>
<ds-space margin-bottom="x-small" />
<nuxt-link
class="notification-mention-post"
:to="{ name: 'post-id-slug', params, ...hashParam }"
@click.native="$emit('read')"
>
<ds-space margin-bottom="x-small">
<ds-card
:header="scope.row.from.title || scope.row.from.post.title"
hover
space="x-small"
class="notifications-card"
>
<ds-space margin-bottom="x-small" />
<div>
<span v-if="isComment" class="comment-notification-header">
{{ $t(`notifications.comment`) }}:
</span>
{{ scope.row.from.contentExcerpt | removeHtml }}
</div>
</ds-card>
</ds-space>
</nuxt-link>
</ds-space>
</template>
<!-- <template slot="user" slot-scope="scope">
<ds-space margin-bottom="base"> <ds-space margin-bottom="base">
<hc-user <hc-user
:user="scope.row.from.author" :user="scope.row.from.author"
@ -93,30 +54,31 @@
</ds-space> </ds-space>
{{ $t(`notifications.reason.${scope.row.reason}`) }} {{ $t(`notifications.reason.${scope.row.reason}`) }}
</template> </template>
<template slot="type" slot-scope="scope"> <template slot="post" slot-scope="scope">
<nuxt-link <nuxt-link
class="notification-mention-post" class="notification-mention-post"
:to="{ name: 'post-id-slug', params, ...hashParam }" :to="{
name: 'post-id-slug',
params: {
id:
scope.row.from.__typename === 'Comment'
? scope.row.from.post.id
: scope.row.from.id,
slug:
scope.row.from.__typename === 'Comment'
? scope.row.from.post.slug
: scope.row.from.slug,
},
hash: scope.row.from.__typename === 'Comment' ? `#commentId-${scope.row.from.id}` : {},
}"
@click.native="$emit('read')" @click.native="$emit('read')"
> >
<ds-space margin-bottom="x-small"> <b>{{ scope.row.from.title || scope.row.from.post.title | truncate(50) }}</b>
<ds-card
:header="scope.row.from.title || scope.row.from.post.title"
hover
space="x-small"
class="notifications-card"
>
<ds-space margin-bottom="x-small" />
<div>
<span v-if="isComment" class="comment-notification-header">
{{ $t(`notifications.comment`) }}:
</span>
{{ scope.row.from.contentExcerpt | removeHtml }}
</div>
</ds-card>
</ds-space>
</nuxt-link> </nuxt-link>
</template> --> </template>
<template slot="content" slot-scope="scope">
<b>{{ scope.row.from.contentExcerpt || scope.row.from.contentExcerpt | removeHtml }}</b>
</template>
</ds-table> </ds-table>
<hc-empty v-else icon="alert" :message="$t('moderation.reports.empty')" /> <hc-empty v-else icon="alert" :message="$t('moderation.reports.empty')" />
</ds-card> </ds-card>
@ -136,23 +98,29 @@ export default {
}, },
data() { data() {
return { return {
notifications: [], selectedNotifications: [],
sortingOptions: ['All', 'Read', 'Unread'], selected: 'All',
sortingOptions: [
{ label: 'All', value: null },
{ label: 'Read', value: true },
{ label: 'Unread', value: false },
],
nofiticationRead: null, nofiticationRead: null,
} }
}, },
computed: { computed: {
fields() { fields() {
return { return {
notifications: null, user: this.$t('notifications.user'),
// user: this.$t('notifications.user'), post: this.$t('notifications.type'),
// type: this.$t('notifications.type'), content: this.$t('notifications.content'),
} }
}, },
routes() { routes() {
let routes = this.sortingOptions.map(option => { let routes = this.sortingOptions.map(option => {
return { return {
option, label: option.label,
value: option.value,
} }
}) })
return routes return routes
@ -160,24 +128,25 @@ export default {
}, },
methods: { methods: {
sortNotifications(option, toggleMenu) { sortNotifications(option, toggleMenu) {
if (option === 'Read') { this.notificationRead = option.value
this.notificationRead = true this.selected = option.label
} else if (option === 'Unread') { this.$apollo.queries.notifications.refresh()
this.notificationRead = false
} else {
this.notificationRead = null
}
this.$apollo.queries.notificationsPage.refetch()
toggleMenu() toggleMenu()
}, },
}, },
apollo: { apollo: {
notificationsPage: { notifications: {
query() { query() {
return notificationQuery(this.$i18n) return notificationQuery(this.$i18n)
}, },
variables() {
return {
read: this.notificationRead,
orderBy: 'updatedAt_desc',
}
},
update({ notifications }) { update({ notifications }) {
this.notifications = notifications this.selectedNotifications = notifications
}, },
fetchPolicy: 'cache-and-network', fetchPolicy: 'cache-and-network',
error(error) { error(error) {
@ -191,7 +160,7 @@ export default {
.sorting-dropdown { .sorting-dropdown {
float: right; float: right;
} }
#notifications-table thead { .notifications-table td {
display: none; width: 500px;
} }
</style> </style>