Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add user notifications #769

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ generate-dataloaders:
go run github.com/vektah/dataloaden TagCategoryLoader github.com/gofrs/uuid.UUID "*github.com/stashapp/stash-box/pkg/models.TagCategory"; \
go run github.com/vektah/dataloaden SiteLoader github.com/gofrs/uuid.UUID "*github.com/stashapp/stash-box/pkg/models.Site"; \
go run github.com/vektah/dataloaden StudioLoader github.com/gofrs/uuid.UUID "*github.com/stashapp/stash-box/pkg/models.Studio"; \
go run github.com/vektah/dataloaden EditLoader github.com/gofrs/uuid.UUID "*github.com/stashapp/stash-box/pkg/models.Edit"; \
go run github.com/vektah/dataloaden EditCommentLoader github.com/gofrs/uuid.UUID "*github.com/stashapp/stash-box/pkg/models.EditComment"; \
go run github.com/vektah/dataloaden SceneLoader github.com/gofrs/uuid.UUID "*github.com/stashapp/stash-box/pkg/models.Scene"; \
go run github.com/vektah/dataloaden BoolsLoader github.com/gofrs/uuid.UUID "bool";

test:
Expand Down
9 changes: 9 additions & 0 deletions frontend/src/App.scss
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,12 @@ div.react-select__menu {
margin: auto;
max-width: 1200px;
}

.NotificationBadge {
color: white;

&:active,
&:hover {
color: var(--bs-gray-500);
}
}
18 changes: 14 additions & 4 deletions frontend/src/Main.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { FC, useEffect } from "react";
import { Navbar, Nav } from "react-bootstrap";
import { NavLink, useLocation, useNavigate } from "react-router-dom";
import { Navbar, Nav, Button, Badge } from "react-bootstrap";
import { NavLink, useLocation, useNavigate, Link } from "react-router-dom";
import { faBell, faBook, faUser } from "@fortawesome/free-solid-svg-icons";
import { faBell as faBellOutlined} from "@fortawesome/free-regular-svg-icons";

import SearchField, { SearchType } from "src/components/searchField";
import { useConfig } from "src/graphql";
import { getPlatformURL, getCredentialsSetting } from "src/utils/createClient";
import { isAdmin, canEdit, userHref, setCachedUser } from "src/utils";
import { useAuth } from "src/hooks";
import { Icon } from "src/components/fragments";
import { faBook, faUser } from "@fortawesome/free-solid-svg-icons";
import { useConfig, useUnreadNotificationsCount } from "src/graphql";
import {
ROUTE_SCENES,
ROUTE_PERFORMERS,
Expand All @@ -25,6 +26,7 @@ import {
ROUTE_FORGOT_PASSWORD,
ROUTE_SITES,
ROUTE_DRAFTS,
ROUTE_NOTIFICATIONS,
} from "src/constants/route";
import AuthContext from "./AuthContext";

Expand All @@ -36,6 +38,8 @@ const Main: FC<Props> = ({ children }) => {
const location = useLocation();
const navigate = useNavigate();
const { loading, user } = useAuth();
const { data: unreadNotifications } = useUnreadNotificationsCount();
const notificationCount = unreadNotifications?.getUnreadNotificationCount || null;
const { data: configData } = useConfig();

const guidelinesURL = configData?.getConfig.guidelines_url;
Expand Down Expand Up @@ -79,6 +83,12 @@ const Main: FC<Props> = ({ children }) => {
contextValue.authenticated &&
contextValue.user && (
<>
<Link to={ROUTE_NOTIFICATIONS}>
<Button variant="link" className="NotificationBadge">
<Icon icon={notificationCount ? faBell : faBellOutlined} />
{ notificationCount && <Badge bg="danger" className="ms-1">{ notificationCount }</Badge> }
</Button>
</Link>
<NavLink
to={userHref(contextValue.user)}
className="nav-link ms-auto me-2"
Expand Down
1 change: 1 addition & 0 deletions frontend/src/constants/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,4 @@ export const ROUTE_SITE_EDIT = "/sites/:id/edit";
export const ROUTE_SITES = "/sites";
export const ROUTE_DRAFT = "/drafts/:id";
export const ROUTE_DRAFTS = "/drafts";
export const ROUTE_NOTIFICATIONS = "/notifications";
73 changes: 73 additions & 0 deletions frontend/src/graphql/queries/QueryNotifications.gql
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#import "../fragments/SceneFragment.gql"
#import "../fragments/EditFragment.gql"
#import "../fragments/CommentFragment.gql"

fragment NotificationCommentFragment on EditComment {
...CommentFragment
edit {
...EditFragment
}
}

query Notifications($input: QueryNotificationsInput!) {
queryNotifications(input: $input) {
count
notifications {
created
read
data {
__typename
...on FavoritePerformerScene {
scene {
...SceneFragment
}
}
...on FavoritePerformerEdit {
edit {
...EditFragment
}
}
...on FavoriteStudioScene {
scene {
...SceneFragment
}
}
...on FavoriteStudioEdit {
edit {
...EditFragment
}
}
...on CommentOwnEdit {
comment {
...NotificationCommentFragment
}
}
...on CommentCommentedEdit{
comment {
...NotificationCommentFragment
}
}
...on CommentVotedEdit {
comment {
...NotificationCommentFragment
}
}
...on DownvoteOwnEdit {
edit {
...EditFragment
}
}
...on FailedOwnEdit {
edit {
...EditFragment
}
}
...on UpdatedEdit {
edit {
...EditFragment
}
}
}
}
}
}
3 changes: 3 additions & 0 deletions frontend/src/graphql/queries/UnreadNotificationCount.gql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
query UnreadNotificationCount {
getUnreadNotificationCount
}
11 changes: 11 additions & 0 deletions frontend/src/graphql/queries/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ import {
StudioPerformersQueryVariables,
VersionDocument,
MeQueryVariables,
NotificationsDocument,
NotificationsQueryVariables,
UnreadNotificationCountDocument,
} from "../types";

export const useCategory = (variables: CategoryQueryVariables, skip = false) =>
Expand Down Expand Up @@ -280,3 +283,11 @@ export const useStudioPerformers = (
useQuery(StudioPerformersDocument, {
variables,
});

export const useNotifications = (variables: NotificationsQueryVariables) =>
useQuery(NotificationsDocument, {
variables,
});

export const useUnreadNotificationsCount = () =>
useQuery(UnreadNotificationCountDocument);
Loading
Loading