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,
};
}

View File

@@ -1,3 +1,7 @@
function setNotifications(state, notifications) {
state.notifications = notifications;
}
function setTagFilter(state, tagFilter) {
state.tagFilter = tagFilter;
}
@@ -19,6 +23,7 @@ function setTheme(state, theme) {
}
export default {
setNotifications,
setTagFilter,
setRange,
setBatch,

View File

@@ -1,4 +1,4 @@
function initUiObservers(store, _router) {
async function initUiObservers(store, _router) {
const body = document.querySelector('body');
body.classList.add(store.state.ui.theme);
@@ -29,6 +29,8 @@ function initUiObservers(store, _router) {
store.dispatch('setTheme', 'light');
}
});
await store.dispatch('fetchNotifications');
}
export default initUiObservers;

View File

@@ -11,4 +11,5 @@ export default {
batch: storedBatch || 'all',
sfw: storedSfw === 'true' || false,
theme: storedTheme || deviceTheme,
notifications: [],
};