Skip to content

Commit a4e4060

Browse files
committed
initial commit
1 parent cd30aac commit a4e4060

File tree

17 files changed

+10746
-86
lines changed

17 files changed

+10746
-86
lines changed

.prettierrc

Whitespace-only changes.

__generated__/globalTypes.ts

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apollo.config.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module.exports = {
2+
client: {
3+
service: {
4+
name: "SpaceX API",
5+
url: "https://api.spacex.land/graphql",
6+
},
7+
},
8+
};

package.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"version": "0.1.0",
44
"private": true,
55
"dependencies": {
6+
"@apollo/client": "^3.5.6",
67
"@testing-library/jest-dom": "^5.16.1",
78
"@testing-library/react": "^12.1.2",
89
"@testing-library/user-event": "^13.5.0",
@@ -12,11 +13,14 @@
1213
"@types/react-dom": "^17.0.11",
1314
"react": "^17.0.2",
1415
"react-dom": "^17.0.2",
16+
"react-loading-skeleton": "^3.0.2",
1517
"react-scripts": "5.0.0",
1618
"typescript": "^4.5.4",
1719
"web-vitals": "^2.1.3"
1820
},
1921
"scripts": {
22+
"gen:types": "npx apollo client:codegen --target typescript --includes **/*.graphql.ts --excludes **/__generated__",
23+
"prestart": "yarn gen:types",
2024
"start": "react-scripts start",
2125
"build": "react-scripts build",
2226
"test": "react-scripts test",
@@ -39,5 +43,11 @@
3943
"last 1 firefox version",
4044
"last 1 safari version"
4145
]
46+
},
47+
"devDependencies": {
48+
"apollo": "^2.33.9",
49+
"autoprefixer": "^10.4.2",
50+
"postcss": "^8.4.5",
51+
"tailwindcss": "^3.0.12"
4252
}
4353
}

postcss.config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = {
2+
plugins: {
3+
tailwindcss: {},
4+
autoprefixer: {},
5+
},
6+
}

src/App.css

Lines changed: 0 additions & 38 deletions
This file was deleted.

src/App.test.tsx

Lines changed: 0 additions & 9 deletions
This file was deleted.

src/App.tsx

Lines changed: 51 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,57 @@
1-
import React from 'react';
2-
import logo from './logo.svg';
3-
import './App.css';
1+
import { useQuery } from "@apollo/client";
2+
import Skeleton from "react-loading-skeleton";
3+
import { LaunchCard } from "./components/LaunchCard";
4+
import { GET_LAUNCHES } from "./graphql/queries.graphql";
5+
import {
6+
GetLaunches,
7+
GetLaunchesVariables,
8+
} from "./graphql/__generated__/GetLaunches";
49

510
function App() {
11+
const { data, loading } = useQuery<GetLaunches, GetLaunchesVariables>(
12+
GET_LAUNCHES,
13+
{
14+
variables: {
15+
limit: 10,
16+
},
17+
}
18+
);
19+
20+
function renderLoader() {
21+
if (loading && !data) {
22+
return (
23+
<div>
24+
<Skeleton height={50} />
25+
<Skeleton height={50} />
26+
<Skeleton height={50} />
27+
<Skeleton height={50} />
28+
<Skeleton height={50} />
29+
<Skeleton height={50} />
30+
<Skeleton height={50} />
31+
</div>
32+
);
33+
}
34+
}
35+
636
return (
7-
<div className="App">
8-
<header className="App-header">
9-
<img src={logo} className="App-logo" alt="logo" />
10-
<p>
11-
Edit <code>src/App.tsx</code> and save to reload.
12-
</p>
13-
<a
14-
className="App-link"
15-
href="https://reactjs.org"
16-
target="_blank"
17-
rel="noopener noreferrer"
18-
>
19-
Learn React
20-
</a>
21-
</header>
37+
<div className="min-h-screen bg-gray-900 text-white pt-40">
38+
<h1 className="text-4xl font-bold text-center mb-10">SpaceX Launches</h1>
39+
<div
40+
className="max-w-screen-sm mx-auto bg-gray-100 shadow-md rounded-md p-5 overflow-auto"
41+
style={{ maxHeight: 600 }}
42+
>
43+
{renderLoader()}
44+
{data?.launches?.map((launch) => {
45+
return (
46+
<LaunchCard
47+
key={Number(launch?.id)}
48+
id={Number(launch?.id)}
49+
missionName={launch?.mission_name!}
50+
details={launch?.details!}
51+
/>
52+
);
53+
})}
54+
</div>
2255
</div>
2356
);
2457
}

src/components/LaunchCard.tsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import React from "react";
2+
3+
type LaunchCardProps = {
4+
id: number;
5+
missionName?: string;
6+
details?: string;
7+
};
8+
export const LaunchCard: React.FC<LaunchCardProps> = (props) => {
9+
return (
10+
<div
11+
className="bg-white p-4 rounded-md shadow text-gray-900 mb-4"
12+
key={props.id}
13+
>
14+
<div className="text-base font-medium text-gray-900">
15+
{props.missionName}
16+
</div>
17+
<p className="text-gray-600 text-xs font-light">{props.details}</p>
18+
</div>
19+
);
20+
};

src/graphql.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import {
2+
HttpLink,
3+
ApolloClient,
4+
InMemoryCache,
5+
NormalizedCacheObject,
6+
} from "@apollo/client";
7+
8+
const httpLink = new HttpLink({
9+
uri: "https://api.spacex.land/graphql",
10+
});
11+
12+
export const client: ApolloClient<NormalizedCacheObject> = new ApolloClient({
13+
link: httpLink,
14+
cache: new InMemoryCache({
15+
addTypename: false,
16+
}),
17+
});

0 commit comments

Comments
 (0)