Skip to content

Commit 136e7e8

Browse files
committed
refactor: tanstack & zustand overhaul
Signed-off-by: Adam Setch <adam.setch@outlook.com>
1 parent b5baf87 commit 136e7e8

18 files changed

Lines changed: 138 additions & 184 deletions

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@
8484
"@octokit/oauth-methods": "6.0.2",
8585
"@octokit/plugin-paginate-rest": "14.0.0",
8686
"@octokit/plugin-rest-endpoint-methods": "17.0.0",
87-
"@octokit/plugin-retry": "8.0.3",
8887
"@octokit/request-error": "7.1.0",
8988
"@octokit/types": "16.0.0",
9089
"@parcel/watcher": "2.5.6",

pnpm-lock.yaml

Lines changed: 0 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/renderer/App.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { LoginWithOAuthAppRoute } from './routes/LoginWithOAuthApp';
2323
import { LoginWithPersonalAccessTokenRoute } from './routes/LoginWithPersonalAccessToken';
2424
import { NotificationsRoute } from './routes/Notifications';
2525
import { SettingsRoute } from './routes/Settings';
26+
import { useAccountsStore } from './stores';
2627
import { initializeStoreSubscriptions } from './stores/subscriptions';
2728

2829
import { GlobalShortcuts } from './components/GlobalShortcuts';

src/renderer/components/GlobalShortcuts.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { type FC, useEffect } from 'react';
22

3-
import { useShortcutActions } from '../hooks/useGlobalShortcuts';
3+
import { useGlobalShortcuts } from '../hooks/useGlobalShortcuts';
44

55
/**
66
* Component that registers global keyboard shortcuts for the renderer app.
77
* Mount once inside App, within Router + AppProvider.
88
*/
99
export const GlobalShortcuts: FC = () => {
10-
const { shortcuts } = useShortcutActions();
10+
const { shortcuts } = useGlobalShortcuts();
1111

1212
useEffect(() => {
1313
const keyToName = new Map<string, keyof typeof shortcuts>(

src/renderer/components/Sidebar.tsx

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,26 @@ import { IconButton, Stack } from '@primer/react';
1616
import { APPLICATION } from '../../shared/constants';
1717

1818
import { useAppContext } from '../hooks/useAppContext';
19-
import { useShortcutActions } from '../hooks/useGlobalShortcuts';
20-
import { useFiltersStore } from '../stores';
19+
import { useGlobalShortcuts } from '../hooks/useGlobalShortcuts';
20+
import { useAccountsStore, useFiltersStore, useSettingsStore } from '../stores';
2121

2222
import { LogoIcon } from './icons/LogoIcon';
2323

2424
export const Sidebar: FC = () => {
25-
const {
26-
status,
27-
isLoggedIn,
28-
settings,
29-
notificationCount,
30-
hasUnreadNotifications,
31-
} = useAppContext();
25+
const { status, notificationCount, hasUnreadNotifications } = useAppContext();
3226

33-
const { shortcuts } = useShortcutActions();
27+
const { shortcuts } = useGlobalShortcuts();
28+
29+
const isLoggedIn = useAccountsStore((s) => s.isLoggedIn());
3430

3531
const hasFilters = useFiltersStore((s) => s.hasActiveFilters());
3632

33+
// Subscribe to settings from store
34+
const fetchReadNotifications = useSettingsStore(
35+
(s) => s.fetchReadNotifications,
36+
);
37+
const participating = useSettingsStore((s) => s.participating);
38+
3739
const isLoading = status === 'loading';
3840

3941
return (
@@ -63,7 +65,7 @@ export const Sidebar: FC = () => {
6365
<IconButton
6466
aria-label="Notifications"
6567
data-testid="sidebar-notifications"
66-
description={`${notificationCount} ${settings.fetchReadNotifications ? 'notifications' : 'unread notifications'} ↗`}
68+
description={`${notificationCount} ${fetchReadNotifications ? 'notifications' : 'unread notifications'} ↗`}
6769
icon={BellIcon}
6870
keybindingHint={shortcuts.myNotifications.key}
6971
onClick={() => shortcuts.myNotifications.action()}
@@ -78,16 +80,16 @@ export const Sidebar: FC = () => {
7880
aria-label="Toggle focused mode"
7981
data-testid="sidebar-focused-mode"
8082
description={
81-
settings.participating
83+
participating
8284
? 'Focused (participating only)'
8385
: 'Participating and watching'
8486
}
85-
icon={settings.participating ? CrosshairsIcon : EyeIcon}
87+
icon={participating ? CrosshairsIcon : EyeIcon}
8688
keybindingHint={shortcuts.focusedMode.key}
8789
onClick={() => shortcuts.focusedMode.action()}
8890
size="small"
8991
tooltipDirection="e"
90-
variant={settings.participating ? 'primary' : 'invisible'}
92+
variant={participating ? 'primary' : 'invisible'}
9193
/>
9294

9395
<IconButton

src/renderer/components/filters/FilterSection.tsx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@ import type { Icon } from '@primer/octicons-react';
44
import { Stack, Text } from '@primer/react';
55

66
import { useAppContext } from '../../hooks/useAppContext';
7+
import {
8+
type FiltersState,
9+
useFiltersStore,
10+
useSettingsStore,
11+
} from '../../stores';
712

813
import { Checkbox } from '../fields/Checkbox';
914
import { Title } from '../primitives/Title';
1015

11-
import { type FiltersState, useFiltersStore } from '../../stores';
1216
import type { Filter } from '../../utils/notifications/filters';
1317
import { RequiresDetailedNotificationWarning } from './RequiresDetailedNotificationsWarning';
1418

@@ -31,9 +35,13 @@ const FilterSectionComponent = <K extends keyof FiltersState>({
3135
tooltip,
3236
layout = 'vertical',
3337
}: FilterSectionProps<K>) => {
34-
const { notifications, settings } = useAppContext();
38+
const { notifications } = useAppContext();
3539
const updateFilter = useFiltersStore((s) => s.updateFilter);
3640

41+
const detailedNotifications = useSettingsStore(
42+
(s) => s.detailedNotifications,
43+
);
44+
3745
// Subscribe to the specific filter state so component re-renders when filters change
3846
useFiltersStore((s) => s[filterSetting]);
3947

@@ -91,8 +99,7 @@ const FilterSectionComponent = <K extends keyof FiltersState>({
9199
checked={isChecked}
92100
counter={count}
93101
disabled={
94-
filter.requiresDetailsNotifications &&
95-
!settings.detailedNotifications
102+
filter.requiresDetailsNotifications && !detailedNotifications
96103
}
97104
key={type as string}
98105
label={typeTitle}

src/renderer/components/filters/SearchFilter.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,12 @@ import {
1010
} from '@primer/octicons-react';
1111
import { Stack, Text } from '@primer/react';
1212

13-
import { useAppContext } from '../../hooks/useAppContext';
13+
import { useFiltersStore, useSettingsStore } from '../../stores';
1414

1515
import { Title } from '../primitives/Title';
1616

1717
import { IconColor, type SearchToken, Size } from '../../types';
1818

19-
import { useFiltersStore } from '../../stores';
2019
import { cn } from '../../utils/cn';
2120
import {
2221
hasExcludeSearchFilters,
@@ -26,12 +25,14 @@ import { RequiresDetailedNotificationWarning } from './RequiresDetailedNotificat
2625
import { TokenSearchInput } from './TokenSearchInput';
2726

2827
export const SearchFilter: FC = () => {
29-
const { settings } = useAppContext();
30-
3128
const updateFilter = useFiltersStore((s) => s.updateFilter);
3229
const includeSearchTokens = useFiltersStore((s) => s.includeSearchTokens);
3330
const excludeSearchTokens = useFiltersStore((s) => s.excludeSearchTokens);
3431

32+
const detailedNotifications = useSettingsStore(
33+
(s) => s.detailedNotifications,
34+
);
35+
3536
const addIncludeSearchToken = (value: string) => {
3637
if (!value || includeSearchTokens.includes(value as SearchToken)) {
3738
return;
@@ -78,7 +79,7 @@ export const SearchFilter: FC = () => {
7879
<Text
7980
className={cn(
8081
'text-gitify-caution',
81-
!settings.detailedNotifications && 'line-through',
82+
!detailedNotifications && 'line-through',
8283
)}
8384
>
8485
Author (author:handle)

src/renderer/components/filters/SearchFilterSuggestions.tsx

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

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

5-
import { useAppContext } from '../../hooks/useAppContext';
5+
import { useSettingsStore } from '../../stores';
66

77
import { Opacity } from '../../types';
88

@@ -22,14 +22,16 @@ export const SearchFilterSuggestions: FC<SearchFilterSuggestionsProps> = ({
2222
open,
2323
inputValue,
2424
}) => {
25-
const { settings } = useAppContext();
25+
const detailedNotifications = useSettingsStore(
26+
(s) => s.detailedNotifications,
27+
);
2628

2729
if (!open) {
2830
return null;
2931
}
3032

3133
const lower = inputValue.toLowerCase();
32-
const base = settings.detailedNotifications
34+
const base = detailedNotifications
3335
? ALL_SEARCH_QUALIFIERS
3436
: BASE_SEARCH_QUALIFIERS;
3537
const suggestions = base.filter(

src/renderer/components/metrics/MetricGroup.tsx

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

3-
import { useAppContext } from '../../hooks/useAppContext';
3+
import { useSettingsStore } from '../../stores';
44

55
import type { GitifyNotification } from '../../types';
66

@@ -16,9 +16,9 @@ export interface MetricGroupProps {
1616
}
1717

1818
export const MetricGroup: FC<MetricGroupProps> = ({ notification }) => {
19-
const { settings } = useAppContext();
19+
const showPills = useSettingsStore((s) => s.showPills);
2020

21-
if (!settings.showPills) {
21+
if (!showPills) {
2222
return null;
2323
}
2424

src/renderer/components/notifications/AccountNotifications.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { type FC, type MouseEvent, useMemo, useState } from 'react';
33
import { GitPullRequestIcon, IssueOpenedIcon } from '@primer/octicons-react';
44
import { Button, Stack } from '@primer/react';
55

6-
import { useAppContext } from '../../hooks/useAppContext';
6+
import { useAccountsStore } from '../../stores';
77

88
import { HoverButton } from '../primitives/HoverButton';
99
import { HoverGroup } from '../primitives/HoverGroup';
@@ -15,7 +15,6 @@ import {
1515
Size,
1616
} from '../../types';
1717

18-
import { hasMultipleAccounts } from '../../utils/auth/utils';
1918
import { cn } from '../../utils/cn';
2019
import { getChevronDetails } from '../../utils/helpers';
2120
import {
@@ -45,8 +44,6 @@ export const AccountNotifications: FC<AccountNotificationsProps> = (
4544
) => {
4645
const { account, showAccountHeader, notifications } = props;
4746

48-
const { auth, settings } = useAppContext();
49-
5047
const [isAccountNotificationsVisible, setIsAccountNotificationsVisible] =
5148
useState(true);
5249

@@ -66,6 +63,8 @@ export const AccountNotifications: FC<AccountNotificationsProps> = (
6663
[notifications],
6764
);
6865

66+
const hasMultipleAccounts = useAccountsStore((s) => s.hasMultipleAccounts);
67+
6968
const actionToggleAccountNotifications = () => {
7069
setIsAccountNotificationsVisible(!isAccountNotificationsVisible);
7170
};
@@ -135,12 +134,12 @@ export const AccountNotifications: FC<AccountNotificationsProps> = (
135134
{isAccountNotificationsVisible && (
136135
<>
137136
{props.error && (
138-
<Oops error={props.error} fullHeight={!hasMultipleAccounts(auth)} />
137+
<Oops error={props.error} fullHeight={!hasMultipleAccounts()} />
139138
)}
140139

141140
{!hasNotifications && !props.error && <AllRead fullHeight={false} />}
142141

143-
{isGroupByRepository(settings)
142+
{isGroupByRepository()
144143
? groupedNotifications.map(([repoSlug, repoNotifications]) => (
145144
<RepositoryNotifications
146145
key={repoSlug}

0 commit comments

Comments
 (0)