|
1 | 1 | # Let's build some beautiful front end
|
2 | 2 |
|
| 3 | +In this section, we will start by setting up the face of our OctoFit application by building the front end page. To do that, we will keep it as simple as possible for now. We need resources like **HTML** and **CSS** to start decorating first, and we will later modify the page to extend the functionalities. |
| 4 | + |
| 5 | +## Goals/Outcome |
| 6 | + |
| 7 | +- Understand the basic strategies around designing the **OctoFit Tracker** app by asking **GitHub Copilot** Chat |
| 8 | +- Start getting the feel for OctoFit app by generating HTML and CSS resources |
| 9 | +- See a front-end page with a greeting message |
| 10 | + |
| 11 | +Let's take a look at what we have so far by expanding the `octofit-tracker/frontend`. It will look something like this: |
| 12 | + |
| 13 | + |
| 14 | + |
| 15 | +Let's expand `public` section because that is where we will find our static files. |
| 16 | + |
| 17 | +Type the following prompt in GitHub Copilot Chat: |
| 18 | + |
| 19 | +> TIP: we are going to use gpt-4o as our OpenAI GPT model for this GitHub Universe Workshop |
| 20 | +
|
| 21 | +```text |
| 22 | +Now, how can I add HTML and CSS on these to make it more OctoFit tracker like? |
| 23 | +
|
| 24 | +Launch the port in 8080 |
| 25 | +Make sure to add a simple navigation |
| 26 | +Ignore bootstrap for now |
| 27 | +``` |
| 28 | + |
| 29 | +If I type that command in the GitHub **Copilot Chat**, it may look like this: |
| 30 | + |
| 31 | + |
| 32 | + |
| 33 | +And the generated response might look like this: |
| 34 | + |
| 35 | + |
| 36 | + |
| 37 | +> :warning: **TIP:** What if you don't get the same response? That's okay! The beauty of GitHub Copilot is that it is generative, and it will give you a different response each time. The key is to be persistent and keep asking the same question in different ways until you get a response that you are happy with. :smile: |
| 38 | +
|
| 39 | +And if you type the following command in the GitHub **Copilot Chat**, it will create a new port in `8080`. |
| 40 | + |
| 41 | + |
| 42 | + |
| 43 | +And the final result should look like this: |
| 44 | + |
| 45 | + |
| 46 | + |
| 47 | +That is it! Please refer to the **Solution** below or the [troubleshoot guide](../9_Troubleshooting/README.md) if you encounter any issues. |
| 48 | + |
| 49 | +## Solution |
| 50 | + |
| 51 | +This shows one possible solution where you need to make a change: |
| 52 | + |
| 53 | +### Modify the following files: |
| 54 | + |
| 55 | +`src/App.js` |
| 56 | + |
| 57 | +```javascript |
| 58 | +import React from 'react'; |
| 59 | +import './App.css'; |
| 60 | + |
| 61 | +function App() { |
| 62 | + return ( |
| 63 | + <div className="App"> |
| 64 | + <nav className="navbar"> |
| 65 | + <ul> |
| 66 | + <li><a href="/">Home</a></li> |
| 67 | + <li><a href="/profile">Profile</a></li> |
| 68 | + <li><a href="/activities">Activities</a></li> |
| 69 | + <li><a href="/teams">Teams</a></li> |
| 70 | + <li><a href="/leaderboard">Leaderboard</a></li> |
| 71 | + <li><a href="/workouts">Workouts</a></li> |
| 72 | + </ul> |
| 73 | + </nav> |
| 74 | + <header className="App-header"> |
| 75 | + <h1>Welcome to OctoFit Tracker</h1> |
| 76 | + </header> |
| 77 | + </div> |
| 78 | + ); |
| 79 | +} |
| 80 | + |
| 81 | +export default App; |
| 82 | +``` |
| 83 | + |
| 84 | +Create or modify `src/App.css` |
| 85 | + |
| 86 | +```css |
| 87 | +.App { |
| 88 | + text-align: center; |
| 89 | +} |
| 90 | + |
| 91 | +.navbar { |
| 92 | + background-color: #333; |
| 93 | + overflow: hidden; |
| 94 | +} |
| 95 | + |
| 96 | +.navbar ul { |
| 97 | + list-style-type: none; |
| 98 | + margin: 0; |
| 99 | + padding: 0; |
| 100 | +} |
| 101 | + |
| 102 | +.navbar li { |
| 103 | + float: left; |
| 104 | +} |
| 105 | + |
| 106 | +.navbar li a { |
| 107 | + display: block; |
| 108 | + color: white; |
| 109 | + text-align: center; |
| 110 | + padding: 14px 16px; |
| 111 | + text-decoration: none; |
| 112 | +} |
| 113 | + |
| 114 | +.navbar li a:hover { |
| 115 | + background-color: #111; |
| 116 | +} |
| 117 | + |
| 118 | +.App-header { |
| 119 | + background-color: #282c34; |
| 120 | + min-height: 100vh; |
| 121 | + display: flex; |
| 122 | + flex-direction: column; |
| 123 | + align-items: center; |
| 124 | + justify-content: center; |
| 125 | + font-size: calc(10px + 2vmin); |
| 126 | + color: white; |
| 127 | +} |
| 128 | +``` |
| 129 | + |
| 130 | + |
| 131 | +`package.json` |
| 132 | +Update the following section: |
| 133 | + |
| 134 | +```json |
| 135 | + "scripts": { |
| 136 | + "start": "PORT=8080 react-scripts start", |
| 137 | + "build": "react-scripts build", |
| 138 | + "test": "react-scripts test", |
| 139 | + "eject": "react-scripts eject" |
| 140 | + }, |
| 141 | +``` |
| 142 | + |
| 143 | +### Run the following commands: |
| 144 | + |
| 145 | +```bash |
| 146 | +cd octofit-tracker/frontend |
| 147 | +``` |
| 148 | + |
| 149 | +Then, followed by... |
| 150 | + |
| 151 | +```bash |
| 152 | +npm start |
| 153 | +``` |
| 154 | + |
| 155 | +Check the browser at the port `8080` to see the changes. |
3 | 156 |
|
4 | 157 | [:arrow_backward: Previous: Getting started - app frontend and backend creation](../3_GettingStarted/README.md) | [Next: The OctoFit Tracker database and app backend creation :arrow_forward:](../5_BackendSettings/README.md)
|
0 commit comments