diff --git a/src/renderer/components/app.tsx b/src/renderer/components/app.tsx index 3a9e969..308a45f 100644 --- a/src/renderer/components/app.tsx +++ b/src/renderer/components/app.tsx @@ -20,7 +20,6 @@ import { fetchNotifications, openUrl, setIcon, - changeToken, changeAutoLoad, muteRepo, unmuteRepo, @@ -63,7 +62,6 @@ interface AppConnectedProps { } interface AppConnectedActions { - changeToken: (token: string) => void; setIcon: (icon: IconType) => void; openUrl: OpenUrl; fetchNotifications: () => void; @@ -327,7 +325,6 @@ const actions = { fetchNotifications, openUrl, setIcon, - changeToken, changeAutoLoad, muteRepo, unmuteRepo, diff --git a/src/renderer/lib/gitnews-fetcher.ts b/src/renderer/lib/gitnews-fetcher.ts index e4db3dd..fb9973f 100644 --- a/src/renderer/lib/gitnews-fetcher.ts +++ b/src/renderer/lib/gitnews-fetcher.ts @@ -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) { @@ -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) { diff --git a/src/renderer/lib/reducer.ts b/src/renderer/lib/reducer.ts index 333372b..b2deeb4 100644 --- a/src/renderer/lib/reducer.ts +++ b/src/renderer/lib/reducer.ts @@ -9,7 +9,6 @@ import { AppReduxAction, Note, ActionSetAccounts, - ActionChangeToken, ActionSetDemoMode, ActionChangeToOffline, ActionGotNotes, @@ -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, @@ -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 }; } diff --git a/src/renderer/types.ts b/src/renderer/types.ts index 73308c8..8273dc0 100644 --- a/src/renderer/types.ts +++ b/src/renderer/types.ts @@ -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'; @@ -97,7 +96,6 @@ export type AppReduxAction = | ActionMarkUnread | ActionClearErrors | ActionMarkAllNotesSeen - | ActionChangeToken | ActionSetAccounts | ActionInitToken | ActionChangeToOffline