Skip to content

rajat-mehra05/hackerpedia

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

51 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

HackerPedia

Screenshot 2025-11-15 at 12 20 16โ€ฏPM

A modern, feature-rich Hacker News interface built with React while learning frontend development. This project fetches real-time data from the Hacker News API without using any state management library like Redux.


๐Ÿ› ๏ธ Tech Stack

  • React - UI framework
  • React Hooks - State and lifecycle management
  • Styled Components - CSS-in-JS with theming
  • Material-UI (MUI) - Layout components and design system
  • React Router DOM - Client-side routing
  • Axios - HTTP client for API calls
  • React Spinners - Loading animations
  • PWA - Progressive Web App

โœจ Features

Core Functionality

  • Real-time Story Feed - Fetches and displays top stories from Hacker News
  • Infinite Scroll - Seamlessly loads more stories as you scroll down
  • Story Metadata - View points, author, post time, and comment count for each story
  • External Links - Direct links to original articles with domain preview

๐ŸŽจ User Interface

  • Dark Mode - Toggle between light and dark themes with persistent localStorage
  • Responsive Design - Fully responsive layout that works on desktop, tablet, and mobile
  • Loading States - Beautiful loading animations using react-spinners
  • Clean UI - Modern, minimalist design inspired by Hacker News

๐Ÿ” Search & Discovery

  • Live Search - Real-time search with debounced input for better performance
  • Smart Filtering - Search across story titles, authors, and domains
  • Search Results Counter - Shows the number of matching stories
  • Clear Search - Quick clear button and ESC key support

๐Ÿ’ฌ Comment System

  • Nested Comments - Fully recursive comment threads with proper indentation
  • Comment Collapse/Expand - Collapse comment threads to focus on what matters
  • HN-Style UI - Authentic Hacker News comment styling
  • Deep Nesting Support - Handles deeply nested comments with smart indentation caps
  • HTML Sanitization - Safe rendering of comment content
  • No Authentication Required - View all comments without logging in

๐ŸŽฏ Technical Features

  • React Hooks - Modern functional components with useState, useEffect, useCallback, useRef
  • Styled Components - Theme-aware, scoped CSS-in-JS styling
  • React Router - Client-side routing for navigation
  • Axios - Efficient API calls with error handling
  • Context API - Global theme management
  • PWA Support - Progressive Web App capabilities
  • Smart Caching - localStorage-based caching with 5-minute TTL and LRU eviction

๐Ÿ“ฆ Setup

Use the node package manager npm to set up the development environment.

Prerequisites

  • Node.js (v14 or higher)
  • npm or yarn

Installation

  1. Clone the repository

    git clone https://github.com/yourusername/hackerpedia.git
    cd hackerpedia
  2. Install dependencies

    npm install
  3. Start the development server

    npm run start
  4. Build for production

    npm run build

The app will be available at http://localhost:3000


๐ŸŽฎ Usage

  • Browse Stories - Scroll through the main feed of top stories
  • Search - Use the search bar to filter stories by title, author, or domain
  • Toggle Theme - Click the moon/sun icon in the navigation bar
  • View Comments - Click on the comment count to view the full discussion
  • Collapse Comments - Click [โˆ’] to collapse a comment thread
  • Navigate - Use the back button or browser history to return to the main feed

๐Ÿ“ Project Structure

hackerpedia/
โ”œโ”€โ”€ public/
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ components/
โ”‚   โ”‚   โ”œโ”€โ”€ CommentItem.js      # Individual comment component
โ”‚   โ”‚   โ”œโ”€โ”€ CommentList.js      # Comment list wrapper
โ”‚   โ”‚   โ”œโ”€โ”€ Search.js           # Search input component
โ”‚   โ”‚   โ”œโ”€โ”€ Story.js            # Story card component
โ”‚   โ”‚   โ”œโ”€โ”€ StoryContainer.js   # Main story feed
โ”‚   โ”‚   โ””โ”€โ”€ mapTime.js          # Time formatting utility
โ”‚   โ”œโ”€โ”€ context/
โ”‚   โ”‚   โ””โ”€โ”€ ThemeContext.js     # Theme provider
โ”‚   โ”œโ”€โ”€ infiniteScroll/
โ”‚   โ”‚   โ”œโ”€โ”€ constants.js        # Infinite scroll constants
โ”‚   โ”‚   โ””โ”€โ”€ infiniteScroll.js   # Infinite scroll hook
โ”‚   โ”œโ”€โ”€ NavigationBar/
โ”‚   โ”‚   โ”œโ”€โ”€ NavNews.js          # Navigation component
โ”‚   โ”‚   โ””โ”€โ”€ NavNews.css         # Navigation styles
โ”‚   โ”œโ”€โ”€ pages/
โ”‚   โ”‚   โ””โ”€โ”€ CommentPage.js      # Comment view page
โ”‚   โ”œโ”€โ”€ services/
โ”‚   โ”‚   โ”œโ”€โ”€ hnAPI.js            # Hacker News API calls
โ”‚   โ”‚   โ””โ”€โ”€ cacheService.js     # Caching layer for API calls
โ”‚   โ”œโ”€โ”€ styles/
โ”‚   โ”‚   โ”œโ”€โ”€ CommentStyles.js    # Comment styled components
โ”‚   โ”‚   โ”œโ”€โ”€ StoryStyles.js      # Story styled components
โ”‚   โ”‚   โ”œโ”€โ”€ StoryContainer.css  # Story container styles
โ”‚   โ”‚   โ””โ”€โ”€ themes.js           # Theme definitions
โ”‚   โ”œโ”€โ”€ utils/
โ”‚   โ”‚   โ”œโ”€โ”€ cacheUtils.js       # Cache management utilities
โ”‚   โ”‚   โ”œโ”€โ”€ commentUtils.js     # Comment helper functions
โ”‚   โ”‚   โ”œโ”€โ”€ searchUtils.js      # Search helper functions
โ”‚   โ”‚   โ””โ”€โ”€ themeUtils.js       # Theme helper functions
โ”‚   โ”œโ”€โ”€ App.js                  # Main app component
โ”‚   โ”œโ”€โ”€ index.js                # App entry point
โ”‚   โ””โ”€โ”€ index.css               # Global styles
โ”œโ”€โ”€ package.json
โ””โ”€โ”€ README.md

โšก Caching Strategy

The app implements an intelligent caching system to improve performance and reduce API calls:

Cache Configuration

  • Cache Duration: 5 minutes TTL (Time To Live)
  • Storage: localStorage for persistence across page reloads
  • Capacity:
    • 100 stories maximum
    • 40 comment threads maximum

Benefits

  • Faster Navigation: Back button and revisits load instantly from cache
  • Reduced API Calls: Minimizes requests to Hacker News API
  • Better UX: No loading spinners for cached content
  • Persistence: Cache survives page reloads (within TTL window)
  • No External Dependencies: Pure localStorage implementation

Implementation Details

The caching system consists of two layers:

  1. cacheUtils.js: Low-level cache management

    • localStorage read/write operations
    • TTL validation
    • LRU eviction algorithm
    • Expired entry cleanup
  2. cacheService.js: High-level API wrapper

    • Transparent caching layer over HN API calls
    • Cache-first strategy with API fallback
    • Automatic cache updates after API calls

๐Ÿš€ Future Enhancements

  • User authentication for commenting and voting
  • Vote functionality (upvote stories and comments)
  • Filter by story type (Ask HN, Show HN, Jobs)
  • Share functionality
  • Bookmarking/favorites
  • Custom story sorting (newest, popular, trending)
  • User profile pages
  • Comment replies
  • Pagination controls

๐Ÿ› Known Issues

All major issues have been resolved! If you find a bug, please open an issue.


๐Ÿค Contributing

Pull requests are welcome! For major changes, please open an issue first to discuss what you would like to change.

Steps to Contribute

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

๐Ÿ“„ License

MIT


๐Ÿ™ Acknowledgments


Releases

No releases published

Packages

 
 
 

Contributors