diff --git a/native/community-settings/tag-farcaster-channel/tag-unfollowed-farcaster-channel.react.js b/native/community-settings/tag-farcaster-channel/tag-unfollowed-farcaster-channel.react.js --- a/native/community-settings/tag-farcaster-channel/tag-unfollowed-farcaster-channel.react.js +++ b/native/community-settings/tag-farcaster-channel/tag-unfollowed-farcaster-channel.react.js @@ -1,8 +1,16 @@ // @flow +import invariant from 'invariant'; import * as React from 'react'; import { View, Text } from 'react-native'; +import { + createOrUpdateFarcasterChannelTagActionTypes, + useCreateOrUpdateFarcasterChannelTag, +} from 'lib/actions/community-actions.js'; +import { NeynarClientContext } from 'lib/components/neynar-client-provider.react.js'; +import { useDispatchActionPromise } from 'lib/utils/redux-promise-utils.js'; + import type { TagFarcasterChannelNavigationProp } from './tag-farcaster-channel-navigator.react.js'; import SubmitButton from '../../components/submit-button.react.js'; import TextInput from '../../components/text-input.react.js'; @@ -18,17 +26,66 @@ +route: NavigationRoute<'TagUnfollowedFarcasterChannel'>, }; -// eslint-disable-next-line no-unused-vars function TagUnfollowedFarcasterChannel(prop: Props): React.Node { + const { navigation, route } = prop; + + const { goBack } = navigation; + const { communityID } = route.params; + const styles = useStyles(unboundStyles); const colors = useColors(); const [channelSelectionText, setChannelSelectionText] = React.useState(''); + const neynarClientContext = React.useContext(NeynarClientContext); + invariant(neynarClientContext, 'NeynarClientContext is missing'); + + const dispatchActionPromise = useDispatchActionPromise(); + + const createOrUpdateFarcasterChannelTag = + useCreateOrUpdateFarcasterChannelTag(); + + const createCreateOrUpdateActionPromise = React.useCallback( + async (channelID: string) => { + try { + return await createOrUpdateFarcasterChannelTag({ + commCommunityID: communityID, + farcasterChannelID: channelID, + }); + } catch (e) { + // TODO: Improve error handling + console.log(e.message); + throw e; + } + }, + [communityID, createOrUpdateFarcasterChannelTag], + ); + const onPressTagChannel = React.useCallback(async () => { - // TODO - }, []); + const channelInfo = + await neynarClientContext.client.fetchFarcasterChannelByName( + channelSelectionText, + ); + + if (!channelInfo) { + // TODO: Improve error handling + return; + } + + await dispatchActionPromise( + createOrUpdateFarcasterChannelTagActionTypes, + createCreateOrUpdateActionPromise(channelInfo.id), + ); + + goBack(); + }, [ + channelSelectionText, + createCreateOrUpdateActionPromise, + dispatchActionPromise, + goBack, + neynarClientContext.client, + ]); const submitButtonVariant = channelSelectionText.length > 0 ? 'enabled' : 'disabled';