Skip to content

πŸš€ Community Hub API Integration & Real-time FeaturesΒ #108

Description

@hillmatthew2000

πŸš€ 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)

  • Replace mock data in CommunityHub.tsx
  • Add API calls to services/api.ts
  • Connect voting buttons to backend
  • Add error handling for API failures
  • Test with real backend server

🟑 Medium Priority (Phase 2)

  • Set up WebSocket server with Socket.IO
  • Add real-time vote updates
  • Implement new reply notifications
  • Add user online presence indicators

🟒 Low Priority (Phase 3)

  • Discussion detail page with replies
  • Advanced search and filtering
  • User profile integration
  • Discussion moderation tools

οΏ½ 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

  1. Start backend server on localhost:4000
  2. Test API endpoints with Postman/curl
  3. Replace mock imports in CommunityHub component
  4. Add error states and loading indicators
  5. Test voting functionality with authenticated users

βœ… Definition of Done

  • No more mock data - all API connected
  • Voting works with real backend
  • Error handling for network issues
  • Real-time updates working via WebSocket
  • All CRUD operations tested and functional

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions