Skip to content

Commit a79233e

Browse files
authored
refactor: continued renaming of accounts to auth (#1156)
1 parent 6ecbbb3 commit a79233e

File tree

3 files changed

+41
-46
lines changed

3 files changed

+41
-46
lines changed

src/components/NotificationRow.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ interface IProps {
3737
export const NotificationRow: FC<IProps> = ({ notification, hostname }) => {
3838
const {
3939
settings,
40-
auth: accounts,
40+
auth,
4141
removeNotificationFromState,
4242
markNotificationRead,
4343
markNotificationDone,
@@ -46,15 +46,15 @@ export const NotificationRow: FC<IProps> = ({ notification, hostname }) => {
4646
} = useContext(AppContext);
4747

4848
const openNotification = useCallback(() => {
49-
openInBrowser(notification, accounts);
49+
openInBrowser(notification, auth);
5050

5151
if (settings.markAsDoneOnOpen) {
5252
markNotificationDone(notification.id, hostname);
5353
} else {
5454
// no need to mark as read, github does it by default when opening it
5555
removeNotificationFromState(settings, notification.id, hostname);
5656
}
57-
}, [notifications, notification, accounts, settings]); // notifications required here to prevent weird state issues
57+
}, [notifications, notification, auth, settings]); // notifications required here to prevent weird state issues
5858

5959
const unsubscribeFromThread = (event: MouseEvent<HTMLElement>) => {
6060
// Don't trigger onClick of parent element.

src/context/App.tsx

+35-35
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ interface AppContextState {
7979
export const AppContext = createContext<Partial<AppContextState>>({});
8080

8181
export const AppProvider = ({ children }: { children: ReactNode }) => {
82-
const [accounts, setAccounts] = useState<AuthState>(defaultAuth);
82+
const [auth, setAuth] = useState<AuthState>(defaultAuth);
8383
const [settings, setSettings] = useState<SettingsState>(defaultSettings);
8484
const {
8585
fetchNotifications,
@@ -104,17 +104,17 @@ export const AppProvider = ({ children }: { children: ReactNode }) => {
104104

105105
// biome-ignore lint/correctness/useExhaustiveDependencies: We only want fetchNotifications to be called for certain account or setting changes.
106106
useEffect(() => {
107-
fetchNotifications(accounts, settings);
107+
fetchNotifications(auth, settings);
108108
}, [
109109
settings.participating,
110110
settings.showBots,
111111
settings.detailedNotifications,
112-
accounts.token,
113-
accounts.enterpriseAccounts.length,
112+
auth.token,
113+
auth.enterpriseAccounts.length,
114114
]);
115115

116116
useInterval(() => {
117-
fetchNotifications(accounts, settings);
117+
fetchNotifications(auth, settings);
118118
}, Constants.FETCH_INTERVAL);
119119

120120
// biome-ignore lint/correctness/useExhaustiveDependencies: We need to update tray title when settings or notifications changes.
@@ -136,58 +136,58 @@ export const AppProvider = ({ children }: { children: ReactNode }) => {
136136

137137
const newSettings = { ...settings, [name]: value };
138138
setSettings(newSettings);
139-
saveState({ auth: accounts, settings: newSettings });
139+
saveState({ auth, settings: newSettings });
140140
},
141-
[accounts, settings],
141+
[auth, settings],
142142
);
143143

144144
const isLoggedIn = useMemo(() => {
145-
return !!accounts.token || accounts.enterpriseAccounts.length > 0;
146-
}, [accounts]);
145+
return !!auth.token || auth.enterpriseAccounts.length > 0;
146+
}, [auth]);
147147

148148
const login = useCallback(async () => {
149149
const { authCode } = await authGitHub();
150150
const { token } = await getToken(authCode);
151151
const hostname = Constants.DEFAULT_AUTH_OPTIONS.hostname;
152152
const user = await getUserData(token, hostname);
153-
const updatedAccounts = addAccount(accounts, token, hostname, user);
154-
setAccounts(updatedAccounts);
155-
saveState({ auth: updatedAccounts, settings });
156-
}, [accounts, settings]);
153+
const updatedAuth = addAccount(auth, token, hostname, user);
154+
setAuth(updatedAuth);
155+
saveState({ auth: updatedAuth, settings });
156+
}, [auth, settings]);
157157

158158
const loginEnterprise = useCallback(
159159
async (data: AuthOptions) => {
160160
const { authOptions, authCode } = await authGitHub(data);
161161
const { token, hostname } = await getToken(authCode, authOptions);
162-
const updatedAccounts = addAccount(accounts, token, hostname);
163-
setAccounts(updatedAccounts);
164-
saveState({ auth: updatedAccounts, settings });
162+
const updatedAuth = addAccount(auth, token, hostname);
163+
setAuth(updatedAuth);
164+
saveState({ auth: updatedAuth, settings });
165165
},
166-
[accounts, settings],
166+
[auth, settings],
167167
);
168168

169169
const validateToken = useCallback(
170170
async ({ token, hostname }: AuthTokenOptions) => {
171171
await headNotifications(hostname, token);
172172

173173
const user = await getUserData(token, hostname);
174-
const updatedAccounts = addAccount(accounts, token, hostname, user);
175-
setAccounts(updatedAccounts);
174+
const updatedAccounts = addAccount(auth, token, hostname, user);
175+
setAuth(updatedAccounts);
176176
saveState({ auth: updatedAccounts, settings });
177177
},
178-
[accounts, settings],
178+
[auth, settings],
179179
);
180180

181181
const logout = useCallback(() => {
182-
setAccounts(defaultAuth);
182+
setAuth(defaultAuth);
183183
clearState();
184184
}, []);
185185

186186
const restoreSettings = useCallback(() => {
187187
const existing = loadState();
188188

189189
if (existing.auth) {
190-
setAccounts({ ...defaultAuth, ...existing.auth });
190+
setAuth({ ...defaultAuth, ...existing.auth });
191191
}
192192

193193
if (existing.settings) {
@@ -197,44 +197,44 @@ export const AppProvider = ({ children }: { children: ReactNode }) => {
197197
}, []);
198198

199199
const fetchNotificationsWithAccounts = useCallback(
200-
async () => await fetchNotifications(accounts, settings),
201-
[accounts, settings, notifications],
200+
async () => await fetchNotifications(auth, settings),
201+
[auth, settings, notifications],
202202
);
203203

204204
const markNotificationReadWithAccounts = useCallback(
205205
async (id: string, hostname: string) =>
206-
await markNotificationRead(accounts, settings, id, hostname),
207-
[accounts, notifications],
206+
await markNotificationRead(auth, settings, id, hostname),
207+
[auth, notifications],
208208
);
209209

210210
const markNotificationDoneWithAccounts = useCallback(
211211
async (id: string, hostname: string) =>
212-
await markNotificationDone(accounts, settings, id, hostname),
213-
[accounts, notifications],
212+
await markNotificationDone(auth, settings, id, hostname),
213+
[auth, notifications],
214214
);
215215

216216
const unsubscribeNotificationWithAccounts = useCallback(
217217
async (id: string, hostname: string) =>
218-
await unsubscribeNotification(accounts, settings, id, hostname),
219-
[accounts, notifications],
218+
await unsubscribeNotification(auth, settings, id, hostname),
219+
[auth, notifications],
220220
);
221221

222222
const markRepoNotificationsWithAccounts = useCallback(
223223
async (repoSlug: string, hostname: string) =>
224-
await markRepoNotifications(accounts, settings, repoSlug, hostname),
225-
[accounts, notifications],
224+
await markRepoNotifications(auth, settings, repoSlug, hostname),
225+
[auth, notifications],
226226
);
227227

228228
const markRepoNotificationsDoneWithAccounts = useCallback(
229229
async (repoSlug: string, hostname: string) =>
230-
await markRepoNotificationsDone(accounts, settings, repoSlug, hostname),
231-
[accounts, notifications],
230+
await markRepoNotificationsDone(auth, settings, repoSlug, hostname),
231+
[auth, notifications],
232232
);
233233

234234
return (
235235
<AppContext.Provider
236236
value={{
237-
auth: accounts,
237+
auth,
238238
isLoggedIn,
239239
login,
240240
loginEnterprise,

src/routes/Settings.tsx

+3-8
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,7 @@ import { isLinux, isMacOS } from '../utils/platform';
3434
import { setTheme } from '../utils/theme';
3535

3636
export const SettingsRoute: FC = () => {
37-
const {
38-
auth: accounts,
39-
settings,
40-
updateSetting,
41-
logout,
42-
} = useContext(AppContext);
37+
const { auth, settings, updateSetting, logout } = useContext(AppContext);
4338
const navigate = useNavigate();
4439

4540
const [appVersion, setAppVersion] = useState<string | null>(null);
@@ -301,7 +296,7 @@ export const SettingsRoute: FC = () => {
301296
className={footerButtonClass}
302297
title="Login with Personal Access Token"
303298
onClick={loginWithPersonalAccessToken}
304-
hidden={isPersonalAccessTokenLoggedIn(accounts)}
299+
hidden={isPersonalAccessTokenLoggedIn(auth)}
305300
>
306301
<KeyIcon size={18} aria-label="Login with Personal Access Token" />
307302
<PlusIcon size={10} className="ml-1 mb-2" />
@@ -312,7 +307,7 @@ export const SettingsRoute: FC = () => {
312307
className={footerButtonClass}
313308
title="Login with OAuth App"
314309
onClick={loginWithOAuthApp}
315-
hidden={isOAuthAppLoggedIn(accounts)}
310+
hidden={isOAuthAppLoggedIn(auth)}
316311
>
317312
<PersonIcon size={20} aria-label="Login with OAuth App" />
318313
<PlusIcon size={10} className="mb-2" />

0 commit comments

Comments
 (0)