diff --git a/native/components/community-actions-button.react.js b/native/components/community-actions-button.react.js
index 5fc3ff696..ed20b98b0 100644
--- a/native/components/community-actions-button.react.js
+++ b/native/components/community-actions-button.react.js
@@ -1,189 +1,192 @@
// @flow
import { useActionSheet } from '@expo/react-native-action-sheet';
import { useNavigation } from '@react-navigation/native';
import * as React from 'react';
import { TouchableOpacity, View } from 'react-native';
import { useSafeAreaInsets } from 'react-native-safe-area-context';
import { primaryInviteLinksSelector } from 'lib/selectors/invite-links-selectors.js';
-import { threadHasPermission } from 'lib/shared/thread-utils.js';
+import { useThreadHasPermission } from 'lib/shared/thread-utils.js';
import type { ThreadInfo } from 'lib/types/minimally-encoded-thread-permissions-types.js';
import { threadPermissions } from 'lib/types/thread-permission-types.js';
import { threadTypes } from 'lib/types/thread-types-enum.js';
import { useCurrentUserFID } from 'lib/utils/farcaster-utils.js';
import { usingCommServicesAccessToken } from 'lib/utils/services-utils.js';
import SWMansionIcon from './swmansion-icon.react.js';
import {
CommunityRolesScreenRouteName,
InviteLinkNavigatorRouteName,
ManagePublicLinkRouteName,
RolesNavigatorRouteName,
ViewInviteLinksRouteName,
TagFarcasterChannelNavigatorRouteName,
TagFarcasterChannelRouteName,
} from '../navigation/route-names.js';
import { useSelector } from '../redux/redux-utils.js';
import { useStyles } from '../themes/colors.js';
type Props = {
+community: ThreadInfo,
};
function CommunityActionsButton(props: Props): React.Node {
const { community } = props;
const inviteLink = useSelector(primaryInviteLinksSelector)[community.id];
const { navigate } = useNavigation();
const fid = useCurrentUserFID();
const navigateToInviteLinksView = React.useCallback(() => {
if (!inviteLink || !community) {
return;
}
navigate<'InviteLinkNavigator'>(InviteLinkNavigatorRouteName, {
screen: ViewInviteLinksRouteName,
params: {
community,
},
});
}, [community, inviteLink, navigate]);
const navigateToManagePublicLinkView = React.useCallback(() => {
navigate<'InviteLinkNavigator'>(InviteLinkNavigatorRouteName, {
screen: ManagePublicLinkRouteName,
params: {
community,
},
});
}, [community, navigate]);
const navigateToCommunityRolesScreen = React.useCallback(() => {
navigate<'RolesNavigator'>(RolesNavigatorRouteName, {
screen: CommunityRolesScreenRouteName,
params: {
threadInfo: community,
},
});
}, [community, navigate]);
const navigateToTagFarcasterChannel = React.useCallback(() => {
navigate<'TagFarcasterChannelNavigator'>(
TagFarcasterChannelNavigatorRouteName,
{
screen: TagFarcasterChannelRouteName,
},
);
}, [navigate]);
const insets = useSafeAreaInsets();
const activeTheme = useSelector(state => state.globalThemeInfo.activeTheme);
const styles = useStyles(unboundStyles);
+ const canManageLinks = useThreadHasPermission(
+ community,
+ threadPermissions.MANAGE_INVITE_LINKS,
+ );
+ const canChangeRoles = useThreadHasPermission(
+ community,
+ threadPermissions.CHANGE_ROLE,
+ );
+
const { showActionSheetWithOptions } = useActionSheet();
const actions = React.useMemo(() => {
if (!community) {
return null;
}
const result = [];
- const canManageLinks = threadHasPermission(
- community,
- threadPermissions.MANAGE_INVITE_LINKS,
- );
if (canManageLinks) {
result.push({
label: 'Manage invite links',
action: navigateToManagePublicLinkView,
});
}
if (inviteLink) {
result.push({
label: 'Invite link',
action: navigateToInviteLinksView,
});
}
- const canChangeRoles = threadHasPermission(
- community,
- threadPermissions.CHANGE_ROLE,
- );
if (canChangeRoles) {
result.push({
label: 'Manage roles',
action: navigateToCommunityRolesScreen,
});
}
const canTagFarcasterChannel =
fid &&
community.type !== threadTypes.GENESIS &&
(usingCommServicesAccessToken || __DEV__);
if (canTagFarcasterChannel) {
result.push({
label: 'Tag Farcaster channel',
action: navigateToTagFarcasterChannel,
});
}
if (result.length > 0) {
return result;
}
return null;
}, [
community,
+ canManageLinks,
inviteLink,
+ canChangeRoles,
fid,
navigateToManagePublicLinkView,
navigateToInviteLinksView,
navigateToCommunityRolesScreen,
navigateToTagFarcasterChannel,
]);
const openActionSheet = React.useCallback(() => {
if (!actions) {
return;
}
const options = [...actions.map(a => a.label), 'Cancel'];
showActionSheetWithOptions(
{
options,
cancelButtonIndex: options.length - 1,
containerStyle: {
paddingBottom: insets.bottom,
},
userInterfaceStyle: activeTheme ?? 'dark',
},
selectedIndex => {
if (selectedIndex !== undefined && selectedIndex < actions.length) {
actions[selectedIndex].action();
}
},
);
}, [actions, activeTheme, insets.bottom, showActionSheetWithOptions]);
let button = null;
if (actions) {
button = (
);
}
return {button};
}
const unboundStyles = {
button: {
color: 'drawerItemLabelLevel0',
},
container: {
width: 22,
},
};
export default CommunityActionsButton;