refactor(GroupMembersScreen): enhance member list management with remote data source
All checks were successful
Frontend CI / build-and-push-web (push) Successful in 2m45s
Frontend CI / ota-android (push) Successful in 13m15s
Frontend CI / build-android-apk (push) Successful in 1h1m10s

- Introduced a new remote data source for managing group members using cursor pagination.
- Updated member list loading logic to utilize the new data source, improving data synchronization and loading states.
- Enhanced member enrichment process by integrating user profiles into the member list.
- Refactored related imports and hooks for better organization and clarity.
This commit is contained in:
lafay
2026-03-23 23:38:53 +08:00
parent c98f1917f7
commit aaf53d1c3b
8 changed files with 205 additions and 19 deletions

View File

@@ -25,7 +25,12 @@ import { MaterialCommunityIcons } from '@expo/vector-icons';
import { colors, spacing, fontSizes, borderRadius } from '../../theme';
import { useAuthStore } from '../../stores';
import { groupService } from '../../services/groupService';
import { groupManager } from '../../stores/groupManager';
import {
createRemoteGroupMemberListSource,
GroupMemberListSourceKind,
IGroupMemberListPagedSource,
} from '../../stores/groupMemberListSources';
import { enrichGroupMembersWithUserProfiles } from '../../stores/groupMemberProfileResolver';
import { Avatar, Text, Button, Loading, EmptyState, Divider, ResponsiveContainer } from '../../components/common';
import { useResponsive, useBreakpointGTE } from '../../hooks/useResponsive';
import { useCursorPagination } from '../../hooks/useCursorPagination';
@@ -36,6 +41,7 @@ import {
import { RootStackParamList } from '../../navigation/types';
const { width: SCREEN_WIDTH } = Dimensions.get('window');
const GROUP_MEMBER_REMOTE_LIST_KIND: GroupMemberListSourceKind = 'cursor';
// 网格布局配置
const GRID_CONFIG = {
@@ -70,7 +76,11 @@ const GroupMembersScreen: React.FC = () => {
return GRID_CONFIG.mobile;
}, [width]);
// 使用游标分页 Hook 管理成员列表
const memberListSource = useMemo<IGroupMemberListPagedSource>(() => {
return createRemoteGroupMemberListSource(GROUP_MEMBER_REMOTE_LIST_KIND, groupId, 50);
}, [groupId]);
// 使用统一数据源 + 游标 Hook 管理成员列表
const {
list: members,
isLoading,
@@ -80,11 +90,12 @@ const GroupMembersScreen: React.FC = () => {
refresh,
error,
} = useCursorPagination(
async ({ cursor, pageSize }) => {
return await groupService.getGroupMembersCursor(groupId, {
cursor,
page_size: pageSize,
});
async ({ cursor }) => {
// cursor 为空表示第一页/刷新,此时重置数据源状态
if (!cursor) {
memberListSource.restart();
}
return await memberListSource.loadNext();
},
{ pageSize: 50 }
);
@@ -95,8 +106,20 @@ const GroupMembersScreen: React.FC = () => {
// 同步分页数据到本地状态
useEffect(() => {
setLocalMembers(members);
setLoading(false);
let active = true;
const syncMembers = async () => {
const enrichedMembers = await enrichGroupMembersWithUserProfiles(members);
if (!active) return;
setLocalMembers(enrichedMembers);
setLoading(false);
};
syncMembers();
return () => {
active = false;
};
}, [members]);
// 当前用户的成员信息