Changeset View
Changeset View
Standalone View
Standalone View
web/selectors/thread-selectors.js
// @flow | // @flow | ||||
import invariant from 'invariant'; | import invariant from 'invariant'; | ||||
import * as React from 'react'; | import * as React from 'react'; | ||||
import { useDispatch } from 'react-redux'; | import { useDispatch } from 'react-redux'; | ||||
import { createSelector } from 'reselect'; | |||||
import { ENSCacheContext } from 'lib/components/ens-cache-provider.react'; | import { ENSCacheContext } from 'lib/components/ens-cache-provider.react'; | ||||
import { createPendingSidebar } from 'lib/shared/thread-utils'; | import { createPendingSidebar } from 'lib/shared/thread-utils'; | ||||
import type { | import type { | ||||
ComposableMessageInfo, | ComposableMessageInfo, | ||||
RobotextMessageInfo, | RobotextMessageInfo, | ||||
} from 'lib/types/message-types'; | } from 'lib/types/message-types'; | ||||
import type { ThreadInfo } from 'lib/types/thread-types'; | import type { ThreadInfo } from 'lib/types/thread-types'; | ||||
import { getDefaultTextMessageRules } from '../markdown/rules.react'; | import { getDefaultTextMessageRules } from '../markdown/rules.react'; | ||||
import { updateNavInfoActionType } from '../redux/action-types'; | import { updateNavInfoActionType } from '../redux/action-types'; | ||||
import type { AppState, CalendarCommunityFilter } from '../redux/redux-setup'; | |||||
import { useSelector } from '../redux/redux-utils'; | import { useSelector } from '../redux/redux-utils'; | ||||
function useOnClickThread( | function useOnClickThread( | ||||
thread: ?ThreadInfo, | thread: ?ThreadInfo, | ||||
): (event: SyntheticEvent<HTMLElement>) => void { | ): (event: SyntheticEvent<HTMLElement>) => void { | ||||
const dispatch = useDispatch(); | const dispatch = useDispatch(); | ||||
return React.useCallback( | return React.useCallback( | ||||
(event: SyntheticEvent<HTMLElement>) => { | (event: SyntheticEvent<HTMLElement>) => { | ||||
▲ Show 20 Lines • Show All 77 Lines • ▼ Show 20 Lines | (event: SyntheticEvent<HTMLElement>) => { | ||||
selectedUserList: [], | selectedUserList: [], | ||||
}, | }, | ||||
}); | }); | ||||
}, | }, | ||||
[dispatch], | [dispatch], | ||||
); | ); | ||||
} | } | ||||
const filteredCommunityThreadIDsSelector: ( | |||||
state: AppState, | |||||
) => ?$ReadOnlySet<string> = createSelector( | |||||
(state: AppState) => state.communityFilter, | |||||
(communityFilter: ?CalendarCommunityFilter): ?Set<string> => { | |||||
if (!communityFilter || communityFilter.threadIDs.length === 0) { | |||||
return null; | |||||
} | |||||
return new Set(communityFilter.threadIDs); | |||||
}, | |||||
); | |||||
export { | export { | ||||
useOnClickThread, | useOnClickThread, | ||||
useThreadIsActive, | useThreadIsActive, | ||||
useOnClickPendingSidebar, | useOnClickPendingSidebar, | ||||
useOnClickNewThread, | useOnClickNewThread, | ||||
filteredCommunityThreadIDsSelector, | |||||
}; | }; |