Skip to content

Commit 44a0db4

Browse files
committed
Convert entire project to Typescript
1 parent 5143d48 commit 44a0db4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+1767
-1793
lines changed

.prettierignore

+3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ build/
22
coverage/
33
dist/
44
node_modules/
5+
public/
56
package.json
67
.cache/
8+
.github/
9+
.vscode/
710
.snapshots/
811
*.min.js

.prettierrc

+11-7
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
{
2-
"useTabs": false,
2+
"arrowParens": "avoid",
3+
"bracketSpacing": true,
4+
"endOfLine": "lf",
5+
"bracketSameLine": false,
6+
"jsxSingleQuote": false,
37
"printWidth": 80,
4-
"tabWidth": 2,
8+
"proseWrap": "preserve",
9+
"quoteProps": "as-needed",
10+
"semi": true,
511
"singleQuote": true,
6-
"trailingComma": "es5",
7-
"jsxBracketSameLine": false,
8-
"parser": "babel",
9-
"noSemi": true,
10-
"rcVerbose": false
12+
"tabWidth": 2,
13+
"trailingComma": "all",
14+
"useTabs": false
1115
}

.vscode/settings.json

-1
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,4 @@
1818
"editor.defaultFormatter": "esbenp.prettier-vscode",
1919
"editor.formatOnSave": true
2020
},
21-
"typescript.validate.enable": false,
2221
}

css-styles

gatsby-browser.js

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import '@zigurous/css-styles/dist/index.css';
2-
import '@zigurous/react-components/dist/index.css';
32
import './src/styles/global.css';
43

54
const updateFavicon = (isDark) => {

gatsby-node.js

+15-6
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,15 @@ exports.onCreateWebpackConfig = ({ actions }) => {
1111
});
1212
};
1313

14+
exports.onCreateBabelConfig = ({ actions }) => {
15+
actions.setBabelPlugin({
16+
name: '@babel/plugin-transform-react-jsx',
17+
options: {
18+
runtime: 'automatic',
19+
},
20+
});
21+
};
22+
1423
exports.createSchemaCustomization = ({ actions }) => {
1524
const { createTypes } = actions;
1625
const typeDefs = `
@@ -26,7 +35,7 @@ exports.createSchemaCustomization = ({ actions }) => {
2635
tech: [String]
2736
image: File! @fileByRelativePath
2837
imageAltText: String
29-
imageBorder: String
38+
imageBorder: Boolean
3039
buttons: [ProjectButton]
3140
sections: [ProjectSection]
3241
}
@@ -42,7 +51,7 @@ exports.createSchemaCustomization = ({ actions }) => {
4251
tech: [String]
4352
image: File! @fileByRelativePath
4453
imageAltText: String
45-
imageBorder: String
54+
imageBorder: Boolean
4655
buttons: [ProjectButton]
4756
sections: [ProjectSection]
4857
}
@@ -58,7 +67,7 @@ exports.createSchemaCustomization = ({ actions }) => {
5867
tech: [String]
5968
image: File! @fileByRelativePath
6069
imageAltText: String
61-
imageBorder: String
70+
imageBorder: Boolean
6271
buttons: [ProjectButton]
6372
sections: [ProjectSection]
6473
}
@@ -74,7 +83,7 @@ exports.createSchemaCustomization = ({ actions }) => {
7483
tech: [String]
7584
image: File! @fileByRelativePath
7685
imageAltText: String
77-
imageBorder: String
86+
imageBorder: Boolean
7887
buttons: [ProjectButton]
7988
sections: [ProjectSection]
8089
}
@@ -90,7 +99,7 @@ exports.createSchemaCustomization = ({ actions }) => {
9099
tech: [String]
91100
image: File! @fileByRelativePath
92101
imageAltText: String
93-
imageBorder: String
102+
imageBorder: Boolean
94103
buttons: [ProjectButton]
95104
sections: [ProjectSection]
96105
}
@@ -107,8 +116,8 @@ exports.createSchemaCustomization = ({ actions }) => {
107116
tags: [String]
108117
}
109118
type ProjectButton {
119+
to: String!
110120
name: String!
111-
url: String!
112121
icon: String
113122
}
114123
type ProjectSection {

package.json

+10-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
22
"name": "@adamgraham/portfolio",
3-
"version": "1.0.0",
3+
"version": "2.0.0",
44
"homepage": "https://adamgraham.github.io",
55
"private": true,
66
"dependencies": {
7-
"@zigurous/css-styles": "^2.2.0",
8-
"@zigurous/react-components": "^2.2.0",
7+
"@zigurous/css-styles": "^3.0.0",
8+
"@zigurous/react-components": "^3.0.0",
99
"classnames": "^2.3.1",
1010
"gatsby": "^4.17.0",
1111
"gatsby-plugin-google-analytics": "^4.17.0",
@@ -21,13 +21,17 @@
2121
"gatsby-transformer-json": "^4.17.0",
2222
"gatsby-transformer-sharp": "^4.17.0",
2323
"gh-pages": "^4.0.0",
24-
"prop-types": "^15.8.1",
2524
"react": "^18.1.0",
2625
"react-dom": "^18.1.0",
2726
"react-helmet": "^6.1.0",
2827
"use-query-params": "^2.2.1"
2928
},
3029
"devDependencies": {
30+
"@babel/plugin-transform-react-jsx": "^7.25.7",
31+
"@types/node": "^20.11.0",
32+
"@types/react": "^18.1.0",
33+
"@types/react-dom": "^18.1.0",
34+
"@types/react-helmet": "^6.1.11",
3135
"eslint": "^8.18.0",
3236
"eslint-config-prettier": "^8.5.0",
3337
"eslint-config-standard": "^17.0.0",
@@ -51,6 +55,7 @@
5155
"precommit": "eslint src --fix --quiet",
5256
"predeploy": "gatsby build",
5357
"serve": "gatsby serve",
54-
"start": "gatsby develop"
58+
"start": "gatsby develop",
59+
"typecheck": "tsc --noEmit"
5560
}
5661
}

react-components

src/components/Dock.js src/components/Dock.tsx

+32-19
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,32 @@
11
import '../styles/dock.css';
2-
import { Icon, Link, SocialIcon } from '@zigurous/react-components';
2+
import { Icon, Link, SocialIcon, Theme } from '@zigurous/react-components'; // prettier-ignore
33
import { Link as GatsbyLink } from 'gatsby';
44
import React from 'react';
55
import { dockLinks, socialLinks } from '../links';
6+
import type { LinkType } from '../types';
67

7-
const Dock = ({ theme, toggleTheme, secondaryLinks }) => {
8+
export interface DockProps {
9+
theme: Theme;
10+
toggleTheme: () => void;
11+
secondaryLinks?: LinkType[];
12+
}
13+
14+
export default function Dock({
15+
theme,
16+
toggleTheme,
17+
secondaryLinks,
18+
}: DockProps) {
819
return (
920
<div className="dock">
1021
<div className="dock__container" id="primary">
1122
<div className="dock__section" id="navigation">
12-
{dockLinks.map((link) => (
13-
<DockItem link={link} key={link.key} />
23+
{dockLinks.map(link => (
24+
<DockItem link={link} key={link.id} />
1425
))}
1526
</div>
1627
<div className="dock__section" id="socials">
17-
{socialLinks.map((link) => (
18-
<DockItem link={link} key={link.key} external />
28+
{socialLinks.map(link => (
29+
<DockItem link={link} key={link.id} external />
1930
))}
2031
</div>
2132
<div className="dock__section" id="gallery">
@@ -57,33 +68,35 @@ const Dock = ({ theme, toggleTheme, secondaryLinks }) => {
5768
</div>
5869
{secondaryLinks && (
5970
<div className="dock__container" id="secondary">
60-
{secondaryLinks.map((link) => (
61-
<DockItem link={link} key={link.key || link.name} external />
71+
{secondaryLinks.map(link => (
72+
<DockItem link={link} key={link.id || link.name} external />
6273
))}
6374
</div>
6475
)}
6576
</div>
6677
);
67-
};
78+
}
79+
80+
export interface DockItemProps {
81+
link: LinkType;
82+
external?: boolean;
83+
}
6884

69-
const DockItem = ({ link, external = false }) => {
85+
export function DockItem({ link, external = false }: DockItemProps) {
7086
return (
7187
<div className="dock__item" id={link.name}>
7288
<Link
73-
ElementType={link.ElementType || (external ? 'a' : GatsbyLink)}
89+
as={external ? 'a' : GatsbyLink}
7490
external={external}
75-
to={link.to || link.url}
91+
to={link.to}
7692
unstyled
7793
>
78-
{link.icon ? (
79-
<Icon name={link.icon} />
80-
) : (
81-
<SocialIcon iconName={link.key} innerPadding={0} size={18} />
94+
{link.icon && <Icon name={link.icon} />}
95+
{link.socialIcon && (
96+
<SocialIcon icon={link.socialIcon} innerPadding={0} size={18} />
8297
)}
8398
</Link>
8499
<div className="dock__tooltip">{link.name}</div>
85100
</div>
86101
);
87-
};
88-
89-
export default Dock;
102+
}

src/components/Gallery.js src/components/Gallery.tsx

+18-16
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,41 @@ import '../styles/gallery.css';
22
import { useMediaQuery } from '@zigurous/react-components';
33
import classNames from 'classnames';
44
import { navigate } from 'gatsby';
5-
import PropTypes from 'prop-types';
65
import React, { useCallback, useEffect } from 'react';
7-
import Slide, { SlideProps } from './Slide';
6+
import Slide from './Slide';
7+
import type { SlideData } from '../types';
88
import { getSessionIndex, setSessionIndex } from '../utils/session';
99

10-
const Gallery = ({ category, location, slides = [] }) => {
10+
export interface GalleryProps {
11+
category: string;
12+
location: Location;
13+
slides: SlideData[];
14+
}
15+
16+
export default function Gallery({
17+
category,
18+
location,
19+
slides = [],
20+
}: GalleryProps) {
1121
const vertical = useMediaQuery('(max-width: 1365px)');
1222

1323
const urlParams = new URLSearchParams(location?.search);
1424
const slideIndex =
1525
(urlParams.has('index')
16-
? Number.parseInt(urlParams.get('index')) || 0
26+
? Number.parseInt(urlParams.get('index')!) || 0
1727
: getSessionIndex(category)) % slides.length;
1828

1929
const currentSlide =
20-
slideIndex >= 0 && slideIndex < slides.length && slides[slideIndex];
30+
slideIndex >= 0 && slideIndex < slides.length ? slides[slideIndex] : null;
2131

2232
const setSlideIndex = useCallback(
23-
(index) => {
33+
(index: number) => {
2434
if (index >= slides.length) index = 0;
2535
if (index < 0) index = slides.length - 1;
2636
setSessionIndex(category, index);
2737
navigate(`/${category}?index=${index}`, { replace: true });
2838
},
29-
[category, slides, slideIndex]
39+
[category, slides, slideIndex],
3040
);
3141

3242
useEffect(() => {
@@ -81,12 +91,4 @@ const Gallery = ({ category, location, slides = [] }) => {
8191
</button>
8292
</div>
8393
);
84-
};
85-
86-
Gallery.propTypes = {
87-
category: PropTypes.string,
88-
location: PropTypes.object,
89-
slides: PropTypes.arrayOf(SlideProps),
90-
};
91-
92-
export default Gallery;
94+
}

src/components/Header.js src/components/Header.tsx

+11-16
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
import '../styles/header.css';
22
import { Button, NavBar } from '@zigurous/react-components';
33
import { Link as GatsbyLink, navigate } from 'gatsby';
4-
import PropTypes from 'prop-types';
54
import React, { useState } from 'react';
65
import Logo from './Logo';
76
import MenuGallery from './MenuGallery';
87
import { headerLinks } from '../links';
98

10-
const Header = ({ location, pageTitle }) => {
9+
export interface HeaderProps {
10+
location?: Location;
11+
pageTitle?: string;
12+
}
13+
14+
export default function Header({ location, pageTitle }: HeaderProps) {
1115
const [isMenuOpen, setIsMenuOpen] = useState(false);
1216
return (
13-
<React.Fragment>
17+
<>
1418
<header className="header">
1519
<div className="header__container container-fluid">
1620
<Logo size={44} />
@@ -23,16 +27,14 @@ const Header = ({ location, pageTitle }) => {
2327
<Button
2428
className="header__title-button"
2529
onClick={() => {
26-
const link = headerLinks.find(
27-
(link) => link.name === pageTitle
28-
);
30+
const link = headerLinks.find(link => link.name === pageTitle);
2931
if (link) {
3032
navigate(link.to);
3133
} else {
3234
setIsMenuOpen(true);
3335
}
3436
}}
35-
style={Button.style.none}
37+
style="unstyled"
3638
>
3739
{pageTitle}
3840
</Button>
@@ -68,13 +70,6 @@ const Header = ({ location, pageTitle }) => {
6870
open={isMenuOpen}
6971
onRequestClose={() => setIsMenuOpen(false)}
7072
/>
71-
</React.Fragment>
73+
</>
7274
);
73-
};
74-
75-
Header.propType = {
76-
location: PropTypes.object,
77-
pageTitle: PropTypes.string,
78-
};
79-
80-
export default Header;
75+
}

0 commit comments

Comments
 (0)