Skip to content

Commit

Permalink
fix: scroll for group list
Browse files Browse the repository at this point in the history
  • Loading branch information
addegbenga committed Aug 31, 2024
1 parent f740f05 commit ac4292b
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 26 deletions.
5 changes: 4 additions & 1 deletion apps/mobile/src/modules/Group/all/AllGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
import {
ActivityIndicator,
FlatList,
RefreshControl,
SafeAreaView,
Text,
TouchableOpacity,
Expand All @@ -22,7 +23,7 @@ import {MainStackNavigationProps} from '../../../types';
import stylesheet from './styles';

export default function AllGroupListComponent() {
const {data, isPending} = useGetGroupList({});
const {data, isPending, isFetching, refetch, fetchNextPage} = useGetGroupList({});
const {mutate: addMember} = useAddMember();
const queryClient = useQueryClient();
const {mutate: addPermission} = useAddPermissions();
Expand Down Expand Up @@ -114,6 +115,8 @@ export default function AllGroupListComponent() {
)}
keyExtractor={(item: any) => item.id}
contentContainerStyle={styles.listContent}
refreshControl={<RefreshControl refreshing={isFetching} onRefresh={() => refetch()} />}
onEndReached={() => fetchNextPage()}
/>
</SafeAreaView>
);
Expand Down
9 changes: 6 additions & 3 deletions apps/mobile/src/modules/Group/groupDetail/GroupChatDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,24 +74,28 @@ const GroupChatDetail: React.FC<GroupChatDetailScreenProps> = ({navigation, rout
groupId={route.params.groupId}
selectedMember={selectedMember}
handleClose={() => modalizeRef.current?.close()}
permissionData={permissionData as any}
/>
</Modalize>
<Modalize ref={editGroupModalizeRef}>
<EditGroup
permissionData={permissionData as any}
metaData={groupMetaData as any}
handleClose={() => editGroupModalizeRef.current?.close()}
groupId={route.params.groupId ? route.params.groupId : ''}
/>
</Modalize>
<Modalize ref={addMemberModalizeRef}>
<AddMemberView
permissionData={permissionData as any}
handleClose={() => addMemberModalizeRef.current?.close()}
groupId={route.params.groupId ? route.params.groupId : ''}
/>
</Modalize>

<Modalize ref={menuModalizeRef}>
<MenuBubble
permissionData={permissionData as any}
groupId={route.params.groupId}
onOpenViewRequest={onOpenViewRequest}
onEditGroup={onOpenEditGroup}
Expand Down Expand Up @@ -198,16 +202,15 @@ const MenuBubble = ({
onDeleteGroup,
onEditGroup,
onOpenViewRequest,
groupId,
permissionData,
}: {
onOpenAddMember: () => void;
onDeleteGroup: () => void;
onEditGroup: () => void;
onOpenViewRequest: () => void;
permissionData: AdminGroupPermission[];
groupId: string;
}) => {
const {data: permissionData, isPending: permissionLoading} = useGetGroupPermission(groupId);

const styles = useStyles(stylesheet);
const theme = useTheme();

Expand Down
5 changes: 3 additions & 2 deletions apps/mobile/src/modules/Group/memberAction/addMember.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
useAddMember,
useAddPermissions,
useGetGroupMemberList,
useGetGroupPermission,
} from 'afk_nostr_sdk';
import {Formik} from 'formik';
import {Text, View} from 'react-native';
Expand All @@ -17,16 +16,18 @@ import stylesheet from './styles';
export default function AddMemberView({
groupId,
handleClose,
permissionData,
}: {
groupId: string;
handleClose: () => void;
permissionData: AdminGroupPermission[];
}) {
const groupMembers = useGetGroupMemberList({
groupId,
});
const {mutate: addMember} = useAddMember();
const {mutate: addPermission} = useAddPermissions();
const {data: permissionData} = useGetGroupPermission(groupId as any);

const queryClient = useQueryClient();
const {showToast} = useToast();
const styles = useStyles(stylesheet);
Expand Down
5 changes: 3 additions & 2 deletions apps/mobile/src/modules/Group/memberAction/editGroup.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {NDKEvent} from '@nostr-dev-kit/ndk';
import {useQueryClient} from '@tanstack/react-query';
import {useGetGroupPermission, useGroupEditMetadata} from 'afk_nostr_sdk';
import {AdminGroupPermission, useGroupEditMetadata} from 'afk_nostr_sdk';
import {Formik} from 'formik';
import {Text, View} from 'react-native';
import {SafeAreaView} from 'react-native-safe-area-context';
Expand All @@ -13,16 +13,17 @@ import stylesheet from '../addGroup/styles';
export const EditGroup = ({
groupId,
handleClose,
permissionData,
}: {
groupId: string;
handleClose: () => void;
metaData: NDKEvent;
permissionData: AdminGroupPermission[];
}) => {
const styles = useStyles(stylesheet);
const {showToast} = useToast();
const queryClient = useQueryClient();
const {mutate} = useGroupEditMetadata();
const {data: permissionData} = useGetGroupPermission(groupId);

const initialValues = {
name: '',
Expand Down
10 changes: 3 additions & 7 deletions apps/mobile/src/modules/Group/memberAction/groupAction.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import {useQueryClient} from '@tanstack/react-query';
import {
AdminGroupPermission,
useAddPermissions,
useGetGroupPermission,
useRemoveMember,
} from 'afk_nostr_sdk';
import {AdminGroupPermission, useAddPermissions, useRemoveMember} from 'afk_nostr_sdk';
import React, {useState} from 'react';
import {ScrollView, Switch, Text, TouchableOpacity, View} from 'react-native';

Expand All @@ -29,12 +24,13 @@ const GroupAdminActions = ({
selectedMember,
handleClose,
groupId,
permissionData,
}: {
selectedMember: any;
handleClose: () => void;
groupId: string;
permissionData: AdminGroupPermission[];
}) => {
const {data: permissionData} = useGetGroupPermission(groupId);
const {mutate: removeMember} = useRemoveMember();
const {mutate: addPermissions} = useAddPermissions();
const queryClient = useQueryClient();
Expand Down
12 changes: 1 addition & 11 deletions apps/mobile/src/modules/Group/message/GroupMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ const GroupChat: React.FC<GroupChatScreenProps> = ({navigation, route}) => {
const {mutate} = useSendGroupMessages();
const styles = useStyles(stylesheet);
const [message, setMessage] = useState('');
const {data: permissionData, isPending: permissionLoading} = useGetGroupPermission(
route.params.groupId,
);
const {data: permissionData} = useGetGroupPermission(route.params.groupId);

// const isMember = memberListData?.data?.pages?.flat().some((e: NDKEvent) => {
// const pubkey = e?.tags?.find((tag: string[]) => tag[0] === 'p')?.[1];
Expand Down Expand Up @@ -104,14 +102,6 @@ const GroupChat: React.FC<GroupChatScreenProps> = ({navigation, route}) => {
);
}

// if (permissionLoading) {
// return (
// <SafeAreaView style={styles.container}>
// <ActivityIndicator />
// </SafeAreaView>
// );
// }

if (
!permissionData?.includes(AdminGroupPermission.ViewAccess) &&
route.params.groupAccess === 'private'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export const useGetGroupPermission = (groupId: string) => {

return useQuery({
queryKey: ['getPermissionsByUserConnected', groupId],
enabled: !!groupId,
queryFn: async () => {
const events = await ndk.fetchEvents({
kinds: [9003],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const useSendGroupMessages = () => {
permissionData: AdminGroupPermission[];
}) => {
if (data.permissionData && !data.permissionData.includes(AdminGroupPermission.ViewAccess)) {
console.log('Hit here');
throw new Error('You do not have permission to send message');
} else {
const event = new NDKEvent(ndk);
Expand Down

0 comments on commit ac4292b

Please sign in to comment.