├── .gitignore ├── README.md ├── package.json ├── public ├── favicon.ico ├── index.html ├── logo192.png ├── logo512.png ├── manifest.json └── robots.txt ├── src ├── App.css ├── App.test.tsx ├── App.tsx ├── index.css ├── index.tsx ├── logo.svg ├── news.ts ├── react-app-env.d.ts ├── serviceWorker.ts └── setupTests.ts ├── tsconfig.json └── yarn.lock /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # production 12 | /build 13 | 14 | # misc 15 | .DS_Store 16 | .env.local 17 | .env.development.local 18 | .env.test.local 19 | .env.production.local 20 | 21 | npm-debug.log* 22 | yarn-debug.log* 23 | yarn-error.log* 24 | 25 | #amplify 26 | amplify/\#current-cloud-backend 27 | amplify/.config/local-* 28 | amplify/mock-data 29 | amplify/backend/amplify-meta.json 30 | amplify/backend/awscloudformation 31 | build/ 32 | dist/ 33 | node_modules/ 34 | aws-exports.js 35 | awsconfiguration.json 36 | amplifyconfiguration.json 37 | amplify-build-config.json 38 | amplify-gradle-config.json 39 | amplifytools.xcconfig -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## TypeSafe Fullstack React 2 | 3 | [**See the full writeup on Dev.to here**](https://dev.to/swyx/typesafe-fullstack-react-graphql-with-aws-amplify-b3a)! 4 | 5 | ### A React + TypeScript + GraphQL + AWS CMS demo 6 | 7 | ![image](https://user-images.githubusercontent.com/6764957/93261590-7c13f980-f7d5-11ea-9fda-b482ac1abdac.png) 8 | 9 | This is a basic CMS with React and TypeScript and you can add an AWS backend easily with GraphQL. 10 | 11 | We also use [Chakra UI v1.0](https://next.chakra-ui.com/) for styling our components because it is awesome. 12 | 13 | I will update this with more info from the talk in future, pls [remind me](https://twitter.com/swyx) if i forget. 14 | 15 | - Deployed version: https://dev.dwr9z9k8p3l6k.amplifyapp.com 16 | - Dev.to writeup: https://dev.to/swyx/typesafe-fullstack-react-graphql-with-aws-amplify-b3a 17 | - Slides: https://docs.google.com/presentation/d/138jJpHxQKmpzuBK7C-kOv31G5CTfSYSkd2qCEMPL-8c/edit?usp=sharing 18 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "my-app", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@chakra-ui/core": "^1.0.0-rc.3", 7 | "@testing-library/jest-dom": "^4.2.4", 8 | "@testing-library/react": "^9.3.2", 9 | "@testing-library/user-event": "^7.1.2", 10 | "@types/jest": "^24.0.0", 11 | "@types/node": "^12.0.0", 12 | "@types/react": "^16.9.0", 13 | "@types/react-dom": "^16.9.0", 14 | "formik": "^2.1.5", 15 | "react": "^16.13.1", 16 | "react-dom": "^16.13.1", 17 | "react-scripts": "3.4.3", 18 | "typescript": "^4.0.2" 19 | }, 20 | "scripts": { 21 | "start": "react-scripts start", 22 | "build": "react-scripts build", 23 | "test": "react-scripts test", 24 | "eject": "react-scripts eject" 25 | }, 26 | "eslintConfig": { 27 | "extends": "react-app" 28 | }, 29 | "browserslist": { 30 | "production": [ 31 | ">0.2%", 32 | "not dead", 33 | "not op_mini all" 34 | ], 35 | "development": [ 36 | "last 1 chrome version", 37 | "last 1 firefox version", 38 | "last 1 safari version" 39 | ] 40 | }, 41 | "devDependencies": { 42 | "aws-amplify": "^3.3.0" 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swyxio/talk-typesafe-fullstack-react-demo-cms/b368c212fcd129aae27c23d77b2de41b23869ac8/public/favicon.ico -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 17 | 18 | 27 | React App 28 | 34 | 35 | 36 | 37 |
38 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swyxio/talk-typesafe-fullstack-react-demo-cms/b368c212fcd129aae27c23d77b2de41b23869ac8/public/logo192.png -------------------------------------------------------------------------------- /public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swyxio/talk-typesafe-fullstack-react-demo-cms/b368c212fcd129aae27c23d77b2de41b23869ac8/public/logo512.png -------------------------------------------------------------------------------- /public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | }, 10 | { 11 | "src": "logo192.png", 12 | "type": "image/png", 13 | "sizes": "192x192" 14 | }, 15 | { 16 | "src": "logo512.png", 17 | "type": "image/png", 18 | "sizes": "512x512" 19 | } 20 | ], 21 | "start_url": ".", 22 | "display": "standalone", 23 | "theme_color": "#000000", 24 | "background_color": "#ffffff" 25 | } 26 | -------------------------------------------------------------------------------- /public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /src/App.css: -------------------------------------------------------------------------------- 1 | .App { 2 | text-align: center; 3 | } 4 | 5 | .App-logo { 6 | height: 40vmin; 7 | pointer-events: none; 8 | } 9 | 10 | @media (prefers-reduced-motion: no-preference) { 11 | .App-logo { 12 | animation: App-logo-spin infinite 20s linear; 13 | } 14 | } 15 | 16 | .App-header { 17 | background-color: #282c34; 18 | min-height: 100vh; 19 | display: flex; 20 | flex-direction: column; 21 | align-items: center; 22 | justify-content: center; 23 | font-size: calc(10px + 2vmin); 24 | color: white; 25 | } 26 | 27 | .App-link { 28 | color: #61dafb; 29 | } 30 | 31 | @keyframes App-logo-spin { 32 | from { 33 | transform: rotate(0deg); 34 | } 35 | to { 36 | transform: rotate(360deg); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/App.test.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { render } from '@testing-library/react'; 3 | import App from './App'; 4 | 5 | test('renders learn react link', () => { 6 | const { getByText } = render(); 7 | const linkElement = getByText(/learn react/i); 8 | expect(linkElement).toBeInTheDocument(); 9 | }); 10 | -------------------------------------------------------------------------------- /src/App.tsx: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import { 3 | Stack, 4 | Flex, 5 | Button, 6 | FormControl, 7 | FormLabel, 8 | Input, 9 | FormErrorMessage, 10 | Box, 11 | Text, 12 | Link, 13 | Grid, 14 | Image, 15 | Container, 16 | Textarea, 17 | Heading, 18 | } from "@chakra-ui/core"; 19 | 20 | import { Formik, Form, Field } from "formik"; 21 | import { news } from "./news"; 22 | 23 | type Blog = { 24 | title: string; 25 | image: string; 26 | body: string; 27 | id?: string; 28 | createdAt?: Date; 29 | updatedAt?: Date; 30 | }; 31 | 32 | function App() { 33 | const [blogs, setBlogs] = React.useState([]); 34 | const [currentSelectedBlog, setCurrentSelectedBlog] = React.useState(); 35 | async function addBlog(values: Blog) { 36 | const timestamp = new Date(); 37 | const newBlog: Blog = { 38 | ...values, 39 | id: uuidv4(), 40 | createdAt: timestamp, 41 | updatedAt: timestamp, 42 | }; 43 | setBlogs([...blogs, newBlog]); 44 | } 45 | function _updateBlog(oldValues: Blog) { 46 | return async function (newValues: Blog) { 47 | const timestamp = new Date(); 48 | const newBlog: Blog = { 49 | ...newValues, 50 | createdAt: oldValues.createdAt, 51 | updatedAt: timestamp, 52 | }; 53 | setBlogs([...blogs.filter((x) => x.id !== oldValues.id), newBlog]); 54 | }; 55 | } 56 | return ( 57 | 58 | 59 | 60 | React + TypeScript + GraphQL + AWS CMS 61 | 62 | 70 | https://git.io/JUBZX 71 | 72 | 73 | 74 | 82 | {blogs.length > 0 && ( 83 | 91 | {blogs.map((blog, key) => { 92 | return ( 93 | 103 | ); 104 | })} 105 | 106 | )} 107 | 108 | 109 | ); 110 | } 111 | 112 | function BlogLine({ 113 | blog, 114 | selected, 115 | setCurrentSelectedBlog, 116 | }: { 117 | blog: Blog; 118 | selected: boolean; 119 | setCurrentSelectedBlog: (blog: Blog) => void; 120 | }) { 121 | return ( 122 | <> 123 | {/* */} 124 | some blog image 133 | {/* */} 134 | setCurrentSelectedBlog(blog)} 138 | backgroundColor={selected ? "rgba(150,150,250, 0.1)" : undefined} 139 | > 140 | 147 | {String(blog.updatedAt?.toDateString())} 148 | 149 | 156 | {String(blog.title)} 157 | 158 | 159 | {String(blog.body.slice(0, 90))}... 160 | 161 | 162 | 163 | ); 164 | } 165 | 166 | function Editor(props: { 167 | initVals?: Blog; 168 | onSubmit: (values: any) => Promise; 169 | setCurrentSelectedBlog: (blog?: Blog) => void; 170 | }) { 171 | const initVals = props.initVals || ({} as Blog); 172 | return ( 173 | 182 | 183 | initialValues={initVals} 184 | onSubmit={(values, actions) => { 185 | props.onSubmit(values).then(() => { 186 | actions.setSubmitting(false); 187 | actions.resetForm({ 188 | values: { 189 | title: "", 190 | image: "", 191 | body: "", 192 | }, 193 | }); 194 | }); 195 | }} 196 | > 197 | {(_props) => ( 198 |
199 | x.length < 1 && "needs a title"} 202 | > 203 | {({ field, form }: any) => ( 204 | 207 | Title 208 | 215 | {form.errors.name} 216 | 217 | )} 218 | 219 | x.length < 1 && "needs a image"} 222 | > 223 | {({ field, form }: any) => ( 224 | 227 | Image 228 | 235 | {form.errors.name} 236 | 237 | )} 238 | 239 | e.length < 1 && "needs a body"} 242 | > 243 | {({ field, form }: any) => ( 244 | 245 | 246 | Body 247 | 248 |