Skip to content

Commit 921c893

Browse files
committed
small fixes to type errors and use of next/link
1 parent 990c375 commit 921c893

14 files changed

+78
-62
lines changed

components/Navbar.tsx

+7-13
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import Logo from './Logo'
1010
import NavMenu from './NavMenu'
1111
import SearchButton from './SearchButton'
1212
import { Text } from './Text'
13+
import { StyledLink } from './StyledLink'
1314

1415
const GITHUB_URL = 'https://github.com/csesoc/learning-platform'
1516
const navItems = [
@@ -153,28 +154,21 @@ export default function Navbar() {
153154
</Flex>
154155
<NavContainer isOpen={isOpen}>
155156
{navItems.map((navItem, idx) => (
156-
<Link key={idx} href={`/${navItem.path}`}>
157+
<Link
158+
key={idx}
159+
href={`/${navItem.path}`}
160+
legacyBehavior
161+
passHref>
157162
<Text
158-
as="a"
163+
as={'a'}
159164
css={{ color: '$slate12', cursor: 'pointer', whiteSpace: 'nowrap' }}
160165
onClick={() => { setIsOpen(false); console.log('hi') }}>
161166
{navItem.title}
162-
163167
</Text>
164168
</Link>
165169

166170
)
167171
)}
168-
{/* <Text
169-
as="a"
170-
size="label-lg"
171-
css={{
172-
color: '$slate11',
173-
userSelect: 'none',
174-
cursor: 'not-allowed'
175-
}}>
176-
About
177-
</Text> */}
178172
</NavContainer>
179173
<Box css={{
180174
display: isOpen ? "block" : "none",

data/articles/ppc-backend-1.mdx

+1-2
Original file line numberDiff line numberDiff line change
@@ -172,5 +172,4 @@ In our <Link href="/articles/ppc-backend-2">next article</Link> we will look at
172172
next="/articles/ppc-backend-2"
173173

174174
nextName="Backend Project Tutorial 2 - MongoDB"
175-
>
176-
</ArticleButtonContainer>
175+
/>

data/articles/ppc-backend-2.mdx

+1-3
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,4 @@ nextName="Backend Project Tutorial 3 - CRUD Opearations"
134134

135135
prev="/articles/ppc-backend-1"
136136
prevName="Backend Project Tutorial 1 - Creating a simple Express.js backend"
137-
>
138-
</ArticleButtonContainer>
139-
137+
/>

data/articles/ppc-backend-3.mdx

+1-2
Original file line numberDiff line numberDiff line change
@@ -97,5 +97,4 @@ nextName="Backend Project Tutorial 4 - Users and authentication"
9797

9898
prev="/articles/ppc-backend-2"
9999
prevName="Backend Project Tutorial 2 - MongoDB"
100-
>
101-
</ArticleButtonContainer>
100+
/>

data/articles/ppc-backend-4.mdx

+1-2
Original file line numberDiff line numberDiff line change
@@ -384,5 +384,4 @@ nextName="Backend Project Tutorial 5 - Deployment"
384384

385385
prev="/articles/ppc-backend-3"
386386
prevName="Backend Project Tutorial 3 - CRUD Operations"
387-
>
388-
</ArticleButtonContainer>
387+
/>

data/articles/ppc-backend-5.mdx

+1-2
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,4 @@ That's about it for our backend tutorial. To recap, we have set up an Express ba
5353

5454
prev="/articles/ppc-backend-4"
5555
prevName="Backend Project Tutorial 4 - Users and authentication"
56-
>
57-
</ArticleButtonContainer>
56+
/>

data/articles/reactjs-tut-0.mdx

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
---
2-
title: "ReactJS Project Tutorial: Introduction"
2+
title: 'ReactJS Project Tutorial: Introduction'
33
date: 2022-06-28
44
desc: A series of tutorials to teach you the fundamentals of ReactJS and how to build a frontend project.
55
author: Gordon Huang
66
tags:
77
- 'ReactJS'
88
- 'Frontend'
99
coverPhoto: '/images/generic/shahadat-rahman-BfrQnKBulYQ-unsplash.jpg'
10-
1110
---
1211

1312
Welcome to this tutorial series on ReactJS! This tutorial aims to teach you the fundamentals of the ReactJS front-end library so you can learn how to build your own projects with ReactJS. By the end of this tutorial series you will have built a front-end application like this:
1413

1514
<Centerer>
16-
<img src="https://imgur.com/sfHTEm4.png" alt="Final product of this this tutorial series" width="70%" />
15+
<img
16+
src="https://imgur.com/sfHTEm4.png"
17+
alt="Final product of this this tutorial series"
18+
width="70%"
19+
/>
1720
</Centerer>
1821

1922
ReactJS is a front-end JavaScript library for building user interfaces for websites, dynamic web applications, mobile apps, and many other places that need a visual interface for users to interact with software. It was released in 2013 and since then it has become by far the most popular tool for building web applications. It is made and maintained by Facebook/Meta and is used for many commercial apps and websites like Facebook, Instagram, Airbnb and Uber Eats. Needless to say, ReactJS is currently widely used in industry and there are huge swathes of positions in the tech industry for ReactJS developers. So learning ReactJS will give you valuable front-end UI development skills, and also make you highly employable for many years before the next big front-end framework takes its place.
@@ -28,5 +31,4 @@ If you're ready, learn to build a mini React application starting in the <Link h
2831

2932
next="/articles/reactjs-tut-1"
3033
nextName="ReactJS Project Tutorial: Part 1"
31-
>
32-
</ArticleButtonContainer>
34+
/>

data/articles/reactjs-tut-1.mdx

+17-8
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ $ node -v
4040
and press enter. This tests whether you have installed NodeJS correctly. If you have, it should print the version of NodeJS which you have installed, such as `16.15.0`.
4141

4242
## NPM - Node Package Manager
43+
4344
Installing NodeJS also automatically installs NPM (Node Package Manager) which manages JavaScript packages for your projects. To check that it has installed properly, type into your command line:
4445

4546
```bash:
@@ -82,30 +83,38 @@ $ cd reactjs-project-tutorial
8283
Also open up the project in VSCode by opening up VSCode and opening the folder <FileName>reactjs-project-tutorial</FileName>.
8384

8485
<Centerer>
85-
<img alt="Open VSCode and open a folder" src="https://imgur.com/T6kP1ov.png" width="80%" />
86+
<img
87+
alt="Open VSCode and open a folder"
88+
src="https://imgur.com/T6kP1ov.png"
89+
width="80%"
90+
/>
8691
</Centerer>
8792

8893
<Centerer>
89-
<img alt="Select the my-react-app folder" src="https://imgur.com/vts088y.png" width="80%" />
94+
<img
95+
alt="Select the my-react-app folder"
96+
src="https://imgur.com/vts088y.png"
97+
width="80%"
98+
/>
9099
</Centerer>
91100

92101
You should now be able to see the source code of your new React app in your code editor!
93102

94103
<Centerer>
95-
<img alt="Your React source code app in VSCode" src="https://i.imgur.com/0uACQX4.png" width="80%" />
104+
<img
105+
alt="Your React source code app in VSCode"
106+
src="https://i.imgur.com/0uACQX4.png"
107+
width="80%"
108+
/>
96109
</Centerer>
97110

98111
In the <Link href="/articles/reactjs-tut-2">next tutorial</Link> we'll explore all the different parts of the code that create-react-app has given to us.
99112

100-
101113
<ArticleButtonContainer
102114

103115
next="/articles/reactjs-tut-2"
104116
prev="/articles/reactjs-tut-0"
105117

106118
nextName="ReactJS Project Tutorial: Part 2"
107119
prevName="ReactJS Project Tutorial: Introduction"
108-
>
109-
</ArticleButtonContainer>
110-
111-
120+
/>

data/articles/reactjs-tut-2.mdx

+1-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ In the last tutorial you installed all the tools we'll need to create a React ap
2222
install it.
2323
</Callout>
2424

25-
2625
The <FileName>README.md</FileName> file at the bottom has a brief description of this repository and how to use it. The <FileName>.md</FileName> extension stands for _markdown_, a common text editing syntax to format text. It is not code; markdown is to make text readable for humans.
2726

2827
In general you should use a <FileName>README.md</FileName> in a project to give an overview of what your project does, how to use it, and any other information you think would be useful for people interested in your code.
@@ -85,5 +84,4 @@ prev="/articles/reactjs-tut-1"
8584

8685
nextName="ReactJS Project Tutorial: Part 3"
8786
prevName="ReactJS Project Tutorial: Part 1"
88-
>
89-
</ArticleButtonContainer>
87+
/>

data/articles/reactjs-tut-3.mdx

+1-2
Original file line numberDiff line numberDiff line change
@@ -124,5 +124,4 @@ prev="/articles/reactjs-tut-2"
124124

125125
nextName="ReactJS Project Tutorial: Part 4"
126126
prevName="ReactJS Project Tutorial: Part 2"
127-
>
128-
</ArticleButtonContainer>
127+
/>

data/articles/reactjs-tut-4.mdx

+2-3
Original file line numberDiff line numberDiff line change
@@ -286,13 +286,12 @@ const App = () => {
286286

287287
Currently we have effectively "hard-coded" the restaurant information into our app. We want to be able to dynamically store and change this information. We will learn how to do this in the <Link href="/articles/reactjs-tut-5">next tutorial</Link>.
288288

289-
290289
<ArticleButtonContainer
291290

292291
next="/articles/reactjs-tut-5"
293292
prev="/articles/reactjs-tut-3"
294293

295294
nextName="ReactJS Project Tutorial: Part 5"
296295
prevName="ReactJS Project Tutorial: Part 3"
297-
>
298-
</ArticleButtonContainer>
296+
297+
/>

data/articles/reactjs-tut-5.mdx

+4-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ coverPhoto: '/images/generic/joan-gamell-nFqwVZhimpM-unsplash.jpg'
1212
Variables are a fundamental concept in programming because it allows us to store and modify data depending on where or how our program is used. In a React app, variables are made using something called the `useState` hook. React hooks are functions that can be called from within our functional components like `App` to use various core React features.
1313

1414
<Callout type="note">
15-
The tutorial starts getting a bit tricky here. If you get lost at any point, take a look at the sample implementation at [github.com/dqna64/reactjs-project-tutorial/tree/full-walkthrough](https://github.com/dqna64/reactjs-project-tutorial/tree/full-walkthrough).
15+
The tutorial starts getting a bit tricky here. If you get lost at any point,
16+
take a look at the sample implementation at
17+
[github.com/dqna64/reactjs-project-tutorial/tree/full-walkthrough](https://github.com/dqna64/reactjs-project-tutorial/tree/full-walkthrough).
1618
</Callout>
1719

1820
To use the `useState` hook, first import it into our <FileName>App.jsx</FileName> file. Then inside the `App` functional component and above the return statement, write the following:
@@ -229,5 +231,4 @@ prev="/articles/reactjs-tut-4"
229231
230232
nextName="ReactJS Project Tutorial: Part 6"
231233
prevName="ReactJS Project Tutorial: Part 4"
232-
>
233-
</ArticleButtonContainer>
234+
/>

data/articles/reactjs-tut-6.mdx

+7-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@ Just like how functions in programming can separate responsibilities and elimina
1616
Make a new <FileName>components </FileName> folder in <FileName>src </FileName>. This new folder will store any reusable components that we create. Inside <FileName>src/components </FileName> create a file <FileName>Card.jsx </FileName> and add in this template for a basic React component:
1717

1818
<Centerer>
19-
<img src="https://imgur.com/3qnvh1a.png" alt="new Card.jsx component" width="90%" />
19+
<img
20+
src="https://imgur.com/3qnvh1a.png"
21+
alt="new Card.jsx component"
22+
width="90%"
23+
/>
2024
</Centerer>
2125

2226
We want this `Card` component to render the restaurant card we made in <FileName>App.jsx </FileName>. Cut and paste that JSX into the return of this `Card` component. Remember to wrap it in parentheses. Also be sure to move the star.svg and <FileName>Card.css </FileName> imports from <FileName>App.jsx </FileName> to <FileName>Card.jsx </FileName> (hint: the path from <FileName>Card.jsx </FileName> to <FileName>Card.css </FileName> is <FileName>"../styles/Card.css" </FileName> where ".." means "the parent folder of the folder that contains this file").
@@ -248,12 +252,11 @@ Our app now renders a list of cards of all restaurants specfied in the `places`
248252

249253
That's all for this series of tutorials, well done on making it to the end! The fundamental concepts that you have learned here including components, props and state will be useful in all future ReactJS projects that you work on.
250254

251-
There are also many more things to learn which we haven't covered in this series. What if you want to provide a form to add more restaurants, or increase `visits` count for a restaurant? These features can be achieved using things called *event handlers*, which ReactJS does very similarly to HTML. There are plenty of resources online including other articles, videos and documentation to teach you those things. The best way to learn how to use them is to continue building projects and searching the internet for learning resources like these whenever you get stuck. Good luck on your ReactJS journey and have fun!
255+
There are also many more things to learn which we haven't covered in this series. What if you want to provide a form to add more restaurants, or increase `visits` count for a restaurant? These features can be achieved using things called _event handlers_, which ReactJS does very similarly to HTML. There are plenty of resources online including other articles, videos and documentation to teach you those things. The best way to learn how to use them is to continue building projects and searching the internet for learning resources like these whenever you get stuck. Good luck on your ReactJS journey and have fun!
252256

253257
<ArticleButtonContainer
254258

255259
prev="/articles/reactjs-tut-5"
256260

257261
prevName="ReactJS Project Tutorial: Part 5"
258-
>
259-
</ArticleButtonContainer>
262+
/>

pages/articles/[slug].tsx

+27-10
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { allArticleTypes, ArticleType } from 'contentlayer/generated'
55
import { format, parseISO } from 'date-fns'
66
import { useMDXComponent } from 'next-contentlayer/hooks'
77
import Head from 'next/head'
8-
import Image from 'next/image'
98
import { Box } from 'components/Box'
109
import Callout from 'components/Callout'
1110
import FileName from 'components/Filename'
@@ -21,26 +20,44 @@ import NextArticleButton from 'components/NextArticleButton'
2120
// import PrevArticleButton from 'components/PrevArticleButton'
2221
import ArticleButtonContainer from 'components/ArticleNavigationContainer'
2322
import { BackButton } from 'components/BackButton'
23+
import { MDXComponents } from 'mdx/types'
24+
import { forwardRef } from 'react'
2425

2526

26-
const defaultComponents = {
27-
Image,
27+
/**
28+
* Create lightweight wrapper components to satisfy MDXComponents type
29+
*/
30+
const WrappedLink = ({ href, children }: { href: string, children: React.ReactNode }) => {
31+
return (
32+
<Link href={href}>
33+
children
34+
</Link>
35+
)
36+
}
37+
38+
const WrappedArrowDown = ({ size }: { size: number }) => {
39+
return (
40+
<ArrowDown size={size} />
41+
)
42+
}
43+
44+
45+
46+
// Add any components used in MDX files here.
47+
// Components here load dynamically if they're used.
48+
// See https://github.com/tsriram/with-mdx-bundler for details.
49+
const components: MDXComponents = {
2850
Callout,
2951
FileName,
3052
Centerer,
3153
MultiChoice,
32-
Link,
33-
ArrowDown,
54+
Link: WrappedLink,
55+
ArrowDown: WrappedArrowDown,
3456
NextArticleButton,
3557
// PrevArticleButton,
3658
ArticleButtonContainer
3759
}
3860

39-
// Add any components used in MDX files here.
40-
// Components here load dynamically if they're used.
41-
// See https://github.com/tsriram/with-mdx-bundler for details.
42-
const components = { ...defaultComponents }
43-
4461
export async function getStaticPaths() {
4562
const paths = allArticleTypes.map((a) => ({ params: { slug: a.slug } }))
4663
return {

0 commit comments

Comments
 (0)