diff --git a/native/navigation/community-drawer-content.react.js b/native/navigation/community-drawer-content.react.js --- a/native/navigation/community-drawer-content.react.js +++ b/native/navigation/community-drawer-content.react.js @@ -7,6 +7,8 @@ import { SafeAreaView } from 'react-native-safe-area-context'; import { + fetchAllCommunityInfosWithNamesActionTypes, + fetchAllCommunityInfosWithNames, fetchCommunityInfosActionTypes, useFetchCommunityInfos, } from 'lib/actions/community-actions.js'; @@ -15,7 +17,9 @@ useFetchPrimaryInviteLinks, } from 'lib/actions/link-actions.js'; import { useChildThreadInfosMap } from 'lib/hooks/thread-hooks.js'; +import { useLegacyAshoatKeyserverCall } from 'lib/keyserver-conn/legacy-keyserver-call.js'; import { communityThreadSelector } from 'lib/selectors/thread-selectors.js'; +import type { ClientCommunityInfoWithCommunityName } from 'lib/types/community-types.js'; import { threadTypeIsCommunityRoot } from 'lib/types/thread-types-enum.js'; import { createRecursiveDrawerItemsData, @@ -25,11 +29,15 @@ import { useDispatchActionPromise } from 'lib/utils/redux-promise-utils.js'; import CommunityDrawerItem from './community-drawer-item.react.js'; -import { CommunityCreationRouteName } from './route-names.js'; +import { + CommunityCreationRouteName, + CommunityJoinerModalRouteName, +} from './route-names.js'; import { useNavigateToThread } from '../chat/message-list-types.js'; import SWMansionIcon from '../components/swmansion-icon.react.js'; import { useSelector } from '../redux/redux-utils.js'; import { useStyles } from '../themes/colors.js'; +import Alert from '../utils/alert.js'; import { flattenDrawerItemsData, filterOutThreadAndDescendantIDs, @@ -53,6 +61,11 @@ const dispatchActionPromise = useDispatchActionPromise(); const drawerStatus = useDrawerStatus(); + const fetchPromise = useLegacyAshoatKeyserverCall( + fetchAllCommunityInfosWithNames, + ); + const [fetchedCommunitiesWithNames, setFetchedCommunitiesWithNames] = + React.useState>(null); React.useEffect(() => { if (drawerStatus !== 'open') { return; @@ -65,11 +78,20 @@ fetchCommunityInfosActionTypes, fetchCommunityInfos(), ); + void dispatchActionPromise( + fetchAllCommunityInfosWithNamesActionTypes, + fetchPromise(), + ); + void (async () => { + const response = await fetchPromise(); + setFetchedCommunitiesWithNames(response.allCommunityInfosWithNames); + })(); }, [ callFetchPrimaryLinks, dispatchActionPromise, drawerStatus, fetchCommunityInfos, + fetchPromise, ]); const [expanded, setExpanded] = React.useState>(() => { @@ -169,10 +191,29 @@ ); + const onPressExploreCommunities = React.useCallback(() => { + if (!fetchedCommunitiesWithNames) { + Alert.alert( + 'Couldn’t load communities', + 'Uhh... try again?', + [{ text: 'OK' }], + { + cancelable: false, + }, + ); + return; + } + + navigate<'CommunityJoinerModal'>({ + name: CommunityJoinerModalRouteName, + params: { communities: fetchedCommunitiesWithNames }, + }); + }, [fetchedCommunitiesWithNames, navigate]); + let exploreCommunitiesButton; if (__DEV__) { exploreCommunitiesButton = ( - +