Skip to content

Commit 9a5bd05

Browse files
authored
refactor: add type-safe useAppContext hook (#2480)
1 parent a14cf3c commit 9a5bd05

24 files changed

+81
-75
lines changed

src/renderer/App.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { useContext } from 'react';
21
import {
32
Navigate,
43
Route,
@@ -10,7 +9,7 @@ import {
109
import { BaseStyles, ThemeProvider } from '@primer/react';
1110

1211
import { AppLayout } from './components/layout/AppLayout';
13-
import { AppContext, AppProvider } from './context/App';
12+
import { AppProvider, useAppContext } from './context/App';
1413
import { AccountsRoute } from './routes/Accounts';
1514
import { FiltersRoute } from './routes/Filters';
1615
import { LoginRoute } from './routes/Login';
@@ -22,7 +21,7 @@ import { SettingsRoute } from './routes/Settings';
2221
import './App.css';
2322

2423
function RequireAuth({ children }) {
25-
const { isLoggedIn } = useContext(AppContext);
24+
const { isLoggedIn } = useAppContext();
2625
const location = useLocation();
2726

2827
return isLoggedIn ? (

src/renderer/components/AllRead.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { type FC, useContext, useMemo } from 'react';
1+
import { type FC, useMemo } from 'react';
22

33
import { Constants } from '../constants';
4-
import { AppContext } from '../context/App';
4+
import { useAppContext } from '../context/App';
55
import { hasActiveFilters } from '../utils/notifications/filters/filter';
66
import { EmojiSplash } from './layout/EmojiSplash';
77

@@ -12,7 +12,7 @@ interface AllReadProps {
1212
export const AllRead: FC<AllReadProps> = ({
1313
fullHeight = true,
1414
}: AllReadProps) => {
15-
const { settings } = useContext(AppContext);
15+
const { settings } = useAppContext();
1616

1717
const hasFilters = hasActiveFilters(settings);
1818

src/renderer/components/Sidebar.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { type FC, useContext } from 'react';
1+
import type { FC } from 'react';
22
import { useLocation, useNavigate } from 'react-router-dom';
33

44
import {
@@ -15,7 +15,7 @@ import { IconButton, Stack } from '@primer/react';
1515
import { APPLICATION } from '../../shared/constants';
1616

1717
import { Constants } from '../constants';
18-
import { AppContext } from '../context/App';
18+
import { useAppContext } from '../context/App';
1919
import { quitApp } from '../utils/comms';
2020
import {
2121
openGitHubIssues,
@@ -37,7 +37,7 @@ export const Sidebar: FC = () => {
3737
auth,
3838
unreadNotificationCount,
3939
hasUnreadNotifications,
40-
} = useContext(AppContext);
40+
} = useAppContext();
4141

4242
// We naively assume that the first account is the primary account for the purposes of our sidebar quick links
4343
const primaryAccountHostname =

src/renderer/components/filters/FilterSection.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { type ReactNode, useContext } from 'react';
1+
import type { ReactNode } from 'react';
22

33
import type { Icon } from '@primer/octicons-react';
44
import { Stack, Text } from '@primer/react';
55

6-
import { AppContext } from '../../context/App';
6+
import { useAppContext } from '../../context/App';
77
import type { FilterSettingsState, FilterSettingsValue } from '../../types';
88
import type { Filter } from '../../utils/notifications/filters';
99
import { Checkbox } from '../fields/Checkbox';
@@ -29,7 +29,7 @@ export const FilterSection = <T extends FilterSettingsValue>({
2929
tooltip,
3030
layout = 'vertical',
3131
}: FilterSectionProps<T>) => {
32-
const { updateFilter, settings, notifications } = useContext(AppContext);
32+
const { updateFilter, settings, notifications } = useAppContext();
3333

3434
return (
3535
<fieldset id={id}>

src/renderer/components/filters/SearchFilter.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { type FC, useContext, useEffect, useState } from 'react';
1+
import { type FC, useEffect, useState } from 'react';
22

33
import {
44
CheckCircleFillIcon,
@@ -10,7 +10,7 @@ import {
1010
} from '@primer/octicons-react';
1111
import { Stack, Text } from '@primer/react';
1212

13-
import { AppContext } from '../../context/App';
13+
import { useAppContext } from '../../context/App';
1414
import { IconColor, type SearchToken, Size } from '../../types';
1515
import { cn } from '../../utils/cn';
1616
import {
@@ -22,7 +22,7 @@ import { RequiresDetailedNotificationWarning } from './RequiresDetailedNotificat
2222
import { TokenSearchInput } from './TokenSearchInput';
2323

2424
export const SearchFilter: FC = () => {
25-
const { updateFilter, settings } = useContext(AppContext);
25+
const { updateFilter, settings } = useAppContext();
2626

2727
// biome-ignore lint/correctness/useExhaustiveDependencies: only run on search filter changes
2828
useEffect(() => {

src/renderer/components/filters/SearchFilterSuggestions.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { type FC, useContext } from 'react';
1+
import type { FC } from 'react';
22

33
import { Popover, Stack, Text } from '@primer/react';
44

5-
import { AppContext } from '../../context/App';
5+
import { useAppContext } from '../../context/App';
66
import { Opacity } from '../../types';
77
import { cn } from '../../utils/cn';
88
import {
@@ -20,7 +20,7 @@ export const SearchFilterSuggestions: FC<SearchFilterSuggestionsProps> = ({
2020
open,
2121
inputValue,
2222
}) => {
23-
const { settings } = useContext(AppContext);
23+
const { settings } = useAppContext();
2424

2525
if (!open) {
2626
return null;

src/renderer/components/metrics/MetricGroup.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { type FC, useContext } from 'react';
1+
import type { FC } from 'react';
22

33
import {
44
CommentIcon,
@@ -7,7 +7,7 @@ import {
77
TagIcon,
88
} from '@primer/octicons-react';
99

10-
import { AppContext } from '../../context/App';
10+
import { useAppContext } from '../../context/App';
1111
import { IconColor } from '../../types';
1212
import type { Notification } from '../../typesGitHub';
1313
import { getPullRequestReviewIcon } from '../../utils/icons';
@@ -20,7 +20,7 @@ interface MetricGroupProps {
2020
export const MetricGroup: FC<MetricGroupProps> = ({
2121
notification,
2222
}: MetricGroupProps) => {
23-
const { settings } = useContext(AppContext);
23+
const { settings } = useAppContext();
2424

2525
const commentsPillDescription = `${notification.subject.comments} ${
2626
notification.subject.comments > 1 ? 'comments' : 'comment'

src/renderer/components/notifications/AccountNotifications.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { type FC, type MouseEvent, useContext, useMemo, useState } from 'react';
1+
import { type FC, type MouseEvent, useMemo, useState } from 'react';
22

33
import { GitPullRequestIcon, IssueOpenedIcon } from '@primer/octicons-react';
44
import { Button, Stack } from '@primer/react';
55

6-
import { AppContext } from '../../context/App';
6+
import { useAppContext } from '../../context/App';
77
import { type Account, type GitifyError, Size } from '../../types';
88
import type { Notification } from '../../typesGitHub';
99
import { hasMultipleAccounts } from '../../utils/auth/utils';
@@ -38,7 +38,7 @@ export const AccountNotifications: FC<AccountNotificationsProps> = (
3838
) => {
3939
const { account, showAccountHeader, notifications } = props;
4040

41-
const { auth, settings } = useContext(AppContext);
41+
const { auth, settings } = useAppContext();
4242

4343
const [showAccountNotifications, setShowAccountNotifications] =
4444
useState(true);

src/renderer/components/notifications/NotificationHeader.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { type FC, type MouseEvent, useContext } from 'react';
1+
import type { FC, MouseEvent } from 'react';
22

33
import { Stack } from '@primer/react';
44

5-
import { AppContext } from '../../context/App';
5+
import { useAppContext } from '../../context/App';
66
import { GroupBy, Opacity, Size } from '../../types';
77
import type { Notification } from '../../typesGitHub';
88
import { cn } from '../../utils/cn';
@@ -16,7 +16,7 @@ interface NotificationHeaderProps {
1616
export const NotificationHeader: FC<NotificationHeaderProps> = ({
1717
notification,
1818
}: NotificationHeaderProps) => {
19-
const { settings } = useContext(AppContext);
19+
const { settings } = useAppContext();
2020

2121
const repoSlug = notification.repository.full_name;
2222

src/renderer/components/notifications/NotificationRow.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { type FC, useCallback, useContext, useState } from 'react';
1+
import { type FC, useCallback, useState } from 'react';
22

33
import { BellSlashIcon, CheckIcon, ReadIcon } from '@primer/octicons-react';
44
import { Stack, Text, Tooltip } from '@primer/react';
55

6-
import { AppContext } from '../../context/App';
6+
import { useAppContext } from '../../context/App';
77
import { GroupBy, Opacity, Size } from '../../types';
88
import type { Notification } from '../../typesGitHub';
99
import { cn } from '../../utils/cn';
@@ -29,7 +29,7 @@ export const NotificationRow: FC<NotificationRowProps> = ({
2929
markNotificationsAsRead,
3030
markNotificationsAsDone,
3131
unsubscribeNotification,
32-
} = useContext(AppContext);
32+
} = useAppContext();
3333
const [animateExit, setAnimateExit] = useState(false);
3434

3535
const handleNotification = useCallback(() => {

0 commit comments

Comments
 (0)