forked from DebaucheryLibrarian/traxxx
Improved alert notifications.
This commit is contained in:
@@ -196,10 +196,20 @@ function curateUser(user) {
|
||||
return curatedUser;
|
||||
}
|
||||
|
||||
function curateNotification(notification) {
|
||||
const curatedNotification = notification;
|
||||
|
||||
curatedNotification.scene = curateRelease(notification.scene);
|
||||
curatedNotification.alert = curateAlert(notification.alert.alert || notification.alert);
|
||||
|
||||
return curatedNotification;
|
||||
}
|
||||
|
||||
export {
|
||||
curateActor,
|
||||
curateEntity,
|
||||
curateRelease,
|
||||
curateNotification,
|
||||
curateTag,
|
||||
curateStash,
|
||||
curateUser,
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -11,4 +11,5 @@ export default {
|
||||
batch: storedBatch || 'all',
|
||||
sfw: storedSfw === 'true' || false,
|
||||
theme: storedTheme || deviceTheme,
|
||||
notifications: [],
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user