This project is a news aggregator website built with React.js. The application pulls articles from various sources and displays them in a clean, easy-to-read format. Users can search for articles by keyword, filter results by date, category, and source, and create a personalized news feed. The application is mobile-responsive and optimized for viewing on various devices.
- Article Search and Filtering Users can search for articles by entering keywords. Filtering options are available by date, category, and source.
- Personalized News Feed Users can customize their news feed by selecting preferred sources, categories, and authors.
- Mobile-Responsive Design The website is optimized for both desktop and mobile devices.
- Data Sources The application uses the following data sources:
- NewsAPI: Provides access to a wide range of news articles from various sources.
- The Guardian API: Fetches articles from The Guardian.
- New York Times API: Retrieves articles from The New York Times.
- React.js: A JavaScript library for building user interfaces.
- Redux Toolkit: For state management.
- Axios: For making HTTP requests to fetch data from APIs.
- React Bootstrap: For UI components and styling.
- Docker: For containerizing the application.
news-aggregator/
│
├── public/
│ ├── index.html
│ └── ...
│
├── src/
│ ├── components/
│ │ ├── Error
│ │ │ ├── Error.js
│ │ ├── Loading
│ │ │ ├── index.js
│ │ │ ├── Loading.js
│ │ ├── NavBar
│ │ │ ├── Loading.css
│ │ │ ├── Loading.js
│ │ ├── News
│ │ │ ├── index.js
│ │ │ ├── News.css
│ │ │ ├── News.js
│ │ ├── NewsCard
│ │ │ ├── Details
│ │ │ │ ├── Details.css
│ │ │ │ ├── Details.js
│ │ │ ├── NewsCard.css
│ │ │ ├── NewsCard.js
│ │ ├── NoDataFound
│ │ │ ├── NoDataFound.css
│ │ │ ├── NoDataFound.js
│ │ ├── NoRouteFound
│ │ │ ├── NoRouteFound.js
│ │ ├── ScrollToTop
│ │ │ ├── ScrollToTop.js
│ │ ├── index.js
│ │ └── ...
│ │
│ ├── config/
│ │ ├── api.js
│ │ ├── config.js
│ │ └── ...
│ │
│ ├── images/
│ │ ├── ArrowIcon.svg
│ │ └── ...
│ │
│ ├── pages/
│ │ ├── HomePage
│ │ │ ├── HomePage.js
│ │ ├── PersonalizedPage
│ │ │ ├── PersonalizedPage.js
│ │ └── ...
│ │
│ ├── router/
│ │ ├── appRouter.js
│ │ └── ...
│ │
│ ├── store/
│ │ ├── slices/
│ │ │ ├── articlesSlice.js
│ │ └── store.js
│ │
│ ├── App.css
│ ├── App.js
│ ├── index.css
│ ├── index.js
│ └── ...
│
├── .dockerignore
├── .env
├── .gitignore
├── docker-compose.yml
├── Dockerfile
├── package.json
└── ...
- Search and Filtering
- SearchBar Component: Allows users to search articles by entering keywords. This triggers a search request to the selected data sources.
- FilterOptions Component: Users can filter articles based on categories, date ranges, and sources. This component interacts with Redux to update the filter criteria.
- Personalized News Feed
- PersonalizedFeed Component: Displays a custom news feed based on user preferences such as preferred categories, sources, and authors. User preferences are stored in Redux and used to fetch and display relevant articles.
- Mobile-Responsive Design
- Responsive Layout: The UI components are designed using React Bootstrap, ensuring the layout adjusts for different screen sizes. Media queries are used for custom styling on mobile devices.
- API Integration
- api.js contains four different data sources newsAPI, guardianAPI, nytAPI, and gnewsAPI: These service file handle API requests to the respective data sources. It contains functions to fetch data, and convert all the data into normalize data which are used in Redux actions and components.
- State Management
- Redux Toolkit: Used to manage the state of the application, including articles fetched, user preferences, and filter criteria. Redux slices (articlesSlice.js) are created to handle specific aspects of the state.
The Dockerfile defines the steps to build the Docker image for the application.
FROM node:18 AS build
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
RUN npm run build
FROM nginx:alpine
COPY --from=build /app/build /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
If using Docker Compose, the docker-compose.yml file simplifies running the application.
version: '3.8'
services:
web:
build: .
ports:
- "80:80"
-
Build the Docker Image: Open a terminal in the root directory of your project and run:
docker build -t news-aggregator .
-
Run the Docker Container: To start a container from your image, run:
docker run -p 80:80 news-aggregator
If using Docker Compose, you can build and run the container with:
docker-compose up --build
-
Clone the Repository:
git clone https://github.com/yourusername/news-aggregator.git cd news-aggregator
-
Install Docker:
Ensure Docker is installed on your machine. You can download it from Docker's official website.
-
Build the Docker Image:
docker build -t news-aggregator .
-
Run the Docker Container:
docker run -p 80:80 news-aggregator
Alternatively, if you are using Docker Compose, run:
docker-compose up --build
-
Access the Application:
Open your web browser and go to http://localhost to see the application running.
-
Stopping the Container:
If you started the container with Docker Compose, stop it using:
docker-compose down
If you started the container directly, find the container ID with:
docker ps
Then stop it with:
docker stop <container_id>