Use FlatList for home agent list
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { View, Text, Pressable, ScrollView, Modal } from "react-native";
|
import { View, Text, Pressable, FlatList, Modal, type ListRenderItem } from "react-native";
|
||||||
import { useCallback, useState } from "react";
|
import { useCallback, useState } from "react";
|
||||||
import { router } from "expo-router";
|
import { router } from "expo-router";
|
||||||
import { StyleSheet, useUnistyles } from "react-native-unistyles";
|
import { StyleSheet, useUnistyles } from "react-native-unistyles";
|
||||||
@@ -56,10 +56,8 @@ export function AgentList({ agents }: AgentListProps) {
|
|||||||
setActionAgent(null);
|
setActionAgent(null);
|
||||||
}, [actionAgent, deleteAgent]);
|
}, [actionAgent, deleteAgent]);
|
||||||
|
|
||||||
return (
|
const renderAgentItem = useCallback<ListRenderItem<AggregatedAgent>>(
|
||||||
<>
|
({ item: agent }) => {
|
||||||
<ScrollView style={styles.container} showsVerticalScrollIndicator={false}>
|
|
||||||
{agents.map((agent) => {
|
|
||||||
const statusColor = getAgentStatusColor(agent.status);
|
const statusColor = getAgentStatusColor(agent.status);
|
||||||
const statusLabel = getAgentStatusLabel(agent.status);
|
const statusLabel = getAgentStatusLabel(agent.status);
|
||||||
const timeAgo = formatTimeAgo(agent.lastActivityAt);
|
const timeAgo = formatTimeAgo(agent.lastActivityAt);
|
||||||
@@ -67,7 +65,6 @@ export function AgentList({ agents }: AgentListProps) {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Pressable
|
<Pressable
|
||||||
key={`${agent.serverId}:${agent.id}`}
|
|
||||||
style={({ pressed }) => [
|
style={({ pressed }) => [
|
||||||
styles.agentItem,
|
styles.agentItem,
|
||||||
pressed && styles.agentItemPressed,
|
pressed && styles.agentItemPressed,
|
||||||
@@ -127,8 +124,26 @@ export function AgentList({ agents }: AgentListProps) {
|
|||||||
</View>
|
</View>
|
||||||
</Pressable>
|
</Pressable>
|
||||||
);
|
);
|
||||||
})}
|
},
|
||||||
</ScrollView>
|
[handleAgentLongPress, handleAgentPress, theme.colors.muted, theme.colors.mutedForeground]
|
||||||
|
);
|
||||||
|
|
||||||
|
const keyExtractor = useCallback(
|
||||||
|
(agent: AggregatedAgent) => `${agent.serverId}:${agent.id}`,
|
||||||
|
[]
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<FlatList
|
||||||
|
data={agents}
|
||||||
|
style={styles.list}
|
||||||
|
contentContainerStyle={styles.listContent}
|
||||||
|
keyExtractor={keyExtractor}
|
||||||
|
renderItem={renderAgentItem}
|
||||||
|
showsVerticalScrollIndicator={false}
|
||||||
|
keyboardShouldPersistTaps="handled"
|
||||||
|
/>
|
||||||
|
|
||||||
<Modal
|
<Modal
|
||||||
visible={isActionSheetVisible}
|
visible={isActionSheetVisible}
|
||||||
@@ -176,10 +191,13 @@ export function AgentList({ agents }: AgentListProps) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const styles = StyleSheet.create((theme) => ({
|
const styles = StyleSheet.create((theme) => ({
|
||||||
container: {
|
list: {
|
||||||
flex: 1,
|
flex: 1,
|
||||||
|
},
|
||||||
|
listContent: {
|
||||||
paddingHorizontal: theme.spacing[4],
|
paddingHorizontal: theme.spacing[4],
|
||||||
paddingTop: theme.spacing[4],
|
paddingTop: theme.spacing[4],
|
||||||
|
paddingBottom: theme.spacing[4],
|
||||||
},
|
},
|
||||||
agentItem: {
|
agentItem: {
|
||||||
paddingVertical: theme.spacing[4],
|
paddingVertical: theme.spacing[4],
|
||||||
|
|||||||
Reference in New Issue
Block a user