Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
66 changes: 66 additions & 0 deletions src/__mocks__/mockedData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,68 +299,101 @@ export const mockedGraphQLResponse: GraphQLSearch<DiscussionSearchResultNode> =
{
databaseId: 2215656,
createdAt: '2022-02-20T18:33:39Z',
author: {
login: 'comment-user',
},
replies: {
nodes: [],
},
},
{
databaseId: 2217789,
createdAt: '2022-02-21T03:30:42Z',
author: {
login: 'comment-user',
},
replies: {
nodes: [],
},
},
{
databaseId: 2223243,
createdAt: '2022-02-21T18:26:27Z',
author: {
login: 'comment-user',
},
replies: {
nodes: [
{
databaseId: 2232922,
createdAt: '2022-02-23T00:57:58Z',
author: {
login: 'reply-user',
},
},
],
},
},
{
databaseId: 2232921,
createdAt: '2022-02-23T00:57:49Z',
author: {
login: 'comment-user',
},
replies: {
nodes: [],
},
},
{
databaseId: 2258799,
createdAt: '2022-02-27T01:22:20Z',
author: {
login: 'comment-user',
},
replies: {
nodes: [
{
databaseId: 2300902,
createdAt: '2022-03-05T17:43:52Z',
author: {
login: 'reply-user',
},
},
],
},
},
{
databaseId: 2297637,
createdAt: '2022-03-04T20:39:44Z',
author: {
login: 'comment-user',
},
replies: {
nodes: [
{
databaseId: 2300893,
createdAt: '2022-03-05T17:41:04Z',
author: {
login: 'reply-user',
},
},
],
},
},
{
databaseId: 2299763,
createdAt: '2022-03-05T11:05:42Z',
author: {
login: 'comment-user',
},
replies: {
nodes: [
{
databaseId: 2300895,
createdAt: '2022-03-05T17:41:44Z',
author: {
login: 'reply-user',
},
},
],
},
Expand All @@ -379,68 +412,101 @@ export const mockedGraphQLResponse: GraphQLSearch<DiscussionSearchResultNode> =
{
databaseId: 2215656,
createdAt: '2022-02-20T18:33:39Z',
author: {
login: 'comment-user',
},
replies: {
nodes: [],
},
},
{
databaseId: 2217789,
createdAt: '2022-02-21T03:30:42Z',
author: {
login: 'comment-user',
},
replies: {
nodes: [],
},
},
{
databaseId: 2223243,
createdAt: '2022-02-21T18:26:27Z',
author: {
login: 'comment-user',
},
replies: {
nodes: [
{
databaseId: 2232922,
createdAt: '2022-02-23T00:57:58Z',
author: {
login: 'reply-user',
},
},
],
},
},
{
databaseId: 2232921,
createdAt: '2022-02-23T00:57:49Z',
author: {
login: 'comment-user',
},
replies: {
nodes: [],
},
},
{
databaseId: 2258799,
createdAt: '2022-02-27T01:22:20Z',
author: {
login: 'comment-user',
},
replies: {
nodes: [
{
databaseId: 2300902,
createdAt: '2022-03-05T17:43:52Z',
author: {
login: 'reply-user',
},
},
],
},
},
{
databaseId: 2297637,
createdAt: '2022-03-04T20:39:44Z',
author: {
login: 'comment-user',
},
replies: {
nodes: [
{
databaseId: 2300893,
createdAt: '2022-03-05T17:41:04Z',
author: {
login: 'reply-user',
},
},
],
},
},
{
databaseId: 2299763,
createdAt: '2022-03-05T11:05:42Z',
author: {
login: 'comment-user',
},
replies: {
nodes: [
{
databaseId: 2300895,
createdAt: '2022-03-05T17:41:44Z',
author: {
login: 'reply-user',
},
},
],
},
Expand Down
10 changes: 7 additions & 3 deletions src/components/NotificationRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ export const NotificationRow: React.FC<IProps> = ({
const updatedAt = formatDistanceToNow(parseISO(notification.updated_at), {
addSuffix: true,
});
const updatedBy = notification.subject.user
? ` by ${notification.subject.user}`
: '';
const updatedLabel = `Updated ${updatedAt}${updatedBy}`;
const notificationTitle = formatForDisplay([
notification.subject.state,
notification.subject.type,
Expand All @@ -84,9 +88,9 @@ export const NotificationRow: React.FC<IProps> = ({
{notification.subject.title}
</div>

<div className="text-xs text-capitalize">
<span title={reason.description}>{reason.type}</span> - Updated{' '}
{updatedAt}
<div className="text-xs text-capitalize whitespace-nowrap overflow-ellipsis overflow-hidden">
<span title={reason.description}>{reason.type}</span> -{' '}
<span title={updatedLabel}>{updatedLabel}</span>
</div>
</div>

Expand Down
10 changes: 7 additions & 3 deletions src/components/__snapshots__/NotificationRow.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,20 @@ exports[`components/Notification.js should render itself & its children 1`] = `
I am a robot and this is a test!
</div>
<div
className="text-xs text-capitalize"
className="text-xs text-capitalize whitespace-nowrap overflow-ellipsis overflow-hidden"
>
<span
title="You're watching the repository."
>
Subscribed
</span>
- Updated
-

in over 3 years
<span
title="Updated in over 3 years"
>
Updated in over 3 years
</span>
</div>
</div>
<div
Expand Down
26 changes: 25 additions & 1 deletion src/hooks/useNotifications.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ describe('hooks/useNotifications.ts', () => {
title: 'This is an Issue.',
type: 'Issue',
url: 'https://api.github.com/3',
latest_comment_url: 'https://api.github.com/3/comments',
},
},
{
Expand All @@ -227,6 +228,7 @@ describe('hooks/useNotifications.ts', () => {
title: 'This is a Pull Request.',
type: 'PullRequest',
url: 'https://api.github.com/4',
latest_comment_url: 'https://api.github.com/4/comments',
},
},
{
Expand Down Expand Up @@ -258,21 +260,43 @@ describe('hooks/useNotifications.ts', () => {
search: {
nodes: [
{
title: 'This is an answered discussion',
title: 'This is a Discussion.',
viewerSubscription: 'SUBSCRIBED',
stateReason: null,
isAnswered: true,
url: 'https://github.com/manosim/notifications-test/discussions/612',
comments: {
nodes: [
{
databaseId: 2297637,
createdAt: '2022-03-04T20:39:44Z',
author: {
login: 'comment-user',
},
replies: {
nodes: [],
},
},
],
},
},
],
},
},
});

nock('https://api.github.com')
.get('/3')
.reply(200, { state: 'closed', merged: true });
nock('https://api.github.com')
.get('/3/comments')
.reply(200, { user: { login: 'some-user' } });
nock('https://api.github.com')
.get('/4')
.reply(200, { state: 'closed', merged: false });
nock('https://api.github.com')
.get('/4/comments')
.reply(200, { user: { login: 'some-user' } });
nock('https://api.github.com')
.get('/5')
.reply(200, { state: 'open', draft: false });
Expand Down
10 changes: 4 additions & 6 deletions src/hooks/useNotifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
} from '../utils/notifications';
import Constants from '../utils/constants';
import { removeNotifications } from '../utils/remove-notifications';
import { getNotificationState } from '../utils/state';
import { getGitifySubjectDetails } from '../utils/subject';

interface NotificationsState {
notifications: AccountNotifications[];
Expand Down Expand Up @@ -141,16 +141,14 @@ export const useNotifications = (colors: boolean): NotificationsState => {
)
: accounts.token;

const notificationState = await getNotificationState(
notification,
token,
);
const additionalSubjectDetails =
await getGitifySubjectDetails(notification, token);

return {
...notification,
subject: {
...notification.subject,
state: notificationState,
...additionalSubjectDetails,
},
};
},
Expand Down
13 changes: 11 additions & 2 deletions src/typesGithub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,21 @@ export interface Owner {
site_admin: boolean;
}

export interface Subject {
export type Subject = GitHubSubject & GitifySubject;

interface GitHubSubject {
title: string;
url: string | null;
state?: StateType; // This is not in the GitHub API, but we add it to the type to make it easier to work with
latest_comment_url: string | null;
type: SubjectType;
}

// This is not in the GitHub API, but we add it to the type to make it easier to work with
export interface GitifySubject {
state?: StateType;
user?: string;
}

export interface PullRequest {
url: string;
id: number;
Expand Down Expand Up @@ -262,6 +269,7 @@ export interface DiscussionSearchResultNode {
export interface DiscussionCommentNode {
databaseId: string | number;
createdAt: string;
author: { login: string };
replies: {
nodes: DiscussionSubcommentNode[];
};
Expand All @@ -270,6 +278,7 @@ export interface DiscussionCommentNode {
export interface DiscussionSubcommentNode {
databaseId: string | number;
createdAt: string;
author: { login: string };
}

export interface CheckSuiteAttributes {
Expand Down
Loading