Skip to content

Commit 33b08ce

Browse files
Add user notifications (#769)
1 parent b5695d7 commit 33b08ce

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+24217
-6575
lines changed

Makefile

+3
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ generate-dataloaders:
7474
go run github.com/vektah/dataloaden TagCategoryLoader github.com/gofrs/uuid.UUID "*github.com/stashapp/stash-box/pkg/models.TagCategory"; \
7575
go run github.com/vektah/dataloaden SiteLoader github.com/gofrs/uuid.UUID "*github.com/stashapp/stash-box/pkg/models.Site"; \
7676
go run github.com/vektah/dataloaden StudioLoader github.com/gofrs/uuid.UUID "*github.com/stashapp/stash-box/pkg/models.Studio"; \
77+
go run github.com/vektah/dataloaden EditLoader github.com/gofrs/uuid.UUID "*github.com/stashapp/stash-box/pkg/models.Edit"; \
78+
go run github.com/vektah/dataloaden EditCommentLoader github.com/gofrs/uuid.UUID "*github.com/stashapp/stash-box/pkg/models.EditComment"; \
79+
go run github.com/vektah/dataloaden SceneLoader github.com/gofrs/uuid.UUID "*github.com/stashapp/stash-box/pkg/models.Scene"; \
7780
go run github.com/vektah/dataloaden BoolsLoader github.com/gofrs/uuid.UUID "bool";
7881

7982
test:

frontend/src/App.scss

+9
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,12 @@ div.react-select__menu {
9494
margin: auto;
9595
max-width: 1200px;
9696
}
97+
98+
.NotificationBadge {
99+
color: white;
100+
101+
&:active,
102+
&:hover {
103+
color: var(--bs-gray-500);
104+
}
105+
}

frontend/src/Main.tsx

+19-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import { FC, useEffect } from "react";
2-
import { Navbar, Nav } from "react-bootstrap";
3-
import { NavLink, useLocation, useNavigate } from "react-router-dom";
2+
import { Navbar, Nav, Button, Badge } from "react-bootstrap";
3+
import { NavLink, useLocation, useNavigate, Link } from "react-router-dom";
4+
import { faBell, faBook, faUser } from "@fortawesome/free-solid-svg-icons";
5+
import { faBell as faBellOutlined } from "@fortawesome/free-regular-svg-icons";
46

57
import SearchField, { SearchType } from "src/components/searchField";
6-
import { useConfig } from "src/graphql";
78
import { getPlatformURL, getCredentialsSetting } from "src/utils/createClient";
89
import { isAdmin, canEdit, userHref, setCachedUser } from "src/utils";
910
import { useAuth } from "src/hooks";
1011
import { Icon } from "src/components/fragments";
11-
import { faBook, faUser } from "@fortawesome/free-solid-svg-icons";
12+
import { useConfig, useUnreadNotificationsCount } from "src/graphql";
1213
import {
1314
ROUTE_SCENES,
1415
ROUTE_PERFORMERS,
@@ -25,6 +26,7 @@ import {
2526
ROUTE_FORGOT_PASSWORD,
2627
ROUTE_SITES,
2728
ROUTE_DRAFTS,
29+
ROUTE_NOTIFICATIONS,
2830
} from "src/constants/route";
2931
import AuthContext from "./AuthContext";
3032

@@ -36,6 +38,9 @@ const Main: FC<Props> = ({ children }) => {
3638
const location = useLocation();
3739
const navigate = useNavigate();
3840
const { loading, user } = useAuth();
41+
const { data: unreadNotifications } = useUnreadNotificationsCount();
42+
const notificationCount =
43+
unreadNotifications?.getUnreadNotificationCount || null;
3944
const { data: configData } = useConfig();
4045

4146
const guidelinesURL = configData?.getConfig.guidelines_url;
@@ -83,6 +88,16 @@ const Main: FC<Props> = ({ children }) => {
8388
contextValue.authenticated &&
8489
contextValue.user && (
8590
<>
91+
<Link to={ROUTE_NOTIFICATIONS}>
92+
<Button variant="link" className="NotificationBadge">
93+
<Icon icon={notificationCount ? faBell : faBellOutlined} />
94+
{notificationCount && (
95+
<Badge bg="danger" className="ms-1">
96+
{notificationCount}
97+
</Badge>
98+
)}
99+
</Button>
100+
</Link>
86101
<NavLink
87102
to={userHref(contextValue.user)}
88103
className="nav-link ms-auto me-2"

frontend/src/constants/route.ts

+1
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,4 @@ export const ROUTE_SITE_EDIT = "/sites/:id/edit";
5151
export const ROUTE_SITES = "/sites";
5252
export const ROUTE_DRAFT = "/drafts/:id";
5353
export const ROUTE_DRAFTS = "/drafts";
54+
export const ROUTE_NOTIFICATIONS = "/notifications";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#import "../fragments/SceneFragment.gql"
2+
#import "../fragments/EditFragment.gql"
3+
#import "../fragments/CommentFragment.gql"
4+
5+
fragment NotificationCommentFragment on EditComment {
6+
...CommentFragment
7+
edit {
8+
...EditFragment
9+
}
10+
}
11+
12+
query Notifications($input: QueryNotificationsInput!) {
13+
queryNotifications(input: $input) {
14+
count
15+
notifications {
16+
created
17+
read
18+
data {
19+
__typename
20+
... on FavoritePerformerScene {
21+
scene {
22+
...SceneFragment
23+
}
24+
}
25+
... on FavoritePerformerEdit {
26+
edit {
27+
...EditFragment
28+
}
29+
}
30+
... on FavoriteStudioScene {
31+
scene {
32+
...SceneFragment
33+
}
34+
}
35+
... on FavoriteStudioEdit {
36+
edit {
37+
...EditFragment
38+
}
39+
}
40+
... on CommentOwnEdit {
41+
comment {
42+
...NotificationCommentFragment
43+
}
44+
}
45+
... on CommentCommentedEdit {
46+
comment {
47+
...NotificationCommentFragment
48+
}
49+
}
50+
... on CommentVotedEdit {
51+
comment {
52+
...NotificationCommentFragment
53+
}
54+
}
55+
... on DownvoteOwnEdit {
56+
edit {
57+
...EditFragment
58+
}
59+
}
60+
... on FailedOwnEdit {
61+
edit {
62+
...EditFragment
63+
}
64+
}
65+
... on UpdatedEdit {
66+
edit {
67+
...EditFragment
68+
}
69+
}
70+
}
71+
}
72+
}
73+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
query UnreadNotificationCount {
2+
getUnreadNotificationCount
3+
}

frontend/src/graphql/queries/index.ts

+11
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ import {
7373
StudioPerformersQueryVariables,
7474
VersionDocument,
7575
MeQueryVariables,
76+
NotificationsDocument,
77+
NotificationsQueryVariables,
78+
UnreadNotificationCountDocument,
7679
} from "../types";
7780

7881
export const useCategory = (variables: CategoryQueryVariables, skip = false) =>
@@ -291,3 +294,11 @@ export const useStudioPerformers = (
291294
useQuery(StudioPerformersDocument, {
292295
variables,
293296
});
297+
298+
export const useNotifications = (variables: NotificationsQueryVariables) =>
299+
useQuery(NotificationsDocument, {
300+
variables,
301+
});
302+
303+
export const useUnreadNotificationsCount = () =>
304+
useQuery(UnreadNotificationCountDocument);

0 commit comments

Comments
 (0)