Skip to content

This repository is the final project from the FGA x Hacktiv8 Bootcamp Web Development + React Native. It is a news application that provides the latest updates using the New York Times API.

Notifications You must be signed in to change notification settings

rifqi142/news-app

Repository files navigation

πŸ“œ Final Project - News App πŸ“œ

A News application that provides the latest updates using the New York Times API. News App is a web application that displays the latest news from various categories by leveraging the New York Times API. This app is built using modern technologies such as React, Redux, and Tailwind CSS. With the News App, users can explore different news categories, search for articles, bookmark their favorite news, and enjoy a user-friendly interface with both dark and light modes.

πŸ§‘πŸ»β€πŸ’» Author

🌐 Preview Website

Preview

πŸ“‹ Table of Contents

⚑️ Features

  • Dark Mode / Light Mode: Users can switch between dark and light themes.
  • Pagination: Navigate through multiple pages of news articles.
  • Responsive Design: The app is fully responsive for mobile, tablet, and desktop screens.
  • Skeleton Design: Display skeleton loaders while the content is being fetched.
  • Bookmark / Un-bookmark News: Users can save or remove news articles from their bookmarks.
  • Scroll Up to Top: Button to scroll up to the top of the page for better UX.

βš™οΈTechnologies Used

  • React + Vite + TypeScript: Frontend framework for building interactive UIs.
  • Tailwind CSS: Utility-first CSS framework for styling.
  • React Router Dom: Library for managing routing in the React app.
  • React Redux: State management library.
  • Redux Toolkit: A toolset for efficient Redux development.
  • Shadcn/UI: Component library for building beautiful UIs.
  • Axios: Promise-based HTTP client for making API requests.
  • React-Toastify: Library for showing notifications in the app.

πŸ“’ Icon Libraries

  • @fortawesome: FontAwesome icons for UI elements.
  • @phosphor-icons/react: Phosphor icons for better design options.

πŸ“ API Integration

This app uses the New York Times API for fetching the latest news articles. You can register and get your API key here.

πŸ“Œ Example .env

VITE_NEWS_API_KEY="your api key"
VITE_NEWS_BASE_URL=https://api.nytimes.com/svc/news/v3/content/all/all.json
VITE_NEWS_SEARCH_URL=https://api.nytimes.com/svc/search/v2/articlesearch.json
  • VITE_NEWS_API_KEY: The API key obtained from the NY Times Developer Portal.
  • VITE_NEWS_BASE_URL: The base URL endpoint to get news from various categories.
  • VITE_NEWS_SEARCH_URL: The URL endpoint to perform article searches based on keywords.

Example API Endpoints:

  • Fetching all news articles:
    export const fetchAllNews = createAsyncThunk(
      "news/fetchAllNews",
      async ({ offset = 0 }: { offset?: number }, { rejectWithValue }) => {
        try {
          const response = await axios.get(
            `${import.meta.env.VITE_NEWS_BASE_URL}?api-key=${
              import.meta.env.VITE_NEWS_API_KEY
            }&offset=${offset}&limit=20`
          );
          return response;
        } catch (error: any) {
          return rejectWithValue(error.message);
        }
      }
    );
  • Fetching News API
export const fetchNewsIndonesia = createAsyncThunk(
  "news/fetchNewsIndonesia",
  async (page: number = 1, { rejectWithValue }) => {
    try {
      const response = await axios.get(
        `${
          import.meta.env.VITE_NEWS_SEARCH_URL
        }?q=indonesia&page=${page}&api-key=${import.meta.env.VITE_NEWS_API_KEY}`
      );
      return response;
    } catch (error: any) {
      return rejectWithValue(error.message);
    }
  }
);
  • Fetching News Programming
export const fetchNewsProgramming = createAsyncThunk(
  "news/fetchNewsProgramming",
  async (page: number = 1, { rejectWithValue }) => {
    const dateNow = new Date();
    const dateLastMonth = subMonths(dateNow, 1);

    const dateNowFormat = format(dateNow, "yyyyMMdd");
    const dateLastMonthFormat = format(dateLastMonth, "yyyyMMdd");

    try {
      const apiUrl = `${
        import.meta.env.VITE_NEWS_SEARCH_URL
      }?q=programming+OR+coding&page=${page}&begin_date=${dateLastMonthFormat}&end_date=${dateNowFormat}&api-key=${
        import.meta.env.VITE_NEWS_API_KEY
      }`;

      const response = await axios.get(apiUrl);
      return response;
    } catch (error: any) {
      return rejectWithValue(error.message);
    }
  }
);
  • Fetching News by Keyword
export const fetchNewsSearch = createAsyncThunk(
  "news/fetchNewsSearch",
  async (
    { keyword, page = 1 }: { keyword: string; page: number },
    { rejectWithValue }
  ) => {
    try {
      const response = await axios.get(
        `${
          import.meta.env.VITE_NEWS_SEARCH_URL
        }?q=${keyword}&page=${page}&sort=newest&api-key=${
          import.meta.env.VITE_NEWS_API_KEY
        }`
      );
      return response;
    } catch (error: any) {
      return rejectWithValue(error.message);
    }
  }
);

πŸ“‘ Project Structure

/src
 β”œβ”€β”€ /assets          # Static assets like images, fonts, etc.
 β”œβ”€β”€ /components      # Reusable components across the app
 β”œβ”€β”€ /constants       # Application-wide constants
 β”œβ”€β”€ /features        # Redux slices and logic
 β”œβ”€β”€ /lib             # Third-party integrations or utilities
 β”œβ”€β”€ /pages           # Application pages (Home, Indonesia, Programming, etc.)
 β”œβ”€β”€ /routes          # React Router configuration
 β”œβ”€β”€ /store           # Redux store and slices
 β”œβ”€β”€ /types           # TypeScript types
 β”œβ”€β”€ /utils           # Utility functions and helpers
 β”œβ”€β”€ App.tsx          # Main app component
 β”œβ”€β”€ index.css        # Global CSS
 └── main.tsx         # Main entry point for the React app

πŸ›  Installation

1. Clone the repository:

git clone https://github.com/rifqi142/news-app

2. Navigate to the project directory:

cd news-app

3. Install Dependencies

npm install

4. Set up Environment Variables

Create a .env file in the root directory and add the required environment variables (refer to the Environment Variables section above).

5. Run the application:

npm run dev

πŸ”— Live Preview

Check out my news-app website at https://news-app-gules-ten.vercel.app/

About

This repository is the final project from the FGA x Hacktiv8 Bootcamp Web Development + React Native. It is a news application that provides the latest updates using the New York Times API.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published