Merge pull request #6116 from Ocelot-Social-Community/6016-feature-refactor-notification-page

feat(webapp): refactor notification page
This commit is contained in:
Wolfgang Huß 2023-03-14 20:21:03 +01:00 committed by GitHub
commit e36af318ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 131 additions and 50 deletions

View File

@ -59,8 +59,8 @@ describe('NotificationsTable.vue', () => {
wrapper = Wrapper() wrapper = Wrapper()
}) })
it('renders a table', () => { it('renders a grid table', () => {
expect(wrapper.find('.ds-table').exists()).toBe(true) expect(wrapper.find('.notification-grid').exists()).toBe(true)
}) })
describe('renders 4 columns', () => { describe('renders 4 columns', () => {
@ -84,7 +84,7 @@ describe('NotificationsTable.vue', () => {
describe('Post', () => { describe('Post', () => {
let firstRowNotification let firstRowNotification
beforeEach(() => { beforeEach(() => {
firstRowNotification = wrapper.findAll('tbody tr').at(0) firstRowNotification = wrapper.findAll('.notification-grid-row').at(0)
}) })
it('renders the author', () => { it('renders the author', () => {
@ -117,7 +117,7 @@ describe('NotificationsTable.vue', () => {
describe('Comment', () => { describe('Comment', () => {
let secondRowNotification let secondRowNotification
beforeEach(() => { beforeEach(() => {
secondRowNotification = wrapper.findAll('tbody tr').at(1) secondRowNotification = wrapper.findAll('.notification-grid-row').at(1)
}) })
it('renders the author', () => { it('renders the author', () => {

View File

@ -1,62 +1,108 @@
<template> <template>
<ds-table v-if="notifications && notifications.length" :data="notifications" :fields="fields"> <div class="notification-grid" v-if="notifications && notifications.length">
<template #icon="scope"> <ds-grid>
<base-icon <ds-grid-item v-if="!isMobile" column-span="fullWidth">
v-if="scope.row.from.post" <ds-grid class="header-grid">
name="comment" <ds-grid-item v-for="field in fields" :key="field.label" class="ds-table-head-col">
v-tooltip="{ content: $t('notifications.comment'), placement: 'right' }" {{ field.label }}
/> </ds-grid-item>
<base-icon </ds-grid>
v-else </ds-grid-item>
name="bookmark" <ds-grid-item
v-tooltip="{ content: $t('notifications.post'), placement: 'right' }" v-for="notification in notifications"
/> :key="notification.id"
</template> column-span="fullWidth"
<template #user="scope"> class="notification-grid-row"
<ds-space margin-bottom="base">
<client-only>
<user-teaser
:user="scope.row.from.author"
:date-time="scope.row.from.createdAt"
:class="{ 'notification-status': scope.row.read }"
/>
</client-only>
</ds-space>
<ds-text :class="{ 'notification-status': scope.row.read, reason: true }">
{{ $t(`notifications.reason.${scope.row.reason}`) }}
</ds-text>
</template>
<template #post="scope">
<nuxt-link
class="notification-mention-post"
:class="{ 'notification-status': scope.row.read }"
:to="{
name: 'post-id-slug',
params: params(scope.row.from),
hash: hashParam(scope.row.from),
}"
@click.native="markNotificationAsRead(scope.row.from.id)"
> >
<b>{{ scope.row.from.title || scope.row.from.post.title | truncate(50) }}</b> <ds-grid>
</nuxt-link> <ds-grid-item>
</template> <ds-flex class="user-section">
<template #content="scope"> <ds-flex-item :width="{ base: '20%' }">
<b :class="{ 'notification-status': scope.row.read }"> <div>
{{ scope.row.from.contentExcerpt | removeHtml }} <base-card :wide-content="true">
</b> <base-icon
</template> v-if="notification.from.post"
</ds-table> name="comment"
v-tooltip="{ content: $t('notifications.comment'), placement: 'right' }"
/>
<base-icon
v-else
name="bookmark"
v-tooltip="{ content: $t('notifications.post'), placement: 'right' }"
/>
</base-card>
</div>
</ds-flex-item>
<ds-flex-item>
<div>
<base-card :wide-content="true">
<ds-space margin-bottom="base">
<client-only>
<user-teaser
:user="notification.from.author"
:date-time="notification.from.createdAt"
:class="{ 'notification-status': notification.read }"
/>
</client-only>
</ds-space>
<ds-text :class="{ 'notification-status': notification.read, reason: true }">
{{ $t(`notifications.reason.${notification.reason}`) }}
</ds-text>
</base-card>
</div>
</ds-flex-item>
</ds-flex>
</ds-grid-item>
<ds-grid-item>
<ds-flex class="content-section" :direction="{ base: 'column', xs: 'row' }">
<ds-flex-item>
<base-card :wide-content="true">
<nuxt-link
class="notification-mention-post"
:class="{ 'notification-status': notification.read }"
:to="{
name: 'post-id-slug',
params: params(notification.from),
hash: hashParam(notification.from),
}"
@click.native="markNotificationAsRead(notification.from.id)"
>
<b>
{{ notification.from.title || notification.from.post.title | truncate(50) }}
</b>
</nuxt-link>
</base-card>
</ds-flex-item>
<ds-flex-item>
<base-card :wide-content="true">
<b :class="{ 'notification-status': notification.read }">
{{ notification.from.contentExcerpt | removeHtml }}
</b>
</base-card>
</ds-flex-item>
</ds-flex>
</ds-grid-item>
</ds-grid>
</ds-grid-item>
</ds-grid>
</div>
<hc-empty v-else icon="alert" :message="$t('notifications.empty')" /> <hc-empty v-else icon="alert" :message="$t('notifications.empty')" />
</template> </template>
<script> <script>
import UserTeaser from '~/components/UserTeaser/UserTeaser' import UserTeaser from '~/components/UserTeaser/UserTeaser'
import HcEmpty from '~/components/Empty/Empty' import HcEmpty from '~/components/Empty/Empty'
import BaseCard from '../_new/generic/BaseCard/BaseCard.vue'
import mobile from '~/mixins/mobile'
const maxMobileWidth = 768 // at this point the table breaks down
export default { export default {
components: { components: {
UserTeaser, UserTeaser,
HcEmpty, HcEmpty,
BaseCard,
}, },
mixins: [mobile(maxMobileWidth)],
props: { props: {
notifications: { type: Array, default: () => [] }, notifications: { type: Array, default: () => [] },
}, },
@ -106,4 +152,39 @@ export default {
.notification-status { .notification-status {
opacity: $opacity-soft; opacity: $opacity-soft;
} }
/* fix to override flex-wrap style of ds flex component */
.notification-grid .content-section {
flex-wrap: nowrap;
}
.notification-grid .ds-grid.header-grid {
grid-template-columns: 1fr 4fr 3fr 3fr !important;
}
.notification-grid-row {
border-top: 1px dotted #e5e3e8;
}
.notification-grid .base-card {
border-radius: 0;
box-shadow: none;
padding: 16px 4px;
}
/* dirty fix to override broken styleguide inline-styles */
.notification-grid .ds-grid {
grid-template-columns: 5fr 6fr !important;
grid-auto-rows: auto !important;
grid-template-rows: 1fr;
gap: 0px !important;
}
@media screen and (max-width: 768px) {
.notification-grid .ds-grid {
grid-template-columns: 1fr !important;
}
.notification-grid .content-section {
border-top: 1px dotted #e5e3e8;
}
.notification-grid-row {
box-shadow: 0px 12px 26px -4px rgb(0 0 0 / 10%);
margin-top: 5px;
border-top: none;
}
}
</style> </style>