Changeset View
Changeset View
Standalone View
Standalone View
web/redux/redux-setup.js
// @flow | // @flow | ||||||||||
import invariant from 'invariant'; | import invariant from 'invariant'; | ||||||||||
import type { PersistState } from 'redux-persist/src/types'; | import type { PersistState } from 'redux-persist/src/types'; | ||||||||||
import { | import { | ||||||||||
logOutActionTypes, | logOutActionTypes, | ||||||||||
deleteAccountActionTypes, | deleteAccountActionTypes, | ||||||||||
} from 'lib/actions/user-actions'; | } from 'lib/actions/user-actions'; | ||||||||||
import baseReducer from 'lib/reducers/master-reducer'; | import baseReducer from 'lib/reducers/master-reducer'; | ||||||||||
import { nonThreadCalendarFilters } from 'lib/selectors/calendar-filter-selectors'; | |||||||||||
import { mostRecentlyReadThreadSelector } from 'lib/selectors/thread-selectors'; | import { mostRecentlyReadThreadSelector } from 'lib/selectors/thread-selectors'; | ||||||||||
import { isLoggedIn } from 'lib/selectors/user-selectors'; | import { isLoggedIn } from 'lib/selectors/user-selectors'; | ||||||||||
import { invalidSessionDowngrade } from 'lib/shared/account-utils'; | import { invalidSessionDowngrade } from 'lib/shared/account-utils'; | ||||||||||
import type { Shape } from 'lib/types/core'; | import type { Shape } from 'lib/types/core'; | ||||||||||
import type { DraftStore } from 'lib/types/draft-types'; | import type { DraftStore } from 'lib/types/draft-types'; | ||||||||||
import type { EnabledApps } from 'lib/types/enabled-apps'; | import type { EnabledApps } from 'lib/types/enabled-apps'; | ||||||||||
import type { EntryStore } from 'lib/types/entry-types'; | import type { EntryStore } from 'lib/types/entry-types'; | ||||||||||
import type { CalendarFilter } from 'lib/types/filter-types'; | import type { CalendarFilter } from 'lib/types/filter-types'; | ||||||||||
import { calendarThreadFilterTypes } from 'lib/types/filter-types'; | |||||||||||
kamil: can be merged with line 19 | |||||||||||
import type { LifecycleState } from 'lib/types/lifecycle-state-types'; | import type { LifecycleState } from 'lib/types/lifecycle-state-types'; | ||||||||||
import type { LoadingStatus } from 'lib/types/loading-types'; | import type { LoadingStatus } from 'lib/types/loading-types'; | ||||||||||
import type { MessageStore } from 'lib/types/message-types'; | import type { MessageStore } from 'lib/types/message-types'; | ||||||||||
import type { UserPolicies } from 'lib/types/policy-types.js'; | import type { UserPolicies } from 'lib/types/policy-types.js'; | ||||||||||
import type { BaseAction } from 'lib/types/redux-types'; | import type { BaseAction } from 'lib/types/redux-types'; | ||||||||||
import type { ReportStore } from 'lib/types/report-types'; | import type { ReportStore } from 'lib/types/report-types'; | ||||||||||
import type { ConnectionInfo } from 'lib/types/socket-types'; | import type { ConnectionInfo } from 'lib/types/socket-types'; | ||||||||||
import type { ThreadStore } from 'lib/types/thread-types'; | import type { ThreadStore } from 'lib/types/thread-types'; | ||||||||||
import type { CurrentUserInfo, UserStore } from 'lib/types/user-types'; | import type { CurrentUserInfo, UserStore } from 'lib/types/user-types'; | ||||||||||
import { setNewSessionActionType } from 'lib/utils/action-utils'; | import { setNewSessionActionType } from 'lib/utils/action-utils'; | ||||||||||
import { activeThreadSelector } from '../selectors/nav-selectors'; | import { activeThreadSelector } from '../selectors/nav-selectors'; | ||||||||||
import { filteredCommunityThreadIDs } from '../selectors/thread-selectors'; | |||||||||||
import { type NavInfo } from '../types/nav-types'; | import { type NavInfo } from '../types/nav-types'; | ||||||||||
import { | import { | ||||||||||
updateWindowActiveActionType, | updateWindowActiveActionType, | ||||||||||
setDeviceIDActionType, | setDeviceIDActionType, | ||||||||||
updateNavInfoActionType, | updateNavInfoActionType, | ||||||||||
updateWindowDimensionsActionType, | updateWindowDimensionsActionType, | ||||||||||
updateCalendarCommunityFilter, | |||||||||||
clearCalendarCommunityFilter, | |||||||||||
} from './action-types'; | } from './action-types'; | ||||||||||
import { reduceDeviceID } from './device-id-reducer'; | import { reduceDeviceID } from './device-id-reducer'; | ||||||||||
import reduceNavInfo from './nav-reducer'; | import reduceNavInfo from './nav-reducer'; | ||||||||||
import { | import { | ||||||||||
reducePrimaryIdentityPublicKey, | reducePrimaryIdentityPublicKey, | ||||||||||
setPrimaryIdentityPublicKey, | setPrimaryIdentityPublicKey, | ||||||||||
} from './primary-identity-public-key-reducer'; | } from './primary-identity-public-key-reducer'; | ||||||||||
import { getVisibility } from './visibility'; | import { getVisibility } from './visibility'; | ||||||||||
▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | export type Action = | ||||||||||
| { | | { | ||||||||||
type: 'UPDATE_WINDOW_ACTIVE', | type: 'UPDATE_WINDOW_ACTIVE', | ||||||||||
payload: boolean, | payload: boolean, | ||||||||||
} | } | ||||||||||
| { | | { | ||||||||||
type: 'SET_DEVICE_ID', | type: 'SET_DEVICE_ID', | ||||||||||
payload: string, | payload: string, | ||||||||||
} | } | ||||||||||
| { +type: 'SET_PRIMARY_IDENTITY_PUBLIC_KEY', payload: ?string }; | | { +type: 'SET_PRIMARY_IDENTITY_PUBLIC_KEY', payload: ?string } | ||||||||||
| { | |||||||||||
+type: 'UPDATE_CALENDAR_COMMUNITY_FILTER', | |||||||||||
+payload: string, | |||||||||||
} | |||||||||||
| { | |||||||||||
+type: 'CLEAR_CALENDAR_COMMUNITY_FILTER', | |||||||||||
+payload: void, | |||||||||||
}; | |||||||||||
export function reducer(oldState: AppState | void, action: Action): AppState { | export function reducer(oldState: AppState | void, action: Action): AppState { | ||||||||||
invariant(oldState, 'should be set'); | invariant(oldState, 'should be set'); | ||||||||||
let state = oldState; | let state = oldState; | ||||||||||
if (action.type === updateWindowDimensionsActionType) { | if (action.type === updateWindowDimensionsActionType) { | ||||||||||
return validateState(oldState, { | return validateState(oldState, { | ||||||||||
...state, | ...state, | ||||||||||
windowDimensions: action.payload, | windowDimensions: action.payload, | ||||||||||
}); | }); | ||||||||||
} else if (action.type === updateWindowActiveActionType) { | } else if (action.type === updateWindowActiveActionType) { | ||||||||||
return validateState(oldState, { | return validateState(oldState, { | ||||||||||
...state, | ...state, | ||||||||||
windowActive: action.payload, | windowActive: action.payload, | ||||||||||
}); | }); | ||||||||||
} else if (action.type === updateCalendarCommunityFilter) { | |||||||||||
const nonThreadFilters = nonThreadCalendarFilters(state.calendarFilters); | |||||||||||
const threadIDs = Array.from( | |||||||||||
filteredCommunityThreadIDs(action.payload, state.threadStore.threadInfos), | |||||||||||
); | |||||||||||
return { | |||||||||||
...state, | |||||||||||
calendarFilters: [ | |||||||||||
...nonThreadFilters, | |||||||||||
{ | |||||||||||
type: calendarThreadFilterTypes.THREAD_LIST, | |||||||||||
threadIDs: threadIDs, | |||||||||||
kamilUnsubmitted Not Done Inline Actions
can be shortened kamil: can be shortened | |||||||||||
}, | |||||||||||
inkaAuthorUnsubmitted Done Inline ActionsWe reset the threads filter, so that only chats from the picked community are picked, and all of them are picked. inka: We reset the `threads` filter, so that only chats from the picked community are picked, and all… | |||||||||||
], | |||||||||||
communityIDFilter: action.payload, | |||||||||||
}; | |||||||||||
} else if (action.type === clearCalendarCommunityFilter) { | |||||||||||
const nonThreadFilters = nonThreadCalendarFilters(state.calendarFilters); | |||||||||||
return { | |||||||||||
...state, | |||||||||||
calendarFilters: [...nonThreadFilters], | |||||||||||
inkaAuthorUnsubmitted Done Inline ActionsWe reset the threads filter, so that all chats are picked inka: We reset the `threads` filter, so that all chats are picked | |||||||||||
kamilUnsubmitted Not Done Inline ActionsIs the destruction needed? Can it be just calendarFilters: nonThreadFilters? kamil: Is the destruction needed? Can it be just `calendarFilters: nonThreadFilters`? | |||||||||||
communityIDFilter: null, | |||||||||||
}; | |||||||||||
} else if (action.type === setNewSessionActionType) { | } else if (action.type === setNewSessionActionType) { | ||||||||||
if ( | if ( | ||||||||||
invalidSessionDowngrade( | invalidSessionDowngrade( | ||||||||||
oldState, | oldState, | ||||||||||
action.payload.sessionChange.currentUserInfo, | action.payload.sessionChange.currentUserInfo, | ||||||||||
action.payload.preRequestUserState, | action.payload.preRequestUserState, | ||||||||||
) | ) | ||||||||||
) { | ) { | ||||||||||
▲ Show 20 Lines • Show All 144 Lines • Show Last 20 Lines |
can be merged with line 19