diff --git a/web/calendar/filter-panel.react.js b/web/calendar/filter-panel.react.js --- a/web/calendar/filter-panel.react.js +++ b/web/calendar/filter-panel.react.js @@ -19,6 +19,7 @@ import { filteredThreadIDsSelector, includeDeletedSelector, + filteredCommunityThreadIDsSelector, } from 'lib/selectors/calendar-filter-selectors'; import SearchIndex from 'lib/shared/search-index'; import { @@ -27,6 +28,8 @@ updateCalendarThreadFilter, clearCalendarThreadFilter, setCalendarDeletedFilter, + updateCalendarCommunityFilter, + clearCalendarCommunityFilter, } from 'lib/types/filter-types'; import type { Dispatch } from 'lib/types/redux-types'; @@ -43,6 +46,7 @@ +filterThreadInfos: () => $ReadOnlyArray, +filterThreadSearchIndex: () => SearchIndex, +filteredThreadIDs: ?$ReadOnlySet, + +filteredCommunityThreadIDs: ?$ReadOnlySet, +includeDeleted: boolean, +dispatch: Dispatch, +pushModal: PushModal, @@ -66,10 +70,20 @@ return this.props.filteredThreadIDs.has(threadID); } + inCurrentCommunity(threadID: string): boolean { + if (!this.props.filteredCommunityThreadIDs) { + return true; + } + return this.props.filteredCommunityThreadIDs.has(threadID); + } + render() { - const filterThreadInfos = this.state.query + let filterThreadInfos = this.state.query ? this.state.searchResults : this.props.filterThreadInfos(); + filterThreadInfos = filterThreadInfos.filter(item => + this.inCurrentCommunity(item.threadInfo.id), + ); let filters = []; if (!this.state.query || filterThreadInfos.length > 0) { @@ -220,6 +234,30 @@ this.setState({ query, searchResults: results, collapsed: false }); }; + onSetCommunity = (communityID: string) => { + const threadIDs = this.props + .filterThreadInfos() + .filter( + thread => + thread.threadInfo.community === communityID || + thread.threadInfo.id === communityID, + ) + .map(item => item.threadInfo.id); + this.props.dispatch({ + type: updateCalendarCommunityFilter, + payload: { + type: calendarThreadFilterTypes.COMMUNITY, + threadIDs, + }, + }); + }; + + onResetCommunity = () => { + this.props.dispatch({ + type: clearCalendarCommunityFilter, + }); + }; + clearQuery = (event: SyntheticEvent) => { event.preventDefault(); this.setState({ query: '', searchResults: [], collapsed: false }); @@ -365,6 +403,9 @@ const ConnectedFilterPanel: React.ComponentType<{}> = React.memo<{}>( function ConnectedFilterPanel(): React.Node { const filteredThreadIDs = useSelector(filteredThreadIDsSelector); + const filteredCommunityThreadIDs = useSelector( + filteredCommunityThreadIDsSelector, + ); const filterThreadInfos = useSelector(webFilterThreadInfos); const filterThreadSearchIndex = useSelector(webFilterThreadSearchIndex); const includeDeleted = useSelector(includeDeletedSelector); @@ -374,6 +415,7 @@ return (