πŸ’‘ Assignment 1: Welcome Message
by Tomas TrescakΒ· Setup

Root Folder
Not Attempted
NameProgress
Introduction
Not Read
🍰 Player
Not Read
Software Installation
Project Setup
Running and Testing
React and ReactDOM
πŸ’‘ Assignment 1: Welcome Message
Not Attempted
Submissions
React
Not Attempted
NameProgress
JSX and Components
Not Read
Props
Not Read
πŸ‘Ύ Exercise: Props
Not Attempted
CSS Styles
Not Read
useState and Hooks
Not Read
πŸ‘Ύ Exercise: useState
Not Attempted
Conditional Rendering
Not Read
Lists
Not Read
πŸ‘Ύ Exercise: Lists
Not Attempted
Forms and Events
Not Read
πŸ‘Ύ Exercise: Forms
Not Attempted
πŸ’‘ Assignment 2: Front End
Not Attempted
Advanced React
Not Attempted
NameProgress
Pure Components - memo
Not Read
Lifecycle - useEffect
Not Read
Expensive? - useMemo
Not Read
DOM Interactions - useRef
Not Read
forwardRef
Not Read
useImperativeHandle
Not Read
πŸ‘Ύ useImperativeHandle
Not Attempted
Context
Not Read
useCallback
Not Read
useId
Not Read
useReducer
Not Read
Infrastructure
Not Attempted
NameProgress
Database
Not Read
NextAuth and Github Authentication
Not Read
Prisma and ORM
Not Read
Project Setup
Not Read
Project Authentication
Not Read
APIs
Not Attempted
NameProgress
APIs
Not Read
APIs - Slides
Not Attempted
Rest APIs
Not Read
Rest APIs - Express.js
Not Read
ReastAPIs - Next.js
Not Read
Securing APIs
Not Read
Securing APIs - NextAuth
Not Read
tRPC
Not Attempted
NameProgress
tRPC
Not Read
tRPC - Routers
Not Read
tRPC - Server Rendering
Not Read
tRPC - Client Rendering
Not Read
Persisting Data
Not Read
Assignment 3: APIs
Not Read
0 / 250 XP
The external project has not been reviewed yet
Please follow instructions below to submit your project

Lecture Transcript
If you prefer text to video, check out the transcript of the presentation above

It's time to solve our first assignment. This time we will do it together!

In this assignment, we keep things simple! You have the following goals:

Add the "Get Things Done" header to your application

Render the initial list of tasks

Once you are done, your result should look as in the following figure

Please open the assignment project in Visual Studio Code. If you forgot how to download your assignment files, please check out the section called Project Setup.

The downloaded project is a NextJS application. Next is a framework for building web application that comes with opinionated project structure supporting routing, client and server rendering and others. We will explore individual features of NextJS in this course in due time.

Let's start exploring the fantastic world of NextJS. First, you need to know that NextJS uses file system-based routing, where each directory represents one segment of your route.

Please check out the directory structure of your project, which you can find in the left part of the Visual Studio Code.

The "src" folder contains the majority of your source code files.

The app folder is a special folder in NextJS representing the root point of your application. Every subdirectory in the app folder represents a route of your web application. More on this later.

The source code of the page is stored in the page.tsx file. The page.tsx stored in the app folder represents the entry point to your web application. In our case, we create a simple React component that returns a Hello World text.

If you run this NextJS application and open it in your browser at http localhost 3000, you will see the Hello World text.

Now, what if we would like to display different content in a new URL path, such as a list of tasks in a new tasks page?

With NextJS it's easy! All we have to do is to create a new directory named "tasks", representing the URL path "/tasks". Inside that directory we create the page.tsx file with the source code of the page.

In our case, we simply render the header of the page with the text Tasks.

When you visit the application in the browser, the welcome page will not display anything. So, how do you proceed? The easiest way to see what is expected of you in the assignment is to run automated tests and ensure they all pass. Thus, in a separate terminal, run the command "pnpm test," which will launch automated tests.

As you would expect, the results are somewhat disappointing, with all the tests failing. Let's fix that!

Please open the entry page file at src/app/page.tsx. As you see, it is not showing anything.

Now, add β€œGet Things Done” between the h1 tags and save your file.

Let's do it together now! We make the changes and save the file. Two things have happened. The page in the browser automatically reloads with your modified content, and the tests are automatically re-run, this time with only one failing test! The process is called β€œhot reloading,” and it makes your changes instantaneous, facilitating development of web applications.

Let's talk about what you need to do to finish your assignment. The best way to find out what is required is to explore the automated tests. In test-driven development, this is how you develop. You first write tests and then the functionality. It is a great practice! Please see the page.test file.

Lines eight to ten show that the test expects the three Tasks to exist in the document, that is, to be displayed on the page. Let's fix that!

Please open the file page.tsx

This time, we will hard code the three tasks to the page as a list. Please make the changes and save the file.

When you save your file, you can see that both tests are now complete! We are almost done. We need to submit our assignment to the classroom. We will do this in the next section.

Welcome to your first assignment! We will keep things simple! Your goal is to:

  1. Add the "Get Things Done" header to your application.
  2. Render the initial list of tasks described as:
    1. Task 1
    2. Task 2
    3. Task 3

Your result should look as follows:

Final Outcome

πŸ›Ÿ Help

The downloaded project is a NEXT.js application. Next is a framework for building web application that comes with opinionated project structure supporting routing, client and server rendering and others. We will explore individual features of NEXT.js in this course in due time.

To start, you need to know that NEXT.js uses file system based routing, where each directory represents one segment of your route. In that directory you need to have a page.tsx file, which takes care of rendering the web page. The root of the router is stored in the src/app folder of your project.

For example route http://localhost:3000/home/profile would render a page stored in your src/app/home/profile/page.tsx file.

Since we need to modify the root of our application, we need to modify the src/app/page.tsx file. Currently the file does not contain much:

import styles from "./index.module.css";

export default async function Home() {
  return (
    <main className={styles.main}>
      <div className={styles.container}>
        <h1 className={styles.title}></h1>
      </div>
    </main>
  );
}

There are the peculiar β€œstyles.abc” statements in the page code. These statements represent CSS style imports from the CSS file. This technique is called CSS modules (read on!). The benefit of CSS modules are multiple, including that the names of classes are local and do not interfere with other components, eliminating conflicts, or that only the styles that the current content needs is sent to the client, reducing bandwidth and speeding up your website.

πŸ§ͺ Tests

When you visit the application in the browser, welcome page will not display anything.  So, how do you proceed? The easiest way to see what is expected from you in the assignment, is to run automated tests and to make sure they all pass. In a seperate terminal run the following command:

pnpm test

This will launch the automated unit tests checking for correctness of your solution. Unfortunately, all of your tests fail and you will see the following result:

Failing tests on initial run

 

 Please try add β€œGet Things Done” between h1 tags in your src/app/page.tsx file and save the file. 

<h1 className={styles.title}>Get Things Done</h1>

You should see that two things have happened:

  1. The page in the browser automatically reloads with your modified content. This process is called β€œhot reloading” making your changes instantaneous.
  2. Your tests have re-run and you should have now only 1 failing tests and 1 passing test!
Passing and a failing test

🏁 Completing Assignment

When you open the src/app/page.test.tsx file, you see that we expect to see β€œTask 1”, β€œTask 2” and β€œTask 3” in the document. This should be understandable from the code below:

it("Show the list of tasks", async function () {
  render(
    <Suspense>
      <Page />
    </Suspense>
  );

  expect(await screen.findByText("Task 1")).toBeInTheDocument();
  expect(screen.getByText("Task 2")).toBeInTheDocument();
  expect(screen.getByText("Task 3")).toBeInTheDocument();
});

Let us finalise the page and provide all three tasks in the unordered list. This is the final source of the src/app/page.tsx:

import styles from "./index.module.css";

export default async function Home() {
  return (
    <main className={styles.main}>
      <div className={styles.container}>
        <h1 className={styles.title}>Get Things Done</h1>
        <ul>
          <li>Task 1</li>
          <li>Task 2</li>
          <li>Task 3</li>
        </ul>
      </div>
    </main>
  );
}

When you save your file, you can see that both tests now complete! πŸŽ‰πŸ•πŸ§ πŸ₯Ή We are almost done. We need to submit our assignment to the classroom.

Passing all tests!

Discussion

0 comments
Loading editor ...
Remember to be polite and report any undesirable behaviour

Category

Empty

Labels

Discussion has no labels

1 participant

user avatar

Priority

Notifications

You're not receiving notifications from this thread.
Course Outline