|
| 1 | +# FloatingContributors Component |
| 2 | + |
| 3 | +The `FloatingContributors` component is a dynamic React component that displays live GitHub activity and a list of contributors for the `recodehive/recode-website` repository. It fetches data from GitHub APIs, processes it, and renders it in an interactive and animated UI. |
| 4 | + |
| 5 | +--- |
| 6 | + |
| 7 | +## Features |
| 8 | + |
| 9 | +### 1. **Live GitHub Activity** |
| 10 | +- Displays recent events such as pushes, pull requests, comments, and more. |
| 11 | +- Cycles through activities every 4 seconds. |
| 12 | + |
| 13 | +### 2. **Contributors Grid** |
| 14 | +- Shows the top contributors with their avatars, GitHub profiles, and contribution counts. |
| 15 | +- Displays tooltips with additional contributor details. |
| 16 | + |
| 17 | +### 3. **Animations** |
| 18 | +- Smooth animations for floating effects, hover interactions, and transitions using `framer-motion`. |
| 19 | + |
| 20 | +### 4. **Fallback Mechanism** |
| 21 | +- Uses hardcoded fallback data when GitHub API calls fail. |
| 22 | + |
| 23 | +### 5. **Caching** |
| 24 | +- Caches API responses in `localStorage` for 2 minutes to reduce API calls. |
| 25 | + |
| 26 | +--- |
| 27 | + |
| 28 | +## API Integration |
| 29 | + |
| 30 | +### GitHub Events API |
| 31 | +- **Endpoint**: `https://api.github.com/repos/recodehive/recode-website/events?per_page=30` |
| 32 | +- **Purpose**: Fetches live activity data (e.g., pushes, pull requests, comments). |
| 33 | + |
| 34 | +### GitHub Contributors API |
| 35 | +- **Endpoint**: `https://api.github.com/repos/recodehive/recode-website/contributors?per_page=100` |
| 36 | +- **Purpose**: Fetches contributor data (e.g., avatars, contribution counts). |
| 37 | + |
| 38 | +--- |
| 39 | + |
| 40 | +## Key Functions |
| 41 | + |
| 42 | +### `formatTimeAgo` |
| 43 | +- Formats timestamps into relative time strings (e.g., "2 hours ago"). |
| 44 | + |
| 45 | +### `getGitHubEventUrl` |
| 46 | +- Generates URLs for GitHub events based on the action type. |
| 47 | + |
| 48 | +### `getActionIcon` and `getActionText` |
| 49 | +- Maps action types to icons and descriptive text. |
| 50 | + |
| 51 | +--- |
| 52 | + |
| 53 | +## Potential Enhancements |
| 54 | + |
| 55 | +### API Integration |
| 56 | +- Add support for more event types (e.g., `IssuesEvent` for issue creation). |
| 57 | +- Use authentication tokens to increase API rate limits. |
| 58 | + |
| 59 | +### UI/UX Features |
| 60 | +- Add user controls to pause or skip activities. |
| 61 | +- Allow users to view all contributors in a modal or separate page. |
| 62 | + |
| 63 | +### Styling |
| 64 | +- Convert CSS to a CSS-in-JS solution (e.g., styled-components). |
| 65 | +- Add theme support for light and dark modes. |
| 66 | + |
| 67 | +### Error Handling |
| 68 | +- Display error messages in the UI. |
| 69 | +- Retry failed API calls with exponential backoff. |
| 70 | + |
| 71 | +--- |
| 72 | + |
| 73 | +## Usage |
| 74 | + |
| 75 | +1. Import the component: |
| 76 | + ```tsx |
| 77 | + import FloatingContributors from './FloatingContributors'; |
| 78 | + ``` |
| 79 | + |
| 80 | +2. Use it in your application: |
| 81 | + ```tsx |
| 82 | + <FloatingContributors headerEmbedded={false} /> |
| 83 | + ``` |
| 84 | + |
| 85 | +--- |
| 86 | + |
| 87 | +## Dependencies |
| 88 | +- `react` |
| 89 | +- `framer-motion` |
| 90 | + |
| 91 | +--- |
| 92 | + |
| 93 | +## Notes |
| 94 | +- The component auto-refreshes data every 60 seconds. |
| 95 | +- It uses `localStorage` for caching API responses. |
| 96 | + |
| 97 | +--- |
0 commit comments