- Add React Query provider and client - Create reusable UI components (Loading, Error, Empty) - Implement custom hooks with fallback data - Integrate hooks into Resources and Community screens - Add pull-to-refresh support - Configure EAS Build profiles and environment variables
56 lines
1.4 KiB
TypeScript
56 lines
1.4 KiB
TypeScript
import { useQuery } from '@tanstack/react-query';
|
|
|
|
export interface Post {
|
|
id: string;
|
|
author: string;
|
|
content: string;
|
|
likes: number;
|
|
comments: number;
|
|
timestamp: string;
|
|
}
|
|
|
|
const FALLBACK_POSTS: Post[] = [
|
|
{
|
|
id: '1',
|
|
author: 'Sarah M.',
|
|
content: 'Just finished my first meditation session! Feeling so much calmer.',
|
|
likes: 12,
|
|
comments: 3,
|
|
timestamp: '2h ago',
|
|
},
|
|
{
|
|
id: '2',
|
|
author: 'James K.',
|
|
content: 'Anyone have recommendations for good books on cognitive behavioral therapy?',
|
|
likes: 8,
|
|
comments: 5,
|
|
timestamp: '5h ago',
|
|
},
|
|
{
|
|
id: '3',
|
|
author: 'Emily R.',
|
|
content: 'Remember to take it one day at a time. You got this!',
|
|
likes: 25,
|
|
comments: 2,
|
|
timestamp: '1d ago',
|
|
},
|
|
];
|
|
|
|
async function fetchCommunityPosts(): Promise<Post[]> {
|
|
// Simulate API call
|
|
// const response = await fetch(`${process.env.EXPO_PUBLIC_API_URL}/community/posts`);
|
|
// if (!response.ok) throw new Error('Failed to fetch posts');
|
|
// return response.json();
|
|
|
|
// Return fallback data for now
|
|
return new Promise((resolve) => {
|
|
setTimeout(() => resolve(FALLBACK_POSTS), 1000);
|
|
});
|
|
}
|
|
|
|
export function useCommunity() {
|
|
return useQuery({
|
|
queryKey: ['community-posts'],
|
|
queryFn: fetchCommunityPosts,
|
|
});
|
|
}
|