Improved alert notifications.

This commit is contained in:
DebaucheryLibrarian
2021-04-22 19:44:23 +02:00
parent 95f3b1c03a
commit c5e74c33b7
9 changed files with 266 additions and 24 deletions

View File

@@ -1,6 +1,6 @@
import { graphql } from '../api';
import { releaseFields, actorStashesFields } from '../fragments';
import { curateRelease, curateActor } from '../curate';
import { curateRelease, curateActor, curateNotification } from '../curate';
function initUiActions(store, _router) {
function setTagFilter({ commit }, filter) {
@@ -29,6 +29,53 @@ function initUiActions(store, _router) {
localStorage.setItem('sfw', sfw);
}
async function fetchNotifications({ commit }) {
if (!store.state.auth.user) {
return [];
}
const { notifications } = await graphql(`
query Notifications(
$hasAuth: Boolean!
$userId: Int
) {
notifications {
id
sceneId
userId
createdAt
scene {
${releaseFields}
}
alert {
tags: alertsTags {
tag {
id
name
slug
}
}
actors: alertsActors {
actor {
id
name
slug
}
}
}
}
}
`, {
hasAuth: !!store.state.auth.user,
userId: store.state.auth.user?.id,
});
const curatedNotifications = notifications.map(notification => curateNotification(notification));
commit('setNotifications', curatedNotifications);
return curatedNotifications;
}
async function search({ _commit }, { query, limit = 20 }) {
const res = await graphql(`
query SearchReleases(
@@ -176,6 +223,7 @@ function initUiActions(store, _router) {
setBatch,
setSfw,
setTheme,
fetchNotifications,
fetchStats,
};
}