Changeset View
Changeset View
Standalone View
Standalone View
lib/reducers/calendar-filters-reducer.js
// @flow | // @flow | ||||
import { | |||||
updateCalendarCommunityFilter, | |||||
clearCalendarCommunityFilter, | |||||
} from '../actions/community-actions.js'; | |||||
import { siweAuthActionTypes } from '../actions/siwe-actions.js'; | import { siweAuthActionTypes } from '../actions/siwe-actions.js'; | ||||
import { | import { | ||||
newThreadActionTypes, | newThreadActionTypes, | ||||
joinThreadActionTypes, | joinThreadActionTypes, | ||||
leaveThreadActionTypes, | leaveThreadActionTypes, | ||||
deleteThreadActionTypes, | deleteThreadActionTypes, | ||||
} from '../actions/thread-actions.js'; | } from '../actions/thread-actions.js'; | ||||
import { | import { | ||||
Show All 16 Lines | import { | ||||
setCalendarDeletedFilter, | setCalendarDeletedFilter, | ||||
calendarThreadFilterTypes, | calendarThreadFilterTypes, | ||||
} from '../types/filter-types.js'; | } from '../types/filter-types.js'; | ||||
import type { BaseAction } from '../types/redux-types.js'; | import type { BaseAction } from '../types/redux-types.js'; | ||||
import { | import { | ||||
fullStateSyncActionType, | fullStateSyncActionType, | ||||
incrementalStateSyncActionType, | incrementalStateSyncActionType, | ||||
} from '../types/socket-types.js'; | } from '../types/socket-types.js'; | ||||
import type { RawThreadInfo } from '../types/thread-types.js'; | import type { RawThreadInfo, ThreadStore } from '../types/thread-types.js'; | ||||
import { updateTypes } from '../types/update-types-enum.js'; | import { updateTypes } from '../types/update-types-enum.js'; | ||||
import { | import { | ||||
type ClientUpdateInfo, | type ClientUpdateInfo, | ||||
processUpdatesActionType, | processUpdatesActionType, | ||||
} from '../types/update-types.js'; | } from '../types/update-types.js'; | ||||
import { setNewSessionActionType } from '../utils/action-utils.js'; | import { setNewSessionActionType } from '../utils/action-utils.js'; | ||||
import { filterThreadIDsBelongingToCommunity } from '../utils/drawer-utils.react.js'; | |||||
export default function reduceCalendarFilters( | export default function reduceCalendarFilters( | ||||
state: $ReadOnlyArray<CalendarFilter>, | state: $ReadOnlyArray<CalendarFilter>, | ||||
action: BaseAction, | action: BaseAction, | ||||
threadStore: ThreadStore, | |||||
): $ReadOnlyArray<CalendarFilter> { | ): $ReadOnlyArray<CalendarFilter> { | ||||
if ( | if ( | ||||
action.type === logOutActionTypes.success || | action.type === logOutActionTypes.success || | ||||
action.type === deleteAccountActionTypes.success || | action.type === deleteAccountActionTypes.success || | ||||
action.type === logInActionTypes.success || | action.type === logInActionTypes.success || | ||||
action.type === siweAuthActionTypes.success || | action.type === siweAuthActionTypes.success || | ||||
action.type === registerActionTypes.success || | action.type === registerActionTypes.success || | ||||
(action.type === setNewSessionActionType && | (action.type === setNewSessionActionType && | ||||
▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | return updateFilterListFromUpdateInfos( | ||||
state, | state, | ||||
action.payload.updatesResult.newUpdates, | action.payload.updatesResult.newUpdates, | ||||
); | ); | ||||
} else if (action.type === fullStateSyncActionType) { | } else if (action.type === fullStateSyncActionType) { | ||||
return removeDeletedThreadIDsFromFilterList( | return removeDeletedThreadIDsFromFilterList( | ||||
state, | state, | ||||
action.payload.threadInfos, | action.payload.threadInfos, | ||||
); | ); | ||||
} else if (action.type === updateCalendarCommunityFilter) { | |||||
const nonThreadFilters = nonThreadCalendarFilters(state); | |||||
const threadIDs = Array.from( | |||||
filterThreadIDsBelongingToCommunity( | |||||
action.payload, | |||||
threadStore.threadInfos, | |||||
), | |||||
); | |||||
return [ | |||||
...nonThreadFilters, | |||||
{ | |||||
type: calendarThreadFilterTypes.THREAD_LIST, | |||||
threadIDs, | |||||
}, | |||||
]; | |||||
} else if (action.type === clearCalendarCommunityFilter) { | |||||
const nonThreadFilters = nonThreadCalendarFilters(state); | |||||
return nonThreadFilters; | |||||
} | } | ||||
return state; | return state; | ||||
} | } | ||||
function updateFilterListFromUpdateInfos( | function updateFilterListFromUpdateInfos( | ||||
state: $ReadOnlyArray<CalendarFilter>, | state: $ReadOnlyArray<CalendarFilter>, | ||||
updateInfos: $ReadOnlyArray<ClientUpdateInfo>, | updateInfos: $ReadOnlyArray<ClientUpdateInfo>, | ||||
): $ReadOnlyArray<CalendarFilter> { | ): $ReadOnlyArray<CalendarFilter> { | ||||
▲ Show 20 Lines • Show All 58 Lines • Show Last 20 Lines |