π Community Hub API Integration & Real-time Features
π Problem
Community Hub currently uses mock data. Need to integrate real API endpoints and add WebSocket real-time features.
β
What's Already Done
- β
Complete UI components and navigation
- β
Backend API routes in
communityRoutes.ts
- β
Database models (Discussion, Reply, Vote)
- β
JWT authentication system
- β
TypeScript types and interfaces
π― What Needs To Be Done
Phase 1: Replace Mock Data with API
Current Problem - CommunityHub.tsx uses fake data:
// β This needs to be replaced
useEffect(() => {
setDiscussions(mockDiscussions);
}, []);
Solution - Connect to real API:
// β
Replace with this
const fetchDiscussions = async () => {
const response = await api.get('/community/discussions');
setDiscussions(response.data.data.discussions);
};
Available API Endpoints:
GET /api/community/discussions # Get all discussions
POST /api/community/discussions # Create discussion (auth required)
POST /api/community/vote # Vote on discussion (auth required)
Phase 2: Add Real-time Features
Add WebSocket server for:
- Live vote count updates
- New reply notifications
- Online user presence
- Real-time discussion updates
οΏ½ Implementation Checklist
π΄ High Priority (Phase 1)
π‘ Medium Priority (Phase 2)
π’ Low Priority (Phase 3)
οΏ½ Key Files to Modify
Frontend:
src/pages/CommunityHub.tsx - Remove mock data, add API calls
src/services/api.ts - Add community API methods
src/components/Community/DiscussionCard.tsx - Connect voting
Backend:
src/index.ts - Add WebSocket server setup
src/websocket/communitySocket.ts - WebSocket event handlers (new file)
οΏ½ Getting Started
- Start backend server on
localhost:4000
- Test API endpoints with Postman/curl
- Replace mock imports in CommunityHub component
- Add error states and loading indicators
- Test voting functionality with authenticated users
β
Definition of Done
π Community Hub API Integration & Real-time Features
π Problem
Community Hub currently uses mock data. Need to integrate real API endpoints and add WebSocket real-time features.
β What's Already Done
communityRoutes.tsπ― What Needs To Be Done
Phase 1: Replace Mock Data with API
Current Problem -
CommunityHub.tsxuses fake data:Solution - Connect to real API:
Available API Endpoints:
Phase 2: Add Real-time Features
Add WebSocket server for:
οΏ½ Implementation Checklist
π΄ High Priority (Phase 1)
CommunityHub.tsxservices/api.tsπ‘ Medium Priority (Phase 2)
π’ Low Priority (Phase 3)
οΏ½ Key Files to Modify
Frontend:
src/pages/CommunityHub.tsx- Remove mock data, add API callssrc/services/api.ts- Add community API methodssrc/components/Community/DiscussionCard.tsx- Connect votingBackend:
src/index.ts- Add WebSocket server setupsrc/websocket/communitySocket.ts- WebSocket event handlers (new file)οΏ½ Getting Started
localhost:4000β Definition of Done