Skip to content

Commit

Permalink
Re-fetch when accounts change
Browse files Browse the repository at this point in the history
  • Loading branch information
sirbrillig committed Sep 9, 2024
1 parent 1b9a090 commit 9a47fac
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 28 deletions.
3 changes: 0 additions & 3 deletions src/renderer/components/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import {
fetchNotifications,
openUrl,
setIcon,
changeToken,
changeAutoLoad,
muteRepo,
unmuteRepo,
Expand Down Expand Up @@ -63,7 +62,6 @@ interface AppConnectedProps {
}

interface AppConnectedActions {
changeToken: (token: string) => void;
setIcon: (icon: IconType) => void;
openUrl: OpenUrl;
fetchNotifications: () => void;
Expand Down Expand Up @@ -327,7 +325,6 @@ const actions = {
fetchNotifications,
openUrl,
setIcon,
changeToken,
changeAutoLoad,
muteRepo,
unmuteRepo,
Expand Down
24 changes: 11 additions & 13 deletions src/renderer/lib/gitnews-fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export function createFetcher(): Middleware<{}, AppReduxState> {
if (!isDispatch(next)) {
throw new Error('Invalid dispatcher in fetcher');
}

if (action.type === 'MARK_NOTE_READ' && store.getState().isDemoMode) {
currentDemoNotifications = currentDemoNotifications.map((note) => {
if (note.id === action.note.id) {
Expand All @@ -48,27 +49,24 @@ export function createFetcher(): Middleware<{}, AppReduxState> {
return next(action);
}

if (action.type === 'CHANGE_TOKEN') {
debug('Token being changed; fetching with new token');
if (action.type === 'SET_ACCOUNTS') {
debug('Accounts changed; fetching with updated accounts');
window.electronApi.logMessage(
'Token being changed; fetching with new token',
'Accounts changed; fetching with updated accounts',
'info'
);
performFetch(
Object.assign({}, store.getState(), { token: action.token }),
next
);
performFetch(store.getState(), next);
return next(action);
}

if (action.type !== 'GITNEWS_FETCH_NOTIFICATIONS') {
return next(action);
if (action.type === 'GITNEWS_FETCH_NOTIFICATIONS') {
debug('Fetching accounts');
window.electronApi.logMessage('Fetching accounts', 'info');
performFetch(store.getState(), next);
return;
}

debug('fetching with existing token');
window.electronApi.logMessage('Fetching with existing token', 'info');
performFetch(store.getState(), next);
return;
return next(action);
};

async function performFetch(state: AppReduxState, next: AppDispatch) {
Expand Down
10 changes: 0 additions & 10 deletions src/renderer/lib/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
AppReduxAction,
Note,
ActionSetAccounts,
ActionChangeToken,
ActionSetDemoMode,
ActionChangeToOffline,
ActionGotNotes,
Expand Down Expand Up @@ -121,11 +120,6 @@ export function createReducer() {
...state,
accounts: action.accounts,
};
case 'CHANGE_TOKEN':
return Object.assign({}, state, {
token: action.token,
isTokenInvalid: false,
});
case 'SELECT_ACCOUNT':
return {
...state,
Expand Down Expand Up @@ -213,10 +207,6 @@ export function markAllNotesSeen(): ActionMarkAllNotesSeen {
return { type: 'MARK_ALL_NOTES_SEEN' };
}

export function changeToken(token: string): ActionChangeToken {
return { type: 'CHANGE_TOKEN', token };
}

export function initToken(token: string): ActionInitToken {
return { type: 'SET_INITIAL_TOKEN', token };
}
Expand Down
2 changes: 0 additions & 2 deletions src/renderer/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ export type ActionMarkRead = {
export type ActionMarkUnread = { type: 'MARK_NOTE_UNREAD'; note: Note };
export type ActionClearErrors = { type: 'CLEAR_ERRORS' };
export type ActionMarkAllNotesSeen = { type: 'MARK_ALL_NOTES_SEEN' };
export type ActionChangeToken = { type: 'CHANGE_TOKEN'; token: string };
export type ActionInitToken = { type: 'SET_INITIAL_TOKEN'; token: string };
export type ActionSelectAccount = {
type: 'SELECT_ACCOUNT';
Expand Down Expand Up @@ -97,7 +96,6 @@ export type AppReduxAction =
| ActionMarkUnread
| ActionClearErrors
| ActionMarkAllNotesSeen
| ActionChangeToken
| ActionSetAccounts
| ActionInitToken
| ActionChangeToOffline
Expand Down

0 comments on commit 9a47fac

Please sign in to comment.