fix: change type parameter from array to single value for API compatibility
SDK API only accepts single MessageType value, not array. Updated to use client-side filtering for Tab-based message type filtering (all/notice/other) instead of server-side filtering. Changes: - hooks/use-messages.ts: Changed type parameter from array to single value - app/(tabs)/message.tsx: Replaced getMessageTypeByTab with filterMessagesByTab for client-side filtering - Removed useEffect dependency on activeTab to prevent unnecessary refetches Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -20,10 +20,12 @@ import LoadingState from '@/components/LoadingState'
|
||||
import ErrorState from '@/components/ErrorState'
|
||||
import PaginationLoader from '@/components/PaginationLoader'
|
||||
|
||||
const getMessageTypeByTab = (tab: 'all' | 'notice' | 'other') => {
|
||||
if (tab === 'all') return undefined
|
||||
if (tab === 'notice') return ['SYSTEM', 'ACTIVITY']
|
||||
return ['BILLING', 'MARKETING']
|
||||
const filterMessagesByTab = (messages: Message[], tab: 'all' | 'notice' | 'other') => {
|
||||
if (tab === 'all') return messages
|
||||
if (tab === 'notice') {
|
||||
return messages.filter(m => m.type === 'SYSTEM' || m.type === 'ACTIVITY')
|
||||
}
|
||||
return messages.filter(m => m.type === 'BILLING' || m.type === 'MARKETING')
|
||||
}
|
||||
|
||||
const formatTime = (date: Date) => {
|
||||
@@ -42,14 +44,15 @@ export default function MessageScreen() {
|
||||
const [activeTab, setActiveTab] = useState<'all' | 'notice' | 'other'>('all')
|
||||
const { markRead } = useMessageActions()
|
||||
|
||||
const messageType = getMessageTypeByTab(activeTab)
|
||||
const { messages, loading, loadingMore, error, refetch, loadMore, hasMore, execute } = useMessages({
|
||||
const { messages: allMessages, loading, loadingMore, error, refetch, loadMore, hasMore, execute } = useMessages({
|
||||
limit: 20,
|
||||
})
|
||||
|
||||
const messages = filterMessagesByTab(allMessages, activeTab)
|
||||
|
||||
useEffect(() => {
|
||||
execute({ type: messageType as any })
|
||||
}, [activeTab])
|
||||
execute()
|
||||
}, [])
|
||||
|
||||
const handleScroll = (event: NativeSyntheticEvent<NativeScrollEvent>) => {
|
||||
const { layoutMeasurement, contentOffset, contentSize } = event.nativeEvent
|
||||
|
||||
Reference in New Issue
Block a user