traxxx/assets/components/header/notifications.vue

280 lines
5.1 KiB
Vue
Raw Normal View History

2021-04-22 17:44:23 +00:00
<template>
<div
class="notifications"
>
<div class="notifications-header">
<h4 class="notifications-title">Notifications</h4>
<div class="notifications-actions">
<Icon
v-if="unseenNotifications.length > 0"
v-tooltip="'Mark all as seen'"
2021-04-22 17:44:23 +00:00
icon="checkmark"
@click="checkNotifications"
2021-04-22 17:44:23 +00:00
/>
<Icon
icon="plus3"
@click="showAddAlert = true"
/>
</div>
</div>
<AddAlert
v-if="showAddAlert"
@close="showAddAlert = false"
>Alert</AddAlert>
<div class="notifications-body">
<span
v-if="notifications.length === 0"
class="notifications-empty"
2021-04-22 17:44:23 +00:00
>No notifications</span>
<ul
v-else
class="nolist"
>
<li
v-for="notification in notifications"
:key="`notification-${notification.id}`"
:class="{ unseen: !notification.seen }"
2021-04-22 17:44:23 +00:00
class="notification"
@click="checkNotification(notification.id)"
2021-04-22 17:44:23 +00:00
>
<router-link
:to="`/scene/${notification.scene.id}/${notification.scene.slug}`"
class="notification-link"
>
<img
:src="getPath(notification.scene.poster, 'thumbnail')"
class="poster"
>
<div class="notification-body">
<div class="notification-row notification-title">
<img
v-if="notification.scene.entity.type === 'network' || notification.scene.entity.independent"
:src="`/img/logos/${notification.scene.entity.slug}/favicon_dark.png`"
class="notification-favicon"
>
<img
v-else
:src="`/img/logos/${notification.scene.entity.parent.slug}/favicon_dark.png`"
class="notification-favicon"
>
New&nbsp;<ul
v-if="notification.alert.tags.length > 0"
class="nolist notification-tags"
>
<li
v-for="tag in notification.alert.tags"
:key="`notification-tag-${tag.slug}`"
class="notification-tag"
>{{ tag.name }}</li>&nbsp;
</ul>scene
</div>
<div class="notification-row">
<ul
v-if="notification.scene.actors.length > 0"
class="nolist notification-actors"
>
<li
v-for="actor in notification.scene.actors"
:key="`notification-actor-${actor.slug}`"
class="notification-actor"
>{{ actor.name }}</li>
</ul>
</div>
2021-04-22 17:44:23 +00:00
</div>
<Icon
v-if="!notification.seen"
v-tooltip="'Mark as seen'"
icon="checkmark"
class="notification-check"
@click.prevent="checkNotification(notification.id)"
/>
2021-04-22 17:44:23 +00:00
</router-link>
</li>
</ul>
</div>
</div>
</template>
<script>
import AddAlert from '../alerts/add.vue';
function notifications() {
return this.$store.state.ui.notifications;
}
function unseenNotifications() {
return this.notifications.filter(notification => !notification.seen);
}
async function checkNotifications() {
await this.$store.dispatch('checkNotifications');
await this.$store.dispatch('fetchNotifications');
}
2021-04-22 17:44:23 +00:00
async function checkNotification(notificationId) {
await this.$store.dispatch('checkNotification', notificationId);
await this.$store.dispatch('fetchNotifications');
2021-04-22 17:44:23 +00:00
}
export default {
components: {
AddAlert,
},
data() {
return {
showAddAlert: false,
};
},
computed: {
notifications,
unseenNotifications,
2021-04-22 17:44:23 +00:00
},
methods: {
checkNotifications,
checkNotification,
2021-04-22 17:44:23 +00:00
},
};
</script>
<style lang="scss" scoped>
.notifications {
width: 30rem;
}
.notifications-header {
display: flex;
justify-content: space-between;
.icon {
padding: .5rem;
fill: var(--shadow);
:hover {
fill: var(--primary);
cursor: pointer;
}
}
}
.notifications-title {
display: inline-block;
padding: .5rem 1rem;
margin: 0;
color: var(--shadow);
font-size: 1rem;
font-weight: bold;
}
.notifications-body {
box-shadow: 0 0 3px var(--shadow-weak);
}
.notifications-empty {
padding: 1rem;
}
2021-04-22 17:44:23 +00:00
.notification {
display: block;
margin: 0 0 -1px 0;
&.unseen {
border-right: solid .5rem var(--primary);
}
2021-04-22 17:44:23 +00:00
&:not(:last-child) {
.notification-body,
.notification-check {
border-bottom: solid 1px var(--shadow-hint);
}
2021-04-22 17:44:23 +00:00
}
&:hover {
color: var(--primary);
}
}
.notification-link {
display: flex;
align-items: stretch;
2021-04-22 17:44:23 +00:00
color: inherit;
text-decoration: none;
}
.notification-body {
flex-grow: 1;
padding: .4rem 1rem .25rem .5rem;
overflow: hidden;
}
.notification-row {
display: flex;
align-items: center;
overflow: hidden;
&:not(:last-child) {
margin: 0 0 .1rem 0;
}
2021-04-22 17:44:23 +00:00
}
.notification-favicon {
width: 1rem;
height: 1rem;
margin: 0 .5rem 0 0;
}
.notification-actors {
height: 1.1rem;
display: inline-block;
overflow: hidden;
}
.notification-tags {
white-space: nowrap;
}
.notification-actor,
.notification-tag {
white-space: nowrap;
&:not(:last-child)::after {
content: ',';
padding: 0 .1rem 0 0;
}
}
.notification-actor {
color: var(--shadow-strong);
font-size: .9rem;
}
.notification-tag {
font-weight: bold;
}
.notification-check {
padding: 1rem;
fill: var(--shadow-weak);
&:hover {
fill: var(--primary);
}
}
2021-04-22 17:44:23 +00:00
.poster {
width: 5rem;
height: 3rem;
object-fit: cover;
object-position: center;
}
</style>