Implemented notifications, simplified alerts overview.
This commit is contained in:
@@ -86,21 +86,90 @@
|
||||
<VDropdown
|
||||
:triggers="['click']"
|
||||
:prevent-overflow="true"
|
||||
class="notifs-trigger"
|
||||
>
|
||||
<Icon
|
||||
icon="bell2"
|
||||
class="notifs-bell"
|
||||
:class="{ unread: notifications.some((notif) => !notif.isSeen) }"
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
class="notifs-button"
|
||||
:class="{ unseen: unseen > 0 }"
|
||||
>
|
||||
<Icon
|
||||
icon="bell2"
|
||||
class="notifs-bell"
|
||||
/>
|
||||
|
||||
<span
|
||||
v-if="unseen > 0"
|
||||
class="notifs-unseen"
|
||||
>{{ unseen }}</span>
|
||||
</button>
|
||||
|
||||
<template #popper>
|
||||
<div class="menu">
|
||||
<div class="notifs-header">
|
||||
<h4 class="notifs-heading">Notifications</h4>
|
||||
|
||||
<div
|
||||
class="notifs-actions"
|
||||
>
|
||||
<Icon
|
||||
icon="stack-check"
|
||||
@click="markAllSeen"
|
||||
/>
|
||||
|
||||
<Icon
|
||||
v-close-popper
|
||||
icon="plus3"
|
||||
@click="showAlertDialog = true"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<ul class="notifs nolist">
|
||||
<li
|
||||
v-for="notif in notifications"
|
||||
:key="notif.id"
|
||||
class="notif"
|
||||
>{{ notif.scene.title }}</li>
|
||||
:class="{ unseen: !notif.isSeen }"
|
||||
@click="markSeen(notif)"
|
||||
>
|
||||
<a
|
||||
:href="`/scene/${notif.scene.id}/${notif.scene.slug}`"
|
||||
target="_blank"
|
||||
class="notif-body notif-link nolink"
|
||||
>
|
||||
<span class="notif-details">
|
||||
New
|
||||
|
||||
<span
|
||||
v-if="notif.matchedTags.length > 0"
|
||||
class="notif-tags"
|
||||
>{{ notif.matchedTags.map((tag) => tag.name).join(', ') }}</span>
|
||||
|
||||
scene
|
||||
|
||||
<span
|
||||
v-if="notif.matchedActors.length > 0"
|
||||
class="notif-actors"
|
||||
>with {{ notif.matchedActors.map((actor) => actor.name).join(', ') }}</span>
|
||||
|
||||
<span
|
||||
v-if="notif.matchedEntity"
|
||||
class="notif-entities"
|
||||
>for {{ notif.matchedEntity.name }}</span>
|
||||
|
||||
<span
|
||||
v-if="notif.matchedExpressions.length > 0"
|
||||
class="notif-entities"
|
||||
>matching {{ notif.matchedExpressions.map((match) => match.expression).join(', ') }}</span>
|
||||
</span>
|
||||
|
||||
<span class="notif-scene">
|
||||
<span class="notif-date">{{ formatDate(notif.scene.effectiveDate, 'MMM d') }}</span>
|
||||
<span class="notif-title ellipsis">{{ notif.scene.title }}</span>
|
||||
</span>
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</template>
|
||||
@@ -184,6 +253,11 @@
|
||||
v-if="showSettings"
|
||||
@close="showSettings = false"
|
||||
/>
|
||||
|
||||
<AlertDialog
|
||||
v-if="showAlertDialog"
|
||||
@close="showAlertDialog = false"
|
||||
/>
|
||||
</header>
|
||||
</template>
|
||||
|
||||
@@ -195,22 +269,26 @@ import {
|
||||
} from 'vue';
|
||||
|
||||
import navigate from '#/src/navigate.js';
|
||||
import { del } from '#/src/api.js';
|
||||
import { get, patch, del } from '#/src/api.js';
|
||||
import { formatDate } from '#/utils/format.js';
|
||||
// import getPath from '#/src/get-path.js';
|
||||
|
||||
import Settings from '#/components/settings/settings.vue';
|
||||
import AlertDialog from '#/components/alerts/create.vue';
|
||||
|
||||
import logo from '../../assets/img/logo.svg?raw'; // eslint-disable-line import/no-unresolved
|
||||
|
||||
const pageContext = inject('pageContext');
|
||||
|
||||
const user = pageContext.user;
|
||||
const notifications = pageContext.notifications;
|
||||
const notifications = ref(pageContext.notifications.notifications);
|
||||
const unseen = ref(pageContext.notifications.unseen);
|
||||
const done = ref(true);
|
||||
const query = ref(pageContext.urlParsed.search.q || '');
|
||||
const allowLogin = pageContext.env.allowLogin;
|
||||
const searchFocused = ref(false);
|
||||
const showSettings = ref(false);
|
||||
|
||||
console.log(notifications);
|
||||
const showAlertDialog = ref(false);
|
||||
|
||||
const activePage = computed(() => pageContext.urlParsed.pathname.split('/')[1]);
|
||||
const currentPath = `${pageContext.urlParsed.pathnameOriginal}${pageContext.urlParsed.searchOriginal || ''}`;
|
||||
@@ -219,6 +297,41 @@ function search() {
|
||||
navigate('/search', { q: query.value }, { redirect: true });
|
||||
}
|
||||
|
||||
async function fetchNotifications() {
|
||||
const res = await get(`/users/${user?.id}/notifications`);
|
||||
|
||||
notifications.value = res.notifications;
|
||||
unseen.value = res.unseen;
|
||||
}
|
||||
|
||||
async function markSeen(notif) {
|
||||
if (notif.isSeen || !done.value) {
|
||||
return;
|
||||
}
|
||||
|
||||
done.value = false;
|
||||
|
||||
await patch(`/users/${user?.id}/notifications/${notif.id}`, {
|
||||
seen: true,
|
||||
});
|
||||
|
||||
await fetchNotifications();
|
||||
|
||||
done.value = true;
|
||||
}
|
||||
|
||||
async function markAllSeen() {
|
||||
done.value = false;
|
||||
|
||||
await patch(`/users/${user?.id}/notifications`, {
|
||||
seen: true,
|
||||
});
|
||||
|
||||
await fetchNotifications();
|
||||
|
||||
done.value = true;
|
||||
}
|
||||
|
||||
async function logout() {
|
||||
await del('/session');
|
||||
navigate('/login', null, { redirect: true });
|
||||
@@ -346,6 +459,10 @@ function blurSearch(event) {
|
||||
font-size: 0;
|
||||
cursor: pointer;
|
||||
|
||||
.button-submit {
|
||||
margin-left: 1rem;
|
||||
}
|
||||
|
||||
&:hover .avatar {
|
||||
box-shadow: 0 0 3px var(--shadow-weak-10);
|
||||
}
|
||||
@@ -358,29 +475,156 @@ function blurSearch(event) {
|
||||
object-fit: cover;
|
||||
}
|
||||
|
||||
.notifs-bell {
|
||||
padding: 0 1.25rem;
|
||||
.notifs-trigger {
|
||||
height: 100%;
|
||||
fill: var(--shadow);
|
||||
}
|
||||
|
||||
.notifs-button {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
height: 100%;
|
||||
padding: 0 1.25rem;
|
||||
background: none;
|
||||
border: none;
|
||||
|
||||
&:hover,
|
||||
&.unread {
|
||||
&.unseen {
|
||||
cursor: pointer;
|
||||
fill: var(--primary);
|
||||
|
||||
.icon {
|
||||
fill: var(--primary);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.notifs-bell {
|
||||
margin-bottom: .1rem;
|
||||
}
|
||||
|
||||
.notifs-unseen {
|
||||
bottom: 0;
|
||||
font-size: .65rem;
|
||||
font-weight: bold;
|
||||
color: var(--primary);
|
||||
}
|
||||
|
||||
.notifs-bell {
|
||||
fill: var(--shadow);
|
||||
}
|
||||
|
||||
.notifs {
|
||||
overflow: auto;
|
||||
width: 30rem;
|
||||
height: 20rem;
|
||||
max-width: 100%;
|
||||
max-height: 100%;
|
||||
overflow-y: auto;
|
||||
overflow-x: hidden;
|
||||
}
|
||||
|
||||
.notifs-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
box-shadow: inset 0 0 3px var(--shadow-weak-30);
|
||||
|
||||
.icon {
|
||||
fill: var(--shadow-strong-10);
|
||||
|
||||
&:hover {
|
||||
fill: var(--primary);
|
||||
cursor: pointer;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.notifs-heading {
|
||||
font-size: 1rem;
|
||||
padding: .75rem 1rem;
|
||||
margin: 0;
|
||||
font-weight: normal;
|
||||
}
|
||||
|
||||
.notifs-actions {
|
||||
align-items: stretch;
|
||||
|
||||
.icon {
|
||||
height: 100%;
|
||||
padding: 0 .75rem;
|
||||
|
||||
&:last-child {
|
||||
padding-right: 1rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.notif {
|
||||
display: flex;
|
||||
padding: .5rem 1rem;
|
||||
align-items: center;
|
||||
width: 100%;
|
||||
overflow: hidden;
|
||||
|
||||
&:not(:last-child) {
|
||||
border-bottom: solid 1px var(--shadow-weak-30);
|
||||
border-bottom: solid 1px var(--shadow-weak-40);
|
||||
}
|
||||
|
||||
&:before {
|
||||
width: 2.5rem;
|
||||
flex-shrink: 0;
|
||||
content: '•';
|
||||
color: var(--shadow-weak-20);
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
&.unseen:before {
|
||||
color: var(--primary);
|
||||
}
|
||||
|
||||
&.unseen:hover:before {
|
||||
content: '✓';
|
||||
}
|
||||
}
|
||||
|
||||
.notif-body {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
flex-grow: 1;
|
||||
overflow: hidden;
|
||||
box-sizing: border-box;
|
||||
font-size: .9rem;
|
||||
}
|
||||
|
||||
.notif-details {
|
||||
padding: .5rem 0 .15rem 0;
|
||||
box-sizing: border-box;
|
||||
color: var(--shadow-strong);
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.notif-link {
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.notif-scene {
|
||||
display: flex;
|
||||
padding: .15rem 0 .5rem 0;
|
||||
}
|
||||
|
||||
.notif-date {
|
||||
flex-shrink: 0;
|
||||
color: var(--shadow-strong-10);
|
||||
|
||||
&:after {
|
||||
content: '•';
|
||||
padding: 0 .5rem;
|
||||
color: var(--shadow-weak-20);
|
||||
}
|
||||
}
|
||||
|
||||
.notif-thumb {
|
||||
width: 5rem;
|
||||
height: 3rem;
|
||||
object-fit: cover;
|
||||
}
|
||||
|
||||
.login {
|
||||
|
||||
Reference in New Issue
Block a user