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
2 changes: 0 additions & 2 deletions src/renderer/__mocks__/state-mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { Constants } from '../constants';
import {
type Account,
type AppearanceSettingsState,
FetchType,
GroupBy,
type KeyboardAcceleratorShortcut,
type NotificationSettingsState,
Expand Down Expand Up @@ -34,7 +33,6 @@ const mockAppearanceSettings: AppearanceSettingsState = {

const mockNotificationSettings: NotificationSettingsState = {
groupBy: GroupBy.REPOSITORY,
fetchType: FetchType.INTERVAL,
fetchInterval: Constants.DEFAULT_FETCH_NOTIFICATIONS_INTERVAL_MS,
fetchAllNotifications: true,
detailedNotifications: true,
Expand Down
11 changes: 0 additions & 11 deletions src/renderer/components/settings/NotificationSettings.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,6 @@ describe('renderer/components/settings/NotificationSettings.tsx', () => {
expect(updateSettingSpy).toHaveBeenCalledWith('groupBy', 'DATE');
});

it('should change the fetchType radio group', async () => {
await act(async () => {
renderWithProviders(<NotificationSettings />);
});

await userEvent.click(screen.getByTestId('radio-fetchType-inactivity'));

expect(updateSettingSpy).toHaveBeenCalledTimes(1);
expect(updateSettingSpy).toHaveBeenCalledWith('fetchType', 'INACTIVITY');
});

describe('fetch interval settings', () => {
it('should update the fetch interval values when using the buttons', async () => {
await act(async () => {
Expand Down
29 changes: 1 addition & 28 deletions src/renderer/components/settings/NotificationSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import { FieldLabel } from '../fields/FieldLabel';
import { RadioGroup } from '../fields/RadioGroup';
import { Title } from '../primitives/Title';

import { FetchType, GroupBy, Size } from '../../types';
import { GroupBy, Size } from '../../types';

import { hasAlternateScopes, hasRecommendedScopes } from '../../utils/auth/scopes';
import { openGitHubParticipatingDocs } from '../../utils/system/links';
Expand All @@ -48,7 +48,6 @@ export const NotificationSettings: FC = () => {

// Setting store values
const groupBy = useSettingsStore((s) => s.groupBy);
const fetchType = useSettingsStore((s) => s.fetchType);
const fetchInterval = useSettingsStore((s) => s.fetchInterval);
const fetchAllNotifications = useSettingsStore((s) => s.fetchAllNotifications);
const detailedNotifications = useSettingsStore((s) => s.detailedNotifications);
Expand Down Expand Up @@ -90,32 +89,6 @@ export const NotificationSettings: FC = () => {
value={groupBy}
/>

<RadioGroup
label="Fetch type:"
name="fetchType"
onChange={(evt) => {
updateSetting('fetchType', evt.target.value as FetchType);
}}
options={[
{ label: 'Interval', value: FetchType.INTERVAL },
{ label: 'Inactivity', value: FetchType.INACTIVITY },
]}
tooltip={
<Stack direction="vertical" gap="condensed">
<Text>Controls how new notifications are fetched.</Text>
<Text>
<Text as="strong">Interval</Text> will check for new notifications on a regular
scheduled interval.
</Text>
<Text>
<Text as="strong">Inactivity</Text> will check for new notifications only when there
has been no user activity within {APPLICATION.NAME} for a specified period of time.
</Text>
</Stack>
}
value={fetchType}
/>

<Stack align="center" className="text-sm" direction="horizontal" gap="condensed">
<FieldLabel label="Fetch interval:" name="fetchInterval" />

Expand Down
67 changes: 0 additions & 67 deletions src/renderer/hooks/timers/useInactivityTimer.ts

This file was deleted.

3 changes: 0 additions & 3 deletions src/renderer/hooks/useNotifications.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
import { useAccountsStore, useFiltersStore, useSettingsStore } from '../stores';

import type { AccountNotifications, Percentage } from '../types';
import { FetchType } from '../types';

import { Errors } from '../utils/core/errors';
import * as logger from '../utils/core/logger';
Expand Down Expand Up @@ -182,7 +181,6 @@ describe('renderer/hooks/useNotifications.ts', () => {
getAllNotificationsMock.mockResolvedValue(mockSingleAccountNotifications);

useSettingsStore.setState({
fetchType: FetchType.INTERVAL,
fetchInterval: 1000,
});

Expand Down Expand Up @@ -222,7 +220,6 @@ describe('renderer/hooks/useNotifications.ts', () => {
getAllNotificationsMock.mockResolvedValue(mockSingleAccountNotifications);

useSettingsStore.setState({
fetchType: FetchType.INTERVAL,
fetchInterval: 1000,
});

Expand Down
22 changes: 5 additions & 17 deletions src/renderer/hooks/useNotifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { useAccountsStore, useFiltersStore, useSettingsStore } from '../stores';
import {
type Account,
type AccountNotifications,
FetchType,
type GitifyError,
type GitifyNotification,
type Status,
Expand All @@ -32,7 +31,6 @@ import { removeNotificationsForAccount } from '../utils/notifications/remove';
import { getNewNotifications } from '../utils/notifications/utils';
import { raiseSoundNotification } from '../utils/system/audio';
import { raiseNativeNotification } from '../utils/system/native';
import { useInactivityTimer } from './timers/useInactivityTimer';

interface NotificationsState {
status: Status;
Expand All @@ -54,10 +52,10 @@ interface NotificationsState {

interface UseNotificationsOptions {
/**
* Run the singleton side effects (sound/native alerts for new notifications,
* inactivity-based refetching, and interval/focus/reconnect polling). Only
* the app-level effects host should enable this; all other consumers share
* the query cache without them.
* Run the singleton side effects (sound/native alerts for new notifications
* and interval/focus/reconnect polling). Only the app-level effects host
* should enable this; all other consumers share the query cache without
* them.
*
* Polling is owned by the singleton host because TanStack Query schedules
* `refetchInterval` per mounted observer, not per query. Every consumer
Expand Down Expand Up @@ -98,7 +96,6 @@ export const useNotifications = ({
// Setting store values
const fetchReadNotifications = useSettingsStore((s) => s.fetchReadNotifications);
const fetchParticipatingNotifications = useSettingsStore((s) => s.participating);
const fetchType = useSettingsStore((s) => s.fetchType);
const fetchIntervalMs = useSettingsStore((s) => s.fetchInterval);
const markAsDoneOnUnsubscribe = useSettingsStore((s) => s.markAsDoneOnUnsubscribe);
const playSoundNewNotifications = useSettingsStore((s) => s.playSound);
Expand Down Expand Up @@ -162,21 +159,12 @@ export const useNotifications = ({

// Only the singleton side-effects host polls. Other consumers share the
// cached data and would otherwise each schedule their own refetch timer.
refetchInterval: withSideEffects && fetchType === FetchType.INTERVAL ? fetchIntervalMs : false,
refetchInterval: withSideEffects ? fetchIntervalMs : false,
refetchOnMount: withSideEffects,
refetchOnReconnect: withSideEffects,
refetchOnWindowFocus: withSideEffects,
});

// Inactivity-based fetching re-fetches once the user has been idle for the
// configured interval, instead of polling on a fixed schedule.
useInactivityTimer(
() => {
refetch();
},
withSideEffects && fetchType === FetchType.INACTIVITY ? fetchIntervalMs : null,
);

const notificationCount = getNotificationCount(notifications);

const unreadNotificationCount = getUnreadNotificationCount(notifications);
Expand Down
107 changes: 6 additions & 101 deletions src/renderer/routes/__snapshots__/Settings.test.tsx.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading