Skip to content

Commit

Permalink
feat: count + indicator
Browse files Browse the repository at this point in the history
Signed-off-by: Adam Setch <[email protected]>
  • Loading branch information
setchy committed Sep 16, 2024
1 parent 4b5799a commit f82a55c
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 7 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ NOW
- [ ] purchase and setup Apple developer account
- [ ] setup brew cask definition
- [ ] update test snapshot for "date updated at" to mock result
- [ ] count total, add + when there are more paged results
- [ ] refactor account header settings from settings -> account object

SOON
Expand Down
5 changes: 2 additions & 3 deletions src/utils/api/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { AxiosPromise } from 'axios';
import gql from 'graphql-tag';
import { print } from 'graphql/language/printer';
import type { Account, SettingsState } from '../../types';
import { Constants } from '../constants';
import { apiRequestAuth } from './request';
import type {
GraphQLResponse,
Expand All @@ -10,8 +11,6 @@ import type {
NotificationsExtensions,
} from './types';

export const MAX_PAGE_SIZE = 1000;

/**
* Get the authenticated user
*
Expand Down Expand Up @@ -108,7 +107,7 @@ export function getNotificationsForUser(
return apiRequestAuth(account, {
query: print(QUERY),
variables: {
first: MAX_PAGE_SIZE,
first: Constants.MAX_NOTIFICATIONS_PER_ACCOUNT,
readState: settings.fetchOnlyUnreadNotifications ? 'unread' : null,
// product: settings.product,
},
Expand Down
2 changes: 2 additions & 0 deletions src/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ export const Constants = {
FETCH_NOTIFICATIONS_INTERVAL: 60000,
REFRESH_ACCOUNTS_INTERVAL: 3600000,

MAX_NOTIFICATIONS_PER_ACCOUNT: 999,

DEFAULT_KEYBOARD_SHORTCUT: 'CommandOrControl+Shift+G',

ATLASSIAN_URLS: {
Expand Down
7 changes: 4 additions & 3 deletions src/utils/notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ import type {
AtlasifyState,
SettingsState,
} from '../types';
import { MAX_PAGE_SIZE, getNotificationsForUser } from './api/client';
import { getNotificationsForUser } from './api/client';
import { determineFailureType } from './api/errors';
import type { AtlassianNotification, Category, ReadState } from './api/types';
import { getAccountUUID } from './auth/utils';
import { hideWindow, showWindow, updateTrayIcon } from './comms';
import { Constants } from './constants';
import { READ_STATES } from './filters';
import { openNotification } from './links';
import { isWindows } from './platform';
Expand All @@ -30,7 +31,7 @@ export function getNotificationCount(notifications: AccountNotifications[]) {
}

export function hasMoreNotifications(notifications: AccountNotifications[]) {
return notifications.some((n) => n.hasNextPage);
return notifications?.some((n) => n.hasNextPage);
}

export const triggerNativeNotifications = (
Expand Down Expand Up @@ -153,7 +154,7 @@ export async function getAllNotifications(
notifications: notifications,
hasNextPage:
res.extensions.notifications.response_info.responseSize ===
MAX_PAGE_SIZE, // TODO - there is a bug in the Atlassian GraphQL response
Constants.MAX_NOTIFICATIONS_PER_ACCOUNT, // TODO - there is a bug in the Atlassian GraphQL response
error: null,
};
} catch (error) {
Expand Down

0 comments on commit f82a55c

Please sign in to comment.