@@ -79,7 +79,7 @@ interface AppContextState {
79
79
export const AppContext = createContext < Partial < AppContextState > > ( { } ) ;
80
80
81
81
export const AppProvider = ( { children } : { children : ReactNode } ) => {
82
- const [ accounts , setAccounts ] = useState < AuthState > ( defaultAuth ) ;
82
+ const [ auth , setAuth ] = useState < AuthState > ( defaultAuth ) ;
83
83
const [ settings , setSettings ] = useState < SettingsState > ( defaultSettings ) ;
84
84
const {
85
85
fetchNotifications,
@@ -104,17 +104,17 @@ export const AppProvider = ({ children }: { children: ReactNode }) => {
104
104
105
105
// biome-ignore lint/correctness/useExhaustiveDependencies: We only want fetchNotifications to be called for certain account or setting changes.
106
106
useEffect ( ( ) => {
107
- fetchNotifications ( accounts , settings ) ;
107
+ fetchNotifications ( auth , settings ) ;
108
108
} , [
109
109
settings . participating ,
110
110
settings . showBots ,
111
111
settings . detailedNotifications ,
112
- accounts . token ,
113
- accounts . enterpriseAccounts . length ,
112
+ auth . token ,
113
+ auth . enterpriseAccounts . length ,
114
114
] ) ;
115
115
116
116
useInterval ( ( ) => {
117
- fetchNotifications ( accounts , settings ) ;
117
+ fetchNotifications ( auth , settings ) ;
118
118
} , Constants . FETCH_INTERVAL ) ;
119
119
120
120
// 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 }) => {
136
136
137
137
const newSettings = { ...settings , [ name ] : value } ;
138
138
setSettings ( newSettings ) ;
139
- saveState ( { auth : accounts , settings : newSettings } ) ;
139
+ saveState ( { auth, settings : newSettings } ) ;
140
140
} ,
141
- [ accounts , settings ] ,
141
+ [ auth , settings ] ,
142
142
) ;
143
143
144
144
const isLoggedIn = useMemo ( ( ) => {
145
- return ! ! accounts . token || accounts . enterpriseAccounts . length > 0 ;
146
- } , [ accounts ] ) ;
145
+ return ! ! auth . token || auth . enterpriseAccounts . length > 0 ;
146
+ } , [ auth ] ) ;
147
147
148
148
const login = useCallback ( async ( ) => {
149
149
const { authCode } = await authGitHub ( ) ;
150
150
const { token } = await getToken ( authCode ) ;
151
151
const hostname = Constants . DEFAULT_AUTH_OPTIONS . hostname ;
152
152
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 ] ) ;
157
157
158
158
const loginEnterprise = useCallback (
159
159
async ( data : AuthOptions ) => {
160
160
const { authOptions, authCode } = await authGitHub ( data ) ;
161
161
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 } ) ;
165
165
} ,
166
- [ accounts , settings ] ,
166
+ [ auth , settings ] ,
167
167
) ;
168
168
169
169
const validateToken = useCallback (
170
170
async ( { token, hostname } : AuthTokenOptions ) => {
171
171
await headNotifications ( hostname , token ) ;
172
172
173
173
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 ) ;
176
176
saveState ( { auth : updatedAccounts , settings } ) ;
177
177
} ,
178
- [ accounts , settings ] ,
178
+ [ auth , settings ] ,
179
179
) ;
180
180
181
181
const logout = useCallback ( ( ) => {
182
- setAccounts ( defaultAuth ) ;
182
+ setAuth ( defaultAuth ) ;
183
183
clearState ( ) ;
184
184
} , [ ] ) ;
185
185
186
186
const restoreSettings = useCallback ( ( ) => {
187
187
const existing = loadState ( ) ;
188
188
189
189
if ( existing . auth ) {
190
- setAccounts ( { ...defaultAuth , ...existing . auth } ) ;
190
+ setAuth ( { ...defaultAuth , ...existing . auth } ) ;
191
191
}
192
192
193
193
if ( existing . settings ) {
@@ -197,44 +197,44 @@ export const AppProvider = ({ children }: { children: ReactNode }) => {
197
197
} , [ ] ) ;
198
198
199
199
const fetchNotificationsWithAccounts = useCallback (
200
- async ( ) => await fetchNotifications ( accounts , settings ) ,
201
- [ accounts , settings , notifications ] ,
200
+ async ( ) => await fetchNotifications ( auth , settings ) ,
201
+ [ auth , settings , notifications ] ,
202
202
) ;
203
203
204
204
const markNotificationReadWithAccounts = useCallback (
205
205
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 ] ,
208
208
) ;
209
209
210
210
const markNotificationDoneWithAccounts = useCallback (
211
211
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 ] ,
214
214
) ;
215
215
216
216
const unsubscribeNotificationWithAccounts = useCallback (
217
217
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 ] ,
220
220
) ;
221
221
222
222
const markRepoNotificationsWithAccounts = useCallback (
223
223
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 ] ,
226
226
) ;
227
227
228
228
const markRepoNotificationsDoneWithAccounts = useCallback (
229
229
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 ] ,
232
232
) ;
233
233
234
234
return (
235
235
< AppContext . Provider
236
236
value = { {
237
- auth : accounts ,
237
+ auth,
238
238
isLoggedIn,
239
239
login,
240
240
loginEnterprise,
0 commit comments