PioneerSquareLabs / otto-playground

A playground where Otto can run free while hopefully not accidentally reformatting your hard drive
https://otto-playground.vercel.app
13 stars 0 forks source link

Create src/pages/create/index.tsx #769

Closed otto-jacob closed 1 year ago

otto-jacob commented 1 year ago

Summary:

Create a Next.js page for src/pages/create/index.tsx. Here are the instructions:

Issue: Create the Next.js index.tsx page

Background

We need to create the main landing page for our application. This page will be a Next.js page written in TypeScript as a functional component using ES6 syntax like arrow functions. The page will use Tailwind CSS for styling and next-auth/react for authentication. Data will be fetched from the database via API endpoints built using Prisma.

Task

Create a new Next.js page called index.tsx in the src/pages directory. This page should be a functional component using ES6 arrow functions and TypeScript. The page should use Tailwind CSS for styling and next-auth/react for authentication. Fetch data from the database via API endpoints built using Prisma.

Detailed Instructions

  1. In the src/pages directory, create a new file called index.tsx.

  2. Import the necessary dependencies at the top of the file:

    import { useSession } from "next-auth/react";
    import { useEffect, useState } from "react";
    import { Project } from "~/types";
    import ProjectCard from "~/components/ProjectCard";
  3. Define the Props interface for this component:

    interface Props {
     projects: Project[];
    }
  4. Create a functional component called IndexPage that accepts Props as its argument:

    const IndexPage: React.FC<Props> = ({ projects }) => {
     // Component logic and rendering will go here
    };
  5. Inside the IndexPage component, use the useSession hook from next-auth/react to get the user's session:

    const { data: session } = useSession();
  6. Use the useState hook to manage the state of the fetched projects:

    const [fetchedProjects, setFetchedProjects] = useState<Project[]>(projects);
  7. Use the useEffect hook to fetch the projects data from the API when the component mounts:

    useEffect(() => {
     // Fetch projects data from the API and update the state
    }, []);
  8. Inside the useEffect hook, create an async function called fetchProjects that fetches the projects data from the API:

    const fetchProjects = async () => {
     const response = await fetch("/api/projects");
     const data = await response.json();
     setFetchedProjects(data.projects);
    };
  9. Call the fetchProjects function inside the useEffect hook:

    useEffect(() => {
     fetchProjects();
    }, []);
  10. Render the IndexPage component with the following structure:

    • A heading with the text "Welcome to Otto"
    • A subheading with the text "Your Projects"
    • A section that maps over the fetchedProjects state and renders a ProjectCard component for each project
    return (
      <div className="container mx-auto px-4">
        <h1 className="text-4xl font-bold mb-4">Welcome to Otto</h1>
        <h2 className="text-2xl font-semibold mb-4">Your Projects</h2>
        <div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
          {fetchedProjects.map((project) => (
            <ProjectCard key={project.id} project={project} />
          ))}
        </div>
      </div>
    );
  11. Export the IndexPage component as the default export:

    export default IndexPage;

Acceptance Criteria

otto-jacob commented 1 year ago

Hello human! šŸ‘‹

This PR was created by Otto to address the issue Create src/pages/create/index.tsx

Next Steps

  1. Please review the PR carefully. Auto-generated code can and will contain subtle bugs and mistakes.

  2. If you identify code that needs to be changed, please reject the PR with a specific reason. Be as detailed as possible in your comments. Otto will take these comments, make changes to the code and push up changes. Please note that this process will take a few minutes.

  3. Once the code looks good, approve the PR and merge the code.

vercel[bot] commented 1 year ago

The latest updates on your projects. Learn more about Vercel for Git ā†—ļøŽ

Name Status Preview Comments Updated (UTC)
otto-playground āœ… Ready (Inspect) Visit Preview šŸ’¬ Add feedback Jun 7, 2023 11:43pm