Skip to content

Commit 335e1fa

Browse files
committed
refactor(Projects): port to typescript
1 parent f8d5ad8 commit 335e1fa

File tree

2 files changed

+29
-14
lines changed

2 files changed

+29
-14
lines changed

lib/index.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,6 @@ type PersonNode =
1717
| Queries.PeopleTplQuery["overlords"]["edges"][0]["node"]
1818
| Queries.PeopleTplQuery["members"]["edges"][0]["node"]
1919
| Queries.PeopleTplQuery["accomplices"]["edges"][0]["node"];
20+
21+
type ProjectList = Queries.ProjectsTplQuery["projects"]["edges"];
22+
type ProjectNode = ProjectList[0]["node"];

lib/ui/templates/ofHome/Projects.js renamed to lib/ui/templates/ofHome/Projects.tsx

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import { array, string } from "prop-types";
21
import { Link } from "gatsby";
3-
import { GatsbyImage } from "gatsby-plugin-image";
2+
import { GatsbyImage, type IGatsbyImageData } from "gatsby-plugin-image";
43
import React from "react";
54
import styled from "styled-components";
65

@@ -36,7 +35,12 @@ const Item = styled.li`
3635
}
3736
}
3837
`;
39-
const ItemImage = styled.div`
38+
39+
interface ItemImageProps {
40+
readonly $hasPlaceholder: boolean;
41+
}
42+
43+
const ItemImage = styled.div<ItemImageProps>`
4044
${setSpace("mbm")};
4145
border: 2px solid ${({ theme }) => theme.actionColor};
4246
position: relative;
@@ -83,7 +87,14 @@ const ItemText = styled.p`
8387
${setSpace("mts")};
8488
`;
8589

86-
function Projects(props) {
90+
interface ProjectsProps {
91+
placeholder: IGatsbyImageData;
92+
projects: ProjectList;
93+
subtitle: string;
94+
title: string;
95+
}
96+
97+
function Projects(props: ProjectsProps) {
8798
const { projects, title, subtitle } = props;
8899
return (
89100
<Element as="section">
@@ -95,15 +106,22 @@ function Projects(props) {
95106
<Items>
96107
{projects.map(({ node }) => {
97108
const project = node.frontmatter;
109+
110+
if (project === null) {
111+
return null;
112+
}
113+
98114
return (
99115
<Item key={node.id}>
100116
<Tile as={Link} to={`/projects/${project.uid}`}>
101117
<ItemImage $hasPlaceholder={!project.cover}>
102118
<GatsbyImage
103-
image={project.cover
104-
? project.cover.childImageSharp.gatsbyImageData
105-
: props.placeholder}
106-
alt={project.title}
119+
image={
120+
project.cover?.childImageSharp?.gatsbyImageData
121+
? project.cover.childImageSharp.gatsbyImageData
122+
: props.placeholder
123+
}
124+
alt={project.title ?? ""}
107125
/>
108126
{!project.cover ? (
109127
<span className="thinking">
@@ -128,10 +146,4 @@ function Projects(props) {
128146
);
129147
}
130148

131-
Projects.propTypes = {
132-
projects: array.isRequired,
133-
subtitle: string.isRequired,
134-
title: string.isRequired
135-
};
136-
137149
export default Projects;

0 commit comments

Comments
 (0)