diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..9a82166 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,29 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "Next.js: debug server-side", + "type": "node-terminal", + "request": "launch", + "command": "yarn dev" + }, + { + "name": "Next.js: debug client-side", + "type": "chrome", + "request": "launch", + "url": "http://localhost:3000" + }, + { + "name": "Next.js: debug full stack", + "type": "node-terminal", + "request": "launch", + "command": "yarn dev", + "serverReadyAction": { + "pattern": "started server on .+, url: (https?://.+)", + "uriFormat": "%s", + "action": "debugWithChrome" + } + } + ] + } + \ No newline at end of file diff --git a/components/ClientOnly.tsx b/components/ClientOnly.tsx new file mode 100644 index 0000000..8b41792 --- /dev/null +++ b/components/ClientOnly.tsx @@ -0,0 +1,21 @@ +import React, { FunctionComponent, useEffect, useState } from "react"; + +interface ClientOnlyProps { + children: React.ReactNode; +} + +const ClientOnly: FunctionComponent = ({ children, ...delegated }) => { + const [hasMounted, setHasMounted] = useState(false); + + useEffect(() => { + setHasMounted(true); + }, []); + + if (!hasMounted) { + return null; + } + + return
{children}
; +}; + +export default ClientOnly; \ No newline at end of file diff --git a/package.json b/package.json index 0dc16dd..a7fbc9a 100644 --- a/package.json +++ b/package.json @@ -12,12 +12,15 @@ "@apollo/client": "^3.7.3", "@chakra-ui/core": "^0.8.0", "@chakra-ui/react": "^2.4.3", + "@emotion/react": "^11", + "@emotion/styled": "^11", "@next/font": "13.0.7", "@types/node": "18.11.15", "@types/react": "18.0.26", "@types/react-dom": "18.0.9", "eslint": "8.29.0", "eslint-config-next": "13.0.7", + "framer-motion": "^6", "graphql": "^16.6.0", "next": "13.0.7", "react": "18.2.0", @@ -25,10 +28,7 @@ "typescript": "4.9.4" }, "devDependencies": { - "@emotion/react": "11.10.5", "@emotion/core": "10.x", - "@emotion/styled": "^10.x", - "emotion-theming": "^10.x", - "framer-motion": "^7.10.0" + "emotion-theming": "^10.x" } } diff --git a/pages/_app.tsx b/pages/_app.tsx index c055f25..7949e6b 100644 --- a/pages/_app.tsx +++ b/pages/_app.tsx @@ -1,6 +1,11 @@ -import '../styles/globals.css' import type { AppProps } from 'next/app' +import { ApolloProvider } from '@apollo/client' +import client from '../apollo-client' export default function App({ Component, pageProps }: AppProps) { - return + return ( + + + + ) } diff --git a/pages/client-side.tsx b/pages/client-side.tsx new file mode 100644 index 0000000..247f700 --- /dev/null +++ b/pages/client-side.tsx @@ -0,0 +1,10 @@ +import ClientOnly from "../components/ClientOnly"; +import Launches from "./launches"; + +export default function ClientSide() { + return ( + + + + ); +} \ No newline at end of file diff --git a/pages/home.tsx b/pages/home.tsx deleted file mode 100644 index 05f1ba9..0000000 --- a/pages/home.tsx +++ /dev/null @@ -1,22 +0,0 @@ -import { Flex, Heading, Text } from '@chakra-ui/core'; -import { Card, CardHeader, CardBody } from '@chakra-ui/react' -import { launch, launches } from '../types/launch'; - - -export default function Home(data: launches) { - return ( - - {data.launches.map((launch: launch) => ( - - - Mission: {launch.mission_name} - - - Launch site: {launch.launch_site.site_name} - Rocket type: {launch.rocket.rocket_type} - - - ))} - - ); -} \ No newline at end of file diff --git a/pages/index.ts b/pages/index.ts index a9426be..8965c6d 100644 --- a/pages/index.ts +++ b/pages/index.ts @@ -1,36 +1,17 @@ -import gql from 'graphql-tag'; import client from "../apollo-client"; -import { launches } from '../types/launch'; -import Home from './home'; +import ClientSide from "./client-side"; +import { query } from './launches'; -export async function getStaticProps() { - const query = gql` - { - launches { - id - launch_site { - site_id - site_name - } - rocket { - rocket_name - rocket_type - } - mission_name - } - } - `; - +export async function getServerSideProps(context: any) { const { data } = await client.query({ query }); - return { props: { - launches: data.launches, + launches: data, }, }; } -export default function HomePage(launches: launches) { - return Home(launches); +export default function HomePage() { + return ClientSide(); } \ No newline at end of file diff --git a/pages/launches.tsx b/pages/launches.tsx new file mode 100644 index 0000000..763a17e --- /dev/null +++ b/pages/launches.tsx @@ -0,0 +1,60 @@ +import { gql, useQuery } from '@apollo/client'; +import { Flex, Heading, Text } from '@chakra-ui/core'; +import { Card, CardHeader, CardBody, ChakraProvider, Image } from '@chakra-ui/react' +import launch from '../types/launch'; + +export const query = gql` +{ + launches { + id + launch_site { + site_id + site_name + } + rocket { + rocket_name + rocket_type + } + mission_name + links { + flickr_images + } + launch_year + launch_success + } +} + `; +export default function Launches() { + const { data, loading, error } = useQuery(query); + + if (loading) { + return

Loading...

; + } + + if (error) { + console.error(error); + return null; + } + + return ( + + SpaceX Launches + + {data?.launches?.map((launch: launch) => ( + + + Mission: {launch.mission_name.length >= 15 ? (launch.mission_name.slice(0,13) + '...') : launch.mission_name } + + + + Launch site: {launch.launch_site.site_name} + Rocket type: {launch.rocket.rocket_type} + Launch year: {launch.launch_year} + Was mission successfull? {launch.launch_success ? 'Yes' : 'No'} + + + ))} + + + ); +} \ No newline at end of file diff --git a/styles/globals.css b/styles/globals.css deleted file mode 100644 index 3a54ccd..0000000 --- a/styles/globals.css +++ /dev/null @@ -1,107 +0,0 @@ -:root { - --max-width: 1100px; - --border-radius: 12px; - --font-mono: ui-monospace, Menlo, Monaco, 'Cascadia Mono', 'Segoe UI Mono', - 'Roboto Mono', 'Oxygen Mono', 'Ubuntu Monospace', 'Source Code Pro', - 'Fira Mono', 'Droid Sans Mono', 'Courier New', monospace; - - --foreground-rgb: 0, 0, 0; - --background-start-rgb: 214, 219, 220; - --background-end-rgb: 255, 255, 255; - - --primary-glow: conic-gradient( - from 180deg at 50% 50%, - #16abff33 0deg, - #0885ff33 55deg, - #54d6ff33 120deg, - #0071ff33 160deg, - transparent 360deg - ); - --secondary-glow: radial-gradient( - rgba(255, 255, 255, 1), - rgba(255, 255, 255, 0) - ); - - --tile-start-rgb: 239, 245, 249; - --tile-end-rgb: 228, 232, 233; - --tile-border: conic-gradient( - #00000080, - #00000040, - #00000030, - #00000020, - #00000010, - #00000010, - #00000080 - ); - - --callout-rgb: 238, 240, 241; - --callout-border-rgb: 172, 175, 176; - --card-rgb: 180, 185, 188; - --card-border-rgb: 131, 134, 135; -} - -@media (prefers-color-scheme: dark) { - :root { - --foreground-rgb: 255, 255, 255; - --background-start-rgb: 0, 0, 0; - --background-end-rgb: 0, 0, 0; - - --primary-glow: radial-gradient(rgba(1, 65, 255, 0.4), rgba(1, 65, 255, 0)); - --secondary-glow: linear-gradient( - to bottom right, - rgba(1, 65, 255, 0), - rgba(1, 65, 255, 0), - rgba(1, 65, 255, 0.3) - ); - - --tile-start-rgb: 2, 13, 46; - --tile-end-rgb: 2, 5, 19; - --tile-border: conic-gradient( - #ffffff80, - #ffffff40, - #ffffff30, - #ffffff20, - #ffffff10, - #ffffff10, - #ffffff80 - ); - - --callout-rgb: 20, 20, 20; - --callout-border-rgb: 108, 108, 108; - --card-rgb: 100, 100, 100; - --card-border-rgb: 200, 200, 200; - } -} - -* { - box-sizing: border-box; - padding: 0; - margin: 0; -} - -html, -body { - max-width: 100vw; - overflow-x: hidden; -} - -body { - color: rbg(--foreground-rgb); - background: linear-gradient( - to bottom, - transparent, - rgb(var(--background-end-rgb)) - ) - rgb(var(--background-start-rgb)); -} - -a { - color: inherit; - text-decoration: none; -} - -@media (prefers-color-scheme: dark) { - html { - color-scheme: dark; - } -} diff --git a/types/launch.ts b/types/launch.ts index 219141d..eb92674 100644 --- a/types/launch.ts +++ b/types/launch.ts @@ -8,13 +8,17 @@ export interface rocket { rocket_type: string; }; -export interface launch { +export interface links { + flickr_images: string[] +} + +export default interface launch { id: number, mission_name: string, launch_site: launch_site, rocket: rocket, + links: links, + launch_year: string, + launch_success: string, }; -export interface launches { - launches: launch[]; -} \ No newline at end of file diff --git a/types/launches.ts b/types/launches.ts new file mode 100644 index 0000000..f00838d --- /dev/null +++ b/types/launches.ts @@ -0,0 +1,5 @@ +import launch from "./launch"; + +export default interface launches { + launches: launch[]; +}; \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index 5294f1e..9888ced 100644 --- a/yarn.lock +++ b/yarn.lock @@ -928,13 +928,20 @@ resolved "https://registry.yarnpkg.com/@emotion/hash/-/hash-0.9.0.tgz#c5153d50401ee3c027a57a177bc269b16d889cb7" integrity sha512-14FtKiHhy2QoPIzdTcvh//8OyBlknNs2nXRwIhG904opCby3l+9Xaf/wuPvICBF0rc1ZCNBd3nKe9cd2mecVkQ== -"@emotion/is-prop-valid@0.8.8", "@emotion/is-prop-valid@^0.8.1", "@emotion/is-prop-valid@^0.8.2": +"@emotion/is-prop-valid@^0.8.1", "@emotion/is-prop-valid@^0.8.2": version "0.8.8" resolved "https://registry.yarnpkg.com/@emotion/is-prop-valid/-/is-prop-valid-0.8.8.tgz#db28b1c4368a259b60a97311d6a952d4fd01ac1a" integrity sha512-u5WtneEAr5IDG2Wv65yhunPSMLIpuKsbuOktRojfrEiEvRyC85LgPMZI63cr7NUqT8ZIGdSVg8ZKGxIug4lXcA== dependencies: "@emotion/memoize" "0.7.4" +"@emotion/is-prop-valid@^1.2.0": + version "1.2.0" + resolved "https://registry.yarnpkg.com/@emotion/is-prop-valid/-/is-prop-valid-1.2.0.tgz#7f2d35c97891669f7e276eb71c83376a5dc44c83" + integrity sha512-3aDpDprjM0AwaxGE09bOPkNxHpBd+kA6jty3RnaEXdweX1DF1U3VQpPYb0g1IStAuK7SVQ1cy+bNBBKp4W3Fjg== + dependencies: + "@emotion/memoize" "^0.8.0" + "@emotion/memoize@0.7.4": version "0.7.4" resolved "https://registry.yarnpkg.com/@emotion/memoize/-/memoize-0.7.4.tgz#19bf0f5af19149111c40d98bb0cf82119f5d9eeb" @@ -950,7 +957,7 @@ resolved "https://registry.yarnpkg.com/@emotion/memoize/-/memoize-0.8.0.tgz#f580f9beb67176fa57aae70b08ed510e1b18980f" integrity sha512-G/YwXTkv7Den9mXDO7AhLWkE3q+I92B+VqAE+dYG4NGPaHZGvt3G8Q0p9vmE+sq7rTGphUbAvmQ9YpbfMQGGlA== -"@emotion/react@11.10.5": +"@emotion/react@^11": version "11.10.5" resolved "https://registry.yarnpkg.com/@emotion/react/-/react-11.10.5.tgz#95fff612a5de1efa9c0d535384d3cfa115fe175d" integrity sha512-TZs6235tCJ/7iF6/rvTaOH4oxQg2gMAcdHemjwLKIjKz4rRuYe1HJ2TQJKnAcRAfOUDdU8XoDadCe1rl72iv8A== @@ -996,23 +1003,17 @@ resolved "https://registry.yarnpkg.com/@emotion/sheet/-/sheet-1.2.1.tgz#0767e0305230e894897cadb6c8df2c51e61a6c2c" integrity sha512-zxRBwl93sHMsOj4zs+OslQKg/uhF38MB+OMKoCrVuS0nyTkqnau+BM3WGEoOptg9Oz45T/aIGs1qbVAsEFo3nA== -"@emotion/styled-base@^10.3.0": - version "10.3.0" - resolved "https://registry.yarnpkg.com/@emotion/styled-base/-/styled-base-10.3.0.tgz#9aa2c946100f78b47316e4bc6048321afa6d4e36" - integrity sha512-PBRqsVKR7QRNkmfH78hTSSwHWcwDpecH9W6heujWAcyp2wdz/64PP73s7fWS1dIPm8/Exc8JAzYS8dEWXjv60w== - dependencies: - "@babel/runtime" "^7.5.5" - "@emotion/is-prop-valid" "0.8.8" - "@emotion/serialize" "^0.11.15" - "@emotion/utils" "0.11.3" - -"@emotion/styled@^10.x": - version "10.3.0" - resolved "https://registry.yarnpkg.com/@emotion/styled/-/styled-10.3.0.tgz#8ee959bf75730789abb5f67f7c3ded0c30aec876" - integrity sha512-GgcUpXBBEU5ido+/p/mCT2/Xx+Oqmp9JzQRuC+a4lYM4i4LBBn/dWvc0rQ19N9ObA8/T4NWMrPNe79kMBDJqoQ== +"@emotion/styled@^11": + version "11.10.5" + resolved "https://registry.yarnpkg.com/@emotion/styled/-/styled-11.10.5.tgz#1fe7bf941b0909802cb826457e362444e7e96a79" + integrity sha512-8EP6dD7dMkdku2foLoruPCNkRevzdcBaY6q0l0OsbyJK+x8D9HWjX27ARiSIKNF634hY9Zdoedh8bJCiva8yZw== dependencies: - "@emotion/styled-base" "^10.3.0" - babel-plugin-emotion "^10.0.27" + "@babel/runtime" "^7.18.3" + "@emotion/babel-plugin" "^11.10.5" + "@emotion/is-prop-valid" "^1.2.0" + "@emotion/serialize" "^1.1.1" + "@emotion/use-insertion-effect-with-fallbacks" "^1.0.0" + "@emotion/utils" "^1.2.0" "@emotion/stylis@0.8.5": version "0.8.5" @@ -1093,7 +1094,7 @@ resolved "https://registry.yarnpkg.com/@humanwhocodes/object-schema/-/object-schema-1.2.1.tgz#b520529ec21d8e5945a1851dfd1c32e94e39ff45" integrity sha512-ZnQMnLV4e7hDlUvw8H+U8ASL02SS2Gn6+9Ac3wGGLIe7+je2AeAOxPY+izIPJDfFDb7eDjev0Us8MO1iFRN8hA== -"@motionone/animation@^10.15.1": +"@motionone/animation@^10.12.0": version "10.15.1" resolved "https://registry.yarnpkg.com/@motionone/animation/-/animation-10.15.1.tgz#4a85596c31cbc5100ae8eb8b34c459fb0ccf6807" integrity sha512-mZcJxLjHor+bhcPuIFErMDNyrdb2vJur8lSfMCsuCB4UyV8ILZLvK+t+pg56erv8ud9xQGK/1OGPt10agPrCyQ== @@ -1103,15 +1104,15 @@ "@motionone/utils" "^10.15.1" tslib "^2.3.1" -"@motionone/dom@^10.15.3": - version "10.15.3" - resolved "https://registry.yarnpkg.com/@motionone/dom/-/dom-10.15.3.tgz#afb27270032368a917f1ae8dd87e0069a6a9fe40" - integrity sha512-FQ7a2zMBXc1UeU8CG9G3yDpst55fbb0+C9A0VGfwOITitBCzigKZnXRgsRSWWR+FW57GSc13eGQxtYB0lKG0Ng== +"@motionone/dom@10.12.0": + version "10.12.0" + resolved "https://registry.yarnpkg.com/@motionone/dom/-/dom-10.12.0.tgz#ae30827fd53219efca4e1150a5ff2165c28351ed" + integrity sha512-UdPTtLMAktHiqV0atOczNYyDd/d8Cf5fFsd1tua03PqTwwCe/6lwhLSQ8a7TbnQ5SN0gm44N1slBfj+ORIhrqw== dependencies: - "@motionone/animation" "^10.15.1" - "@motionone/generators" "^10.15.1" - "@motionone/types" "^10.15.1" - "@motionone/utils" "^10.15.1" + "@motionone/animation" "^10.12.0" + "@motionone/generators" "^10.12.0" + "@motionone/types" "^10.12.0" + "@motionone/utils" "^10.12.0" hey-listen "^1.0.8" tslib "^2.3.1" @@ -1123,7 +1124,7 @@ "@motionone/utils" "^10.15.1" tslib "^2.3.1" -"@motionone/generators@^10.15.1": +"@motionone/generators@^10.12.0": version "10.15.1" resolved "https://registry.yarnpkg.com/@motionone/generators/-/generators-10.15.1.tgz#dc6abb11139d1bafe758a41c134d4c753a9b871c" integrity sha512-67HLsvHJbw6cIbLA/o+gsm7h+6D4Sn7AUrB/GPxvujse1cGZ38F5H7DzoH7PhX+sjvtDnt2IhFYF2Zp1QTMKWQ== @@ -1132,12 +1133,12 @@ "@motionone/utils" "^10.15.1" tslib "^2.3.1" -"@motionone/types@^10.15.1": +"@motionone/types@^10.12.0", "@motionone/types@^10.15.1": version "10.15.1" resolved "https://registry.yarnpkg.com/@motionone/types/-/types-10.15.1.tgz#89441b54285012795cbba8612cbaa0fa420db3eb" integrity sha512-iIUd/EgUsRZGrvW0jqdst8st7zKTzS9EsKkP+6c6n4MPZoQHwiHuVtTQLD6Kp0bsBLhNzKIBlHXponn/SDT4hA== -"@motionone/utils@^10.15.1": +"@motionone/utils@^10.12.0", "@motionone/utils@^10.15.1": version "10.15.1" resolved "https://registry.yarnpkg.com/@motionone/utils/-/utils-10.15.1.tgz#6b5f51bde75be88b5411e084310299050368a438" integrity sha512-p0YncgU+iklvYr/Dq4NobTRdAPv9PveRDUXabPEeOjBLSO/1FNB2phNTZxOxpi1/GZwYpAoECEa0Wam+nsmhSw== @@ -2374,14 +2375,17 @@ focus-lock@^0.11.2: dependencies: tslib "^2.0.3" -framer-motion@^7.10.0: - version "7.10.0" - resolved "https://registry.yarnpkg.com/framer-motion/-/framer-motion-7.10.0.tgz#500c44f064aa26904abc3a1a683afc1311b7cec9" - integrity sha512-HZUl5hFIO23XuhxhGaWSVXaElYv0Wlk3iYXeqNmp1WF1JvD1vQMvuH3OE7Q5PsFX+a5+FrWRam7a4S7xDigEag== +framer-motion@^6: + version "6.5.1" + resolved "https://registry.yarnpkg.com/framer-motion/-/framer-motion-6.5.1.tgz#802448a16a6eb764124bf36d8cbdfa6dd6b931a7" + integrity sha512-o1BGqqposwi7cgDrtg0dNONhkmPsUFDaLcKXigzuTFC5x58mE8iyTazxSudFzmT6MEyJKfjjU8ItoMe3W+3fiw== dependencies: - "@motionone/dom" "^10.15.3" + "@motionone/dom" "10.12.0" + framesync "6.0.1" hey-listen "^1.0.8" - tslib "2.4.0" + popmotion "11.0.3" + style-value-types "5.0.0" + tslib "^2.1.0" optionalDependencies: "@emotion/is-prop-valid" "^0.8.2" @@ -2392,6 +2396,13 @@ framesync@5.3.0: dependencies: tslib "^2.1.0" +framesync@6.0.1: + version "6.0.1" + resolved "https://registry.yarnpkg.com/framesync/-/framesync-6.0.1.tgz#5e32fc01f1c42b39c654c35b16440e07a25d6f20" + integrity sha512-fUY88kXvGiIItgNC7wcTOl0SNRCVXMKSWW2Yzfmn7EKNc+MpCzcz9DhdHcdjbrtN3c6R4H5dTY2jiCpPdysEjA== + dependencies: + tslib "^2.1.0" + fs.realpath@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f" @@ -3122,6 +3133,16 @@ picomatch@^2.3.1: resolved "https://registry.yarnpkg.com/picomatch/-/picomatch-2.3.1.tgz#3ba3833733646d9d3e4995946c1365a67fb07a42" integrity sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA== +popmotion@11.0.3: + version "11.0.3" + resolved "https://registry.yarnpkg.com/popmotion/-/popmotion-11.0.3.tgz#565c5f6590bbcddab7a33a074bb2ba97e24b0cc9" + integrity sha512-Y55FLdj3UxkR7Vl3s7Qr4e9m0onSnP8W7d/xQLsoJM40vs6UKHFdygs6SWryasTZYqugMjm3BepCF4CWXDiHgA== + dependencies: + framesync "6.0.1" + hey-listen "^1.0.8" + style-value-types "5.0.0" + tslib "^2.1.0" + popper.js@^1.15.0: version "1.16.1" resolved "https://registry.yarnpkg.com/popper.js/-/popper.js-1.16.1.tgz#2a223cb3dc7b6213d740e40372be40de43e65b1b" @@ -3439,6 +3460,14 @@ strip-json-comments@^3.1.0, strip-json-comments@^3.1.1: resolved "https://registry.yarnpkg.com/strip-json-comments/-/strip-json-comments-3.1.1.tgz#31f1281b3832630434831c310c01cccda8cbe006" integrity sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig== +style-value-types@5.0.0: + version "5.0.0" + resolved "https://registry.yarnpkg.com/style-value-types/-/style-value-types-5.0.0.tgz#76c35f0e579843d523187989da866729411fc8ad" + integrity sha512-08yq36Ikn4kx4YU6RD7jWEv27v4V+PUsOGa4n/as8Et3CuODMJQ00ENeAVXAeydX4Z2j1XHZF1K2sX4mGl18fA== + dependencies: + hey-listen "^1.0.8" + tslib "^2.1.0" + styled-jsx@5.1.0: version "5.1.0" resolved "https://registry.yarnpkg.com/styled-jsx/-/styled-jsx-5.1.0.tgz#4a5622ab9714bd3fcfaeec292aa555871f057563" @@ -3568,11 +3597,6 @@ tsconfig-paths@^3.14.1: minimist "^1.2.6" strip-bom "^3.0.0" -tslib@2.4.0: - version "2.4.0" - resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.4.0.tgz#7cecaa7f073ce680a05847aa77be941098f36dc3" - integrity sha512-d6xOpEDfsi2CZVlPQzGeux8XMwLT9hssAsaPYExaQMuYskwb+x1x7J371tWlbBdWHroy99KnVB6qIkUbs5X3UQ== - tslib@^1.11.2, tslib@^1.8.1: version "1.14.1" resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.14.1.tgz#cf2d38bdc34a134bcaf1091c41f6619e2f672d00"