({
list,
onPress,
onDelete,
}: {
list: {
id: string
name: string
totalItems: any
checkedItems: any
uncheckedPreview: any
$synced?: boolean
}
onPress: () => void
onDelete: () => void
})
| 16 | |
| 17 | // Subcomponent that subscribes to the child aggregate collections for reactive counts |
| 18 | function ListCard({ |
| 19 | list, |
| 20 | onPress, |
| 21 | onDelete, |
| 22 | }: { |
| 23 | list: { |
| 24 | id: string |
| 25 | name: string |
| 26 | totalItems: any |
| 27 | checkedItems: any |
| 28 | uncheckedPreview: any |
| 29 | $synced?: boolean |
| 30 | } |
| 31 | onPress: () => void |
| 32 | onDelete: () => void |
| 33 | }) { |
| 34 | // Subscribe to the child collections — this is the "includes" pattern for React |
| 35 | const { data: totalData } = useLiveQuery(list.totalItems) |
| 36 | const { data: checkedData } = useLiveQuery(list.checkedItems) |
| 37 | const { data: uncheckedPreviewData } = useLiveQuery(list.uncheckedPreview) |
| 38 | const totalCount = (totalData as any)?.[0]?.n ?? 0 |
| 39 | const checkedCount = (checkedData as any)?.[0]?.n ?? 0 |
| 40 | const uncheckedPreview = |
| 41 | (uncheckedPreviewData as any as Array<{ text: string }> | undefined) ?? [] |
| 42 | const uncheckedCount = Math.max(0, totalCount - checkedCount) |
| 43 | const remainingCount = Math.max(0, uncheckedCount - uncheckedPreview.length) |
| 44 | const previewText = uncheckedPreview |
| 45 | .map((item) => item.text.trim()) |
| 46 | .filter((text) => text.length > 0) |
| 47 | .join(`, `) |
| 48 | const [showSavingBadge, setShowSavingBadge] = useState(false) |
| 49 | |
| 50 | useEffect(() => { |
| 51 | if (list.$synced !== false) { |
| 52 | setShowSavingBadge(false) |
| 53 | return |
| 54 | } |
| 55 | |
| 56 | setShowSavingBadge(false) |
| 57 | const timer = setTimeout(() => { |
| 58 | setShowSavingBadge(true) |
| 59 | }, 200) |
| 60 | return () => { |
| 61 | clearTimeout(timer) |
| 62 | } |
| 63 | }, [list.id, list.$synced]) |
| 64 | |
| 65 | return ( |
| 66 | <TouchableOpacity |
| 67 | style={styles.listCard} |
| 68 | onPress={onPress} |
| 69 | activeOpacity={0.7} |
| 70 | > |
| 71 | <View style={styles.listContent}> |
| 72 | <View style={styles.listHeaderRow}> |
| 73 | <Text style={styles.listName}>{list.name}</Text> |
| 74 | {showSavingBadge ? ( |
| 75 | <View style={styles.savingBadge}> |
nothing calls this directly
no test coverage detected