Welcome to the Hacker News Search App! This project is a simple and interactive way to explore the content on Hacker News using the Hacker News Algolia API. π
This app allows users to search for news articles and stories from the Hacker News community. Users can input any keyword, navigate through multiple pages of results, and view detailed information about each story, such as the number of comments, author, and score.
- π Search Functionality: Enter any search term to retrieve relevant stories and articles.
- π Pagination: Navigate through multiple pages of results with "Next" and "Previous" buttons.
- π Story Details: View the story's title, author, points, comments, and a snippet of the text (if available).
- π¨ Skeleton Loading State: Displays skeleton cards while fetching data to improve UX.
- π± Responsive Design: The app is fully responsive and works across desktop and mobile devices.
The project is built with React using a component-based architecture. It leverages various UI components such as Card
, Button
, and Input
from a custom library. Below is a high-level structure of the app:
.
βββ components
β βββ ui
β β βββ button.tsx
β β βββ input.tsx
β β βββ card.tsx
β β βββ skeleton.tsx
βββ pages
β βββ hacker-search.tsx
βββ README.md
To run this app locally, make sure you have the following installed:
- Node.js: v14 or higher
- npm: v6 or higher
-
Clone the repository:
git clone https://github.com/yourusername/hacker-news-search.git
-
Navigate to the project directory:
cd hacker-news-search
-
Install dependencies:
npm install
Start the app in development mode:
npm run dev
This command will start a local development server. Open your browser and go to http://localhost:3000 to see the app in action! π
- Input Component: A text input field to enter the search query.
- Button Component: Used for initiating searches and navigating between pages.
- Card Component: Displays each story's details such as the title, author, points, and comments.
- Skeleton Component: Used to show loading placeholders when fetching data.
The app uses the Hacker News Algolia API to retrieve search results based on user queries. The relevant API endpoint is:
https://hn.algolia.com/api/v1/search?query=YOUR_QUERY&page=PAGE_NUMBER&hitsPerPage=20
For a search on "React", the request URL would look like:
https://hn.algolia.com/api/v1/search?query=React&page=0&hitsPerPage=20
query
: Stores the current search term.page
: Tracks the current page number for pagination.results
: Holds the array of search results from the API.totalPages
: Keeps the total number of pages available.isLoading
: Manages the loading state for the app.
SkeletonCard
Component: Displays skeleton cards during data fetching.HackerSearch
Component: The main component that brings all functionalities together.
If you find any bugs or have suggestions for improvements, feel free to open an issue or submit a pull request. Let's make this app better together! πͺ
- Fork the repository.
- Create a new branch (
git checkout -b feature-branch-name
). - Make your changes.
- Commit your changes (
git commit -am 'Add some feature'
). - Push to the branch (
git push origin feature-branch-name
). - Open a Pull Request.
- React for UI components.
- Next.js for server-side rendering.
- TypeScript for type safety.
- Hacker News Algolia API for fetching news stories.
Your Name
GitHub Profile
This project is licensed under the MIT License - see the LICENSE file for details.
Enjoy using the Hacker News Search App? Donβt forget to β the repo if you find it useful! π