|
1 | 1 | # STEP7: Implement a simple Mercari webapp as frontend
|
2 | 2 |
|
3 |
| - |
4 | 3 | ## 1. Build local environment
|
5 |
| -Install Node v20 from below. |
6 |
| -(20.11.0 LTS is recommended as of Jan 2024) |
| 4 | + |
| 5 | +Install Node v22 from below. |
| 6 | +(v22.13.1 LTS is recommended as of Feb 2025) |
7 | 7 |
|
8 | 8 | https://nodejs.org/en/
|
9 | 9 |
|
10 | 10 | If you would like to install multiple versions of Node, use [nvs](https://github.com/jasongin/nvs).
|
11 | 11 |
|
12 |
| -Run `node -v` and confirm that `v20.0.0` or above is displayed. |
| 12 | +Run `node -v` and confirm that `v22.0.0` or above is displayed. |
13 | 13 |
|
14 | 14 | Move to the following directory and install dependencies with the following command.
|
| 15 | + |
15 | 16 | ```shell
|
16 | 17 | cd typescript/simple-mercari-web
|
17 | 18 | npm ci
|
18 | 19 | ```
|
19 | 20 |
|
20 | 21 | After launching the web application with the following command, check your web app from your browser at [http://localhost:3000/](http://localhost:3000/).
|
| 22 | + |
21 | 23 | ```shell
|
22 | 24 | npm start
|
23 | 25 | ```
|
24 | 26 |
|
25 | 27 | Run the backend servers in Python/Go as described in Step3.
|
26 | 28 | This simple web application allows you to do two things
|
| 29 | + |
27 | 30 | - Add a new item (Listing)
|
28 | 31 | - View the list of items (ItemList)
|
29 | 32 |
|
30 |
| -These functionalities are carved out as components called `src/components/Listing` and `src/components/ItemList`, and called from the main `App.tsx`. |
| 33 | +These functionalities are carved out as components called `src/components/Listing.tsx` and `src/components/ItemList.tsx`, and called from the main `App.tsx`. |
31 | 34 |
|
32 | 35 | :pushpin: Sample code is in React but the knowledge of React is not necessary.
|
33 | 36 |
|
34 |
| -### (Optional) Task 1: Add a new item |
35 |
| -Use the listing form to add a new item. In this screen, you can input name, category and an image for a new item. |
| 37 | +## (Optional) Task 1: Add a new item |
36 | 38 |
|
37 |
| -If your API from STEP3 only accepts name and category, modify `typescript/simple-mercari-web/src/components/Listing/Listing.tsx` and delete the image field. |
| 39 | +Use the listing form to add a new item. In this screen, you can input name, category and an image for a new item. |
38 | 40 |
|
| 41 | +If your API from STEP3 only accepts name and category, modify `typescript/simple-mercari-web/src/components/Listing.tsx` and delete the image field. |
39 | 42 |
|
40 |
| -### (Optional) Task 2. Show item images |
| 43 | +## (Optional) Task 2. Show item images |
41 | 44 |
|
42 | 45 | In this screen, item images are all rendered as Build@Mercari logo. Specify the item image as `http://localhost:9000/image/<item_id>.jpg` and see if they can be displayed on the web app.
|
43 | 46 |
|
| 47 | +## (Optional) Task 3. Change the styling with HTML and CSS |
44 | 48 |
|
45 |
| -### (Optional) Task 3. Change the styling with HTML and CSS |
46 | 49 | These two components are styled by CSS. To see what types of changes can be made, try modifying `ItemList` component CSS. These are specified in `App.css` and they are applied by `className` attribute (e.g. `<div className='Listing'></div>`).
|
| 50 | + |
47 | 51 | ```css
|
48 | 52 | .Listing {
|
49 |
| - ... |
| 53 | + ...; |
50 | 54 | }
|
51 | 55 | .ItemList {
|
52 |
| - ... |
| 56 | + ...; |
53 | 57 | }
|
54 | 58 | ```
|
55 |
| -Try editing the HTML tags returned in each component and see how the UI changes. |
56 | 59 |
|
| 60 | +Try editing the HTML tags returned in each component and see how the UI changes. |
57 | 61 |
|
58 |
| -### (Optional) Task 4. Change the UI for ItemList |
| 62 | +## (Optional) Task 4. Change the UI for ItemList |
59 | 63 |
|
60 | 64 | Current `ItemList` shows one column of items sequentially. Use the following reference to change this style into a grid system where multiple items are displayed in the same row.
|
61 | 65 |
|
62 |
| - |
63 | 66 | **:book: References**
|
64 | 67 |
|
65 | 68 | - [HTML basics](https://developer.mozilla.org/en-US/docs/Learn/Getting_started_with_the_web/HTML_basics)
|
66 | 69 |
|
67 |
| - |
68 | 70 | - [CSS basics](https://developer.mozilla.org/en-US/docs/Learn/Getting_started_with_the_web/CSS_basics)
|
69 | 71 |
|
70 |
| - |
71 | 72 | - [Basic Concepts of grid layout](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Grid_Layout/Basic_Concepts_of_Grid_Layout)
|
72 | 73 |
|
73 | 74 | ---
|
74 | 75 |
|
75 |
| -### Next |
| 76 | +## Tips |
| 77 | + |
| 78 | +### Debugging |
| 79 | + |
| 80 | +Debugging is the process of checking the operation of a program, identifying problems, and fixing them. In web front-end development, debugging can be performed using the following methods: |
| 81 | + |
| 82 | +By inserting `console.debug()` at the points in the code where you want to check the operation, you can verify the values and states at runtime. For example, in `ItemList.tsx`: |
| 83 | + |
| 84 | +```typescript |
| 85 | +export const ItemList = (props: Prop) => { |
| 86 | + ... |
| 87 | + useEffect(() => { |
| 88 | + const fetchData = () => { |
| 89 | + fetchItems() |
| 90 | + .then((data) => { |
| 91 | + console.debug('GET success:', data); // Check the contents of the data retrieved from the API here |
| 92 | + ... |
| 93 | + }) |
| 94 | + .catch((error) => { |
| 95 | + console.error('GET error:', error); |
| 96 | + }); |
| 97 | + }; |
| 98 | + ... |
| 99 | +``` |
| 100 | +
|
| 101 | +This debugging information can be checked using the browser's developer tools (**Chrome DevTools**). Chrome DevTools can be opened in any of the following ways: |
| 102 | +
|
| 103 | +- Keyboard shortcuts: |
| 104 | + - Windows/Linux: `Ctrl + Shift + I` |
| 105 | + - macOS: `Cmd + Option + I` |
| 106 | +- Right-click on the browser and select "Inspect" |
| 107 | +- From the menu, select "More tools" > "Developer tools" |
| 108 | +
|
| 109 | +The information output by `console.debug()` will be displayed in the "Console" tab of the developer tools. |
| 110 | +
|
| 111 | +For detailed instructions on how to use the developer tools, refer to the [Chrome DevTools documentation](https://developer.chrome.com/docs/devtools/open?hl=en). |
| 112 | +
|
| 113 | +### Build Production-Ready App by using Framework |
| 114 | +
|
| 115 | +This material aims to provide a basic understanding of React, so it does not use any specific frameworks. However, the React development team recommends using the following frameworks when developing actual production-level web services ([Creating a React App](https://react.dev/learn/creating-a-react-app)): |
| 116 | +
|
| 117 | +- [Next.js (App Router)](https://nextjs.org/docs) |
| 118 | +- [React Router (v7)](https://reactrouter.com/start/framework/installation) |
| 119 | +
|
| 120 | +:warning: As a point of caution, **it has been [officially announced on February 14, 2025](https://react.dev/blog/2025/02/14/sunsetting-create-react-app) that [`create-react-app`](https://github.com/facebook/create-react-app), which is introduced in many React materials, will be deprecated**. For new projects, it is strongly recommended to consider methods other than using `create-react-app`. |
| 121 | +
|
| 122 | +In the future, when you are responsible for developing services intended for long-term use by users, consider using these frameworks. When creating a new service, it is important to understand the characteristics of each framework and the requirements of the service you want to create, and select the appropriate framework. |
| 123 | +
|
| 124 | +When selecting a framework, it is good to consider the following perspectives: |
| 125 | +
|
| 126 | +- Scale and complexity of the service |
| 127 | +- Performance requirements |
| 128 | +- SEO requirements |
| 129 | +- Team's technology stack |
| 130 | +- Deployment environment |
| 131 | +
|
| 132 | +## Next |
76 | 133 |
|
77 |
| -[STEP8: Run frontend and API using docker-compose](08-docker-compose.en.md) |
| 134 | +[STEP8: Run frontend and API using docker-compose](08-docker-compose.en.md) |
0 commit comments