Skip to content

sixhops/pokefront

Repository files navigation

PokeFront

Description:

A front end for the educational Pokemon API. Uses Next.js, react, typescript, and cloudscape.

AI Usage Notes:

This app was generated almost entirely by AI (cursor) as a way to practice with gen AI tools and learn how to use Next.js to spin up a react app. All of my prompts are recorded here with summaries of what the tools did in response. Each change by the AI will be to add support for one bit of functionality at a time. The AI will document all changes and the reason for each such that a person could use it to spin up another Next.js app by following the steps.

The AI should use the following format as an example for its entries:

Step Description (e.g. "Add index page to project")

Prompt:

List the exact prompt as provided

Commands run:

Explain what each command was used for.

List all commands used here
One command per line

Files Modified:

  1. List each file modified and the explanation for why. Use the format in #2.
  2. /path/from/root/filename.ts - Explanation for what was done to the file and why

Summary:

Here the AI will summarize what it did to complete the work for the prompt.


The is the end of the example.

Development Journal

Initialize Next.js project with React and TypeScript

Prompt:

For each prompt and response, create an entry in the Development Journal using the example format in the README. In this directory create a Next.js app that will use react and typescript. There is no need to list the files changed or installed during this particular step, but do list the commands used.

Commands run:

The npx create-next-app@latest command was used to initialize a new Next.js application in the current directory. The command was run with several flags:

  • --typescript to enable TypeScript support
  • --react to ensure React is included
  • --tailwind to include Tailwind CSS for styling
  • --eslint to set up ESLint for code linting
  • --app to use the App Router (Next.js 13+ routing system)
  • --src-dir to organize source files in a src directory
  • --import-alias "@/*" to configure path aliases for cleaner imports
  • --yes to skip interactive prompts and use default settings
npx create-next-app@latest . --typescript --react --tailwind --eslint --app --src-dir --import-alias "@/*" --yes

Summary:

Initialized a new Next.js application with React and TypeScript support in the pokefront directory. The setup includes TypeScript configuration, Tailwind CSS for styling, ESLint for code quality, and uses the modern App Router architecture. The project structure was created with source files organized in a src directory, and import aliases were configured for cleaner module imports. All necessary dependencies were automatically installed, including Next.js, React, React DOM, and their TypeScript type definitions.


Add axios node module for AJAX calls

Prompt:

Add the axios node module for AJAX calls.

Commands run:

The npm install axios command was used to install axios as a runtime dependency. Axios is a popular HTTP client library for making AJAX requests in JavaScript/TypeScript applications.

npm install axios

Files Modified:

  1. package.json - Added axios to the dependencies section
  2. package-lock.json - Updated with axios and its dependency tree information

Summary:

Installed axios as a dependency to enable AJAX/HTTP requests in the application. Axios provides a promise-based API for making HTTP requests and will be used to interact with the Pokemon API. The package was added to the project dependencies and is now available for import and use throughout the application.


Create index page at /pokemon/ route

Prompt:

Create an index page that can be accessed at a /pokemon/ route from the document root.

Commands run:

No commands were run for this step. The route was created using Next.js App Router file-based routing by creating the appropriate directory structure.

(No commands required - file-based routing)

Files Modified:

  1. src/app/pokemon/page.tsx - Created a new page component for the /pokemon/ route. This file defines a React component that renders the Pokemon index page with a heading and welcome message, styled consistently with the existing Next.js template using Tailwind CSS classes.

Summary:

Created a new index page accessible at the /pokemon/ route by adding a pokemon directory inside src/app/ and creating a page.tsx file within it. This follows Next.js App Router conventions where the file system structure determines the routing. The page component includes a simple layout with a heading and welcome message, styled to match the existing design patterns in the application using Tailwind CSS for dark mode support and responsive design.


Add axios GET call to Pokemon API and store response in state

Prompt:

`Add an axios GET call to the following URL:

https://pokeapi.co/api/v2/pokemon/

And add the response to app state for the pokemon index page. The response has the following schema:

{ count: number; next: string; previous: string; results: [ { name: string; url: string; }, ]; }`

Commands run:

No commands were run for this step. The implementation only required code changes to the existing component.

(No commands required)

Files Modified:

  1. src/app/pokemon/page.tsx - Updated the Pokemon index page component to fetch data from the Pokemon API using axios. The component was converted to a client component by adding the 'use client' directive, which is required for using React hooks like useState and useEffect in Next.js App Router. Added TypeScript interfaces for the API response schema (PokemonApiResponse and PokemonResult). Implemented state management using useState to store the API response, loading state, and error state. Added a useEffect hook to make the axios GET request when the component mounts. The component now displays loading state, error handling, and shows the total count and number of results loaded from the API response.

Summary:

Enhanced the Pokemon index page to fetch data from the Pokemon API using axios. Converted the component to a client component to enable React hooks, added TypeScript interfaces matching the provided API response schema, and implemented state management to store the API response. The component now makes an asynchronous GET request to https://pokeapi.co/api/v2/pokemon/ when it mounts, handles loading and error states, and displays the total Pokemon count and number of results loaded from the response.


Display Pokemon results array with borders

Prompt:

Add a section to the pokemon index page to display the results of the ajax call. Each result in the "results" array should be mapped to a div displaying the "name" and "url" values for that result. Add a border around each result.

Commands run:

No commands were run for this step. The implementation only required code changes to the existing component.

(No commands required)

Files Modified:

  1. src/app/pokemon/page.tsx - Added a results display section that maps over the results array from the API response. Each result is rendered in a bordered div that displays both the name and url properties. Used Tailwind CSS classes to add borders (border border-zinc-300 dark:border-zinc-700), rounded corners, padding, and background colors that support dark mode. The results are displayed in a flex column layout with spacing between items. Each result div shows the name with a bold font and the URL below it with a smaller font size and word-break styling to handle long URLs.

Summary:

Added a visual display section to the Pokemon index page that maps over the results array from the API response. Each Pokemon result is rendered in its own bordered div showing both the name and URL. The styling uses Tailwind CSS with borders, rounded corners, padding, and dark mode support. The results are displayed in a vertical list with proper spacing, making it easy to see all the Pokemon data returned from the API call.


Add Pokemon detail page with dynamic routing

Prompt:

`Make the displayed name in each result into a link to a new detail page in the same directory that displays the details of of that result. The details page will need to know the "name" value of the clicked result so that it can call the API for details. The ajax call from the details page will be to this URL:

https://pokeapi.co/api/v2/pokemon/NAME

where "NAME" is replaced with the value from the result's name field. The pokemon details page should be accessible both via the link and via a direct URL to "/pokemon/NAME" where "NAME" is the name to be passed into the API call.`

Commands run:

No commands were run for this step. The implementation only required code changes and creating a new file.

(No commands required)

Files Modified:

  1. src/app/pokemon/page.tsx - Updated the Pokemon index page to make each Pokemon name a clickable link. Imported Next.js Link component and wrapped each result's name in a Link component that navigates to /pokemon/${result.name}. Added hover styling with underline and blue color to indicate the link is clickable.

  2. src/app/pokemon/[name]/page.tsx - Created a new dynamic route page for Pokemon details. This file uses Next.js App Router dynamic routing with the [name] folder structure to create a route that accepts a Pokemon name as a URL parameter. The component uses useParams() hook to extract the name from the URL, then makes an axios GET request to https://pokeapi.co/api/v2/pokemon/${name} to fetch the Pokemon details. The page displays loading and error states, and shows the full Pokemon data as formatted JSON in a bordered container. The page is accessible both via links from the index page and via direct URL navigation to /pokemon/NAME.

Summary:

Implemented dynamic routing for Pokemon detail pages by creating a [name] dynamic route segment in the pokemon directory. Updated the index page to make Pokemon names clickable links that navigate to the detail page. The detail page extracts the Pokemon name from the URL parameter and uses it to fetch detailed information from the Pokemon API. The page handles loading and error states and displays the full API response as formatted JSON. Users can access detail pages both by clicking names on the index page and by directly navigating to /pokemon/NAME URLs.


Update Pokemon details response schema

Prompt:

`Update the response schema for the details fetch to the following:

@page.tsx (66-81)`

Commands run:

No commands were run for this step. The implementation only required code changes to add TypeScript type definitions.

(No commands required)

Files Modified:

  1. src/app/pokemon/[name]/page.tsx - Added a TypeScript interface PokemonDetails to define the schema for the Pokemon details API response. The interface includes properties for name, height, weight, base_experience, sprites (with front_default, back_default, front_shiny, back_shiny), and cries (with latest and legacy). Updated the pokemonData state to use PokemonDetails | null instead of any, and added the generic type parameter to the axios.get call to ensure type safety for the API response.

Summary:

Added TypeScript type definitions for the Pokemon details API response by creating a PokemonDetails interface that matches the specified schema. This provides type safety for the Pokemon details data, ensuring that the component correctly handles the structure of the API response with properties for name, height, weight, base experience, sprites, and cries. The axios call and state management now use these types instead of the generic any type.


Display Pokemon details with images, audio, and navigation

Prompt:

Add elements on the details page to display the response values from the details fetch. Use the URLs for the sprites to display each as an image labeled with the property name. Create buttons that will play the OGG files linked in the "cries" property. Add a link at the top that links back to the pokemon index page.

Commands run:

No commands were run for this step. The implementation only required code changes.

(No commands required)

Files Modified:

  1. src/app/pokemon/[name]/page.tsx - Completely redesigned the Pokemon details page to display structured information instead of raw JSON. Added imports for Next.js Link and Image components. Created a "Back to Pokemon Index" link at the top of the page. Replaced the JSON display with organized sections: Basic Information (name, height, weight, base_experience), Sprites (displaying all four sprite images in a 2x2 grid with labels), and Cries (buttons to play the latest and legacy cry audio files). Each sprite is displayed using Next.js Image component with proper sizing, borders, and labels showing the property name. Added a playAudio function that creates an Audio object and plays the OGG files when the cry buttons are clicked. The page now provides a user-friendly interface for viewing Pokemon details.

  2. next.config.ts - Updated the Next.js configuration to allow loading images from external domains. Added remotePatterns configuration to permit images from raw.githubusercontent.com, which is where Pokemon API sprite images are hosted. This is required for Next.js Image component to load external images.

Summary:

Transformed the Pokemon details page from a raw JSON display into a structured, user-friendly interface. Added a navigation link back to the index page, organized the data into clear sections (Basic Information, Sprites, Cries), displayed all four sprite images with labels in a grid layout, and created interactive buttons to play the Pokemon's cry audio files. Updated Next.js configuration to allow external image loading from the Pokemon API's image hosting domain. The page now provides a complete visual and interactive experience for viewing Pokemon details.


Add error handling for Pokemon not found (4xx errors)

Prompt:

Resume adding journal entries from this prompt on. If the details fetch returns a 4xx code or an error similar to "resource not found" then have the details page show an error saying that the pokemon could not be found. Provide a link to return to the pokemon index page.

Commands run:

No commands were run for this step. The implementation only required code changes.

(No commands required)

Files Modified:

  1. src/app/pokemon/[name]/page.tsx - Enhanced error handling to specifically detect and handle 4xx status codes and "resource not found" errors. Added a new notFound state variable to track when a Pokemon cannot be found. Updated the catch block to check if the error is an Axios error, then check for 4xx status codes (400-499) or error messages containing "not found" or "resource not found". When a not found error is detected, the component displays a user-friendly error message in a styled bordered container with red theming. The error message includes the Pokemon name that was searched for and a prominent "Return to Pokemon Index" button that links back to the Pokemon list page. The error display is visually distinct with red borders and background colors that support dark mode.

Summary:

Added comprehensive error handling for cases where a Pokemon cannot be found. The details page now detects 4xx HTTP status codes and "resource not found" error messages, displaying a clear, user-friendly error message instead of a generic error. The error display includes the searched Pokemon name and provides a convenient link back to the Pokemon index page, improving the user experience when invalid Pokemon names are accessed via direct URL or other means.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors