├── src ├── App.css ├── app │ └── store.js ├── features │ └── counter │ │ ├── counterAPI.js │ │ ├── counterSlice.spec.js │ │ ├── Counter.module.css │ │ ├── Counter.js │ │ └── counterSlice.js ├── Templates.css ├── index.css ├── index.js ├── Sidebar.css ├── Templates.js ├── Banner.css ├── Header.css ├── App.js ├── serviceWorker.js ├── Sidebar.js ├── Header.js └── Banner.js ├── .firebaserc ├── public ├── robots.txt ├── favicon.ico ├── logo192.png ├── logo512.png ├── manifest.json └── index.html ├── firebase.json ├── .gitignore ├── package.json ├── .firebase └── hosting.YnVpbGQ.cache └── README.md /src/App.css: -------------------------------------------------------------------------------- 1 | main { 2 | padding: 100px 0px 0px 275px; 3 | } 4 | -------------------------------------------------------------------------------- /.firebaserc: -------------------------------------------------------------------------------- 1 | { 2 | "projects": { 3 | "default": "canva-demo" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nicklamb7/canva-clone/HEAD/public/favicon.ico -------------------------------------------------------------------------------- /public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nicklamb7/canva-clone/HEAD/public/logo192.png -------------------------------------------------------------------------------- /public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nicklamb7/canva-clone/HEAD/public/logo512.png -------------------------------------------------------------------------------- /src/app/store.js: -------------------------------------------------------------------------------- 1 | import { configureStore } from '@reduxjs/toolkit'; 2 | import counterReducer from '../features/counter/counterSlice'; 3 | 4 | export const store = configureStore({ 5 | reducer: { 6 | counter: counterReducer, 7 | }, 8 | }); 9 | -------------------------------------------------------------------------------- /src/features/counter/counterAPI.js: -------------------------------------------------------------------------------- 1 | // A mock function to mimic making an async request for data 2 | export function fetchCount(amount = 1) { 3 | return new Promise((resolve) => 4 | setTimeout(() => resolve({ data: amount }), 500) 5 | ); 6 | } 7 | -------------------------------------------------------------------------------- /firebase.json: -------------------------------------------------------------------------------- 1 | { 2 | "hosting": { 3 | "public": "build", 4 | "ignore": [ 5 | "firebase.json", 6 | "**/.*", 7 | "**/node_modules/**" 8 | ], 9 | "rewrites": [ 10 | { 11 | "source": "**", 12 | "destination": "/index.html" 13 | } 14 | ] 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /.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 | -------------------------------------------------------------------------------- /src/Templates.css: -------------------------------------------------------------------------------- 1 | .template { 2 | display: flex; 3 | justify-content: flex-start; 4 | align-items: center; 5 | } 6 | 7 | .templates h1 { 8 | font-size: 24px; 9 | } 10 | 11 | .templates ul { 12 | display: flex; 13 | justify-content: space-between; 14 | align-items: center; 15 | padding: 0px; 16 | } 17 | 18 | .template img { 19 | width: 210px; 20 | margin: 24px 24px 48px 0px; 21 | border-radius: 4px; 22 | overflow: hidden; 23 | } 24 | -------------------------------------------------------------------------------- /src/index.css: -------------------------------------------------------------------------------- 1 | * { 2 | margin: 0px; 3 | } 4 | 5 | body { 6 | margin: 0; 7 | font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 8 | 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', 9 | sans-serif; 10 | -webkit-font-smoothing: antialiased; 11 | -moz-osx-font-smoothing: grayscale; 12 | } 13 | 14 | code { 15 | font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', 16 | monospace; 17 | } 18 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import './index.css'; 4 | import App from './App'; 5 | import { store } from './app/store'; 6 | import { Provider } from 'react-redux'; 7 | import * as serviceWorker from './serviceWorker'; 8 | 9 | ReactDOM.render( 10 | 11 | 12 | 13 | 14 | , 15 | document.getElementById('root') 16 | ); 17 | 18 | // If you want your app to work offline and load faster, you can change 19 | // unregister() to register() below. Note this comes with some pitfalls. 20 | // Learn more about service workers: https://bit.ly/CRA-PWA 21 | serviceWorker.unregister(); 22 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "canva-clone", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@reduxjs/toolkit": "^1.5.1", 7 | "@testing-library/jest-dom": "^4.2.4", 8 | "@testing-library/react": "^9.3.2", 9 | "@testing-library/user-event": "^7.1.2", 10 | "react": "^17.0.2", 11 | "react-dom": "^17.0.2", 12 | "react-redux": "^7.2.3", 13 | "react-scripts": "4.0.3" 14 | }, 15 | "scripts": { 16 | "start": "react-scripts start", 17 | "build": "react-scripts build", 18 | "test": "react-scripts test", 19 | "eject": "react-scripts eject" 20 | }, 21 | "eslintConfig": { 22 | "extends": "react-app" 23 | }, 24 | "browserslist": { 25 | "production": [ 26 | ">0.2%", 27 | "not dead", 28 | "not op_mini all" 29 | ], 30 | "development": [ 31 | "last 1 chrome version", 32 | "last 1 firefox version", 33 | "last 1 safari version" 34 | ] 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/features/counter/counterSlice.spec.js: -------------------------------------------------------------------------------- 1 | import counterReducer, { 2 | increment, 3 | decrement, 4 | incrementByAmount, 5 | } from './counterSlice'; 6 | 7 | describe('counter reducer', () => { 8 | const initialState = { 9 | value: 3, 10 | status: 'idle', 11 | }; 12 | it('should handle initial state', () => { 13 | expect(counterReducer(undefined, { type: 'unknown' })).toEqual({ 14 | value: 0, 15 | status: 'idle', 16 | }); 17 | }); 18 | 19 | it('should handle increment', () => { 20 | const actual = counterReducer(initialState, increment()); 21 | expect(actual.value).toEqual(4); 22 | }); 23 | 24 | it('should handle decrement', () => { 25 | const actual = counterReducer(initialState, decrement()); 26 | expect(actual.value).toEqual(2); 27 | }); 28 | 29 | it('should handle incrementByAmount', () => { 30 | const actual = counterReducer(initialState, incrementByAmount(2)); 31 | expect(actual.value).toEqual(5); 32 | }); 33 | }); 34 | -------------------------------------------------------------------------------- /src/Sidebar.css: -------------------------------------------------------------------------------- 1 | .sidebar { 2 | padding-top: 100px; 3 | display: flex; 4 | flex-direction: column; 5 | width: 260px; 6 | height: 100vh; 7 | position: fixed; 8 | top: 0; 9 | background-color: white; 10 | margin-left: 12px; 11 | } 12 | 13 | .sidebar button { 14 | background-color: white; 15 | border: none; 16 | text-align: left; 17 | height: 40px; 18 | width: 244px; 19 | font-size: 14px; 20 | margin: 4px; 21 | border-radius: 4px; 22 | display: flex; 23 | align-items: center; 24 | justify-content: flex-start; 25 | } 26 | 27 | .sidebar button:hover { 28 | background-color: rgba(64,87,109,.07);; 29 | } 30 | 31 | .sidebar button svg { 32 | margin: 8px 12px 8px 8px; 33 | } 34 | 35 | #sidebar__btn-active { 36 | background-color: rgba(64,87,109,.07); 37 | width: 244px; 38 | } 39 | 40 | #sidebar__bottom-btn { 41 | position: absolute; 42 | right: 16px; 43 | bottom: 132px; 44 | width: 220px; 45 | 46 | background-color: rgba(64,87,109,.07); 47 | } 48 | 49 | #sidebar__bottom-btn svg { 50 | color: #fbbe28; 51 | 52 | } 53 | -------------------------------------------------------------------------------- /src/Templates.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import './Templates.css'; 3 | 4 | function Templates({ title, image_1, image_2, image_3, image_4, image_5 }) { 5 | return ( 6 |
7 |

{title}

8 | 35 |
36 | ) 37 | } 38 | 39 | export default Templates 40 | -------------------------------------------------------------------------------- /src/features/counter/Counter.module.css: -------------------------------------------------------------------------------- 1 | .row { 2 | display: flex; 3 | align-items: center; 4 | justify-content: center; 5 | } 6 | 7 | .row > button { 8 | margin-left: 4px; 9 | margin-right: 8px; 10 | } 11 | .row:not(:last-child) { 12 | margin-bottom: 16px; 13 | } 14 | 15 | .value { 16 | font-size: 78px; 17 | padding-left: 16px; 18 | padding-right: 16px; 19 | margin-top: 2px; 20 | font-family: 'Courier New', Courier, monospace; 21 | } 22 | 23 | .button { 24 | appearance: none; 25 | background: none; 26 | font-size: 32px; 27 | padding-left: 12px; 28 | padding-right: 12px; 29 | outline: none; 30 | border: 2px solid transparent; 31 | color: rgb(112, 76, 182); 32 | padding-bottom: 4px; 33 | cursor: pointer; 34 | background-color: rgba(112, 76, 182, 0.1); 35 | border-radius: 2px; 36 | transition: all 0.15s; 37 | } 38 | 39 | .textbox { 40 | font-size: 32px; 41 | padding: 2px; 42 | width: 64px; 43 | text-align: center; 44 | margin-right: 4px; 45 | } 46 | 47 | .button:hover, 48 | .button:focus { 49 | border: 2px solid rgba(112, 76, 182, 0.4); 50 | } 51 | 52 | .button:active { 53 | background-color: rgba(112, 76, 182, 0.2); 54 | } 55 | 56 | .asyncButton { 57 | composes: button; 58 | position: relative; 59 | } 60 | 61 | .asyncButton:after { 62 | content: ''; 63 | background-color: rgba(112, 76, 182, 0.15); 64 | display: block; 65 | position: absolute; 66 | width: 100%; 67 | height: 100%; 68 | left: 0; 69 | top: 0; 70 | opacity: 0; 71 | transition: width 1s linear, opacity 0.5s ease 1s; 72 | } 73 | 74 | .asyncButton:active:after { 75 | width: 0%; 76 | opacity: 1; 77 | transition: 0s; 78 | } 79 | -------------------------------------------------------------------------------- /.firebase/hosting.YnVpbGQ.cache: -------------------------------------------------------------------------------- 1 | asset-manifest.json,1626560693767,fb35cf94ef63675f55aa3ed9049f3e8e7bf0be5e76bd54e6e14b4d43b64152fc 2 | favicon.ico,1626560679921,c81fe46aa56ff717146af829dfdd7b9caa5caf51a1d8e65f6843335dec38c2f9 3 | index.html,1626560693767,1d40db7f9bd162a1c9db5b4022c1d790921c813b39fd7e482b6c75b2c269b151 4 | logo192.png,1626560679922,b6d536a4ad34ade7f3e29832862aa72cf87c179a3c93752fc9097b31ae9e39ff 5 | logo512.png,1626560679922,95c6c19d1765afb5e489883a64de60caa980aa45c129eae52568585d660be15a 6 | manifest.json,1626560679923,341d52628782f8ac9290bbfc43298afccb47b7cbfcee146ae30cf0f46bc30900 7 | robots.txt,1626560679923,381eb2c6776dd7924af6a6f8761e8720f5c7fb210451f07f2d13cf52af3073d2 8 | static/css/main.a4e64d47.chunk.css,1626560693769,13f58b2ef15471f65a239e56fa2fb265b9853c6d2eadc7d1a3ecdb43a3e83ae9 9 | static/css/main.a4e64d47.chunk.css.map,1626560693788,a02f82acd272a251aa4925bb7b3aa89b69539c0cbb623fead00f59331d21aac3 10 | static/js/2.bf49640c.chunk.js.LICENSE.txt,1626560693785,bfbf3a4b9e414262e302b9c850733cb7cfafa9577cb62b814d04300a511215fc 11 | static/js/runtime-main.51856891.js,1626560693785,aa91f0655041ca0c05aee61fc9948b91c716a2d91323daa16e412e293f837879 12 | static/js/runtime-main.51856891.js.map,1626560693788,4983c10d89f9e1c5bfe4960b4105e761590fa49358ce737e4b26aba1fab58cb5 13 | static/js/main.4d5e04fc.chunk.js,1626560693777,c0b550f3b2d43c60610d4e54df387e6eb227f43f1f9b5a548799bf12850f3d42 14 | static/js/main.4d5e04fc.chunk.js.map,1626560693788,b6ce9fbe61ea56c0718cdf3993c8b24ab4ddc70318f05f261ec60aecd18a8bad 15 | static/js/2.bf49640c.chunk.js,1626560693785,5c9d6c52558017cc28e6214510121e5539e3d70d6aab9ade30438e3ef14c1443 16 | static/js/2.bf49640c.chunk.js.map,1626560693788,00cc40bf3eacd05f00443bd66d84ad80ea92d9f9522506aa552599a8099feb7f 17 | -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 17 | 18 | 27 | React Redux App 28 | 29 | 30 | 31 |
32 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /src/Banner.css: -------------------------------------------------------------------------------- 1 | .banner__top { 2 | padding-right: 32px; 3 | height: 192px; 4 | width: 95%; 5 | border-top-left-radius: 8px; 6 | border-top-right-radius: 8px; 7 | color: white; 8 | text-align: center; 9 | background-size: cover; 10 | font-size: 14px; 11 | text-align: center; 12 | background-image: url('https://static.canva.com/web/images/f1ea2ceabc2022676b55fe69cecbbf5c.jpg'); 13 | } 14 | 15 | .banner__top h1 { 16 | padding-top: 24px; 17 | margin-bottom: 12px; 18 | } 19 | 20 | .banner__categories { 21 | list-style-type: none; 22 | display: flex; 23 | justify-content: space-evenly; 24 | width: 880px; 25 | margin: 0 auto; 26 | 27 | } 28 | 29 | .banner__category { 30 | width: 96px; 31 | margin: 12px 8px 8px 8px; 32 | } 33 | 34 | .banner__category p { 35 | margin: 8px 8px 8px 8px; 36 | text-align: center; 37 | } 38 | 39 | .banner__category-btn { 40 | height: 56px; 41 | width: 56px; 42 | border-radius: 50%; 43 | border: none; 44 | margin: 8px; 45 | display: flex; 46 | justify-content: center; 47 | align-items: center; 48 | margin: 0 auto; 49 | background-color: hsla(0,0%,100%,.15); 50 | } 51 | 52 | .banner__category-btn:hover { 53 | background-color: white; 54 | color: #713adf 55 | } 56 | 57 | .banner__category-btn svg { 58 | color: white; 59 | } 60 | 61 | .banner__category-btn svg:hover { 62 | color: #713adf 63 | } 64 | 65 | .banner__bottom { 66 | width: 95%; 67 | padding-right: 32px; 68 | background-color: #f8f9f9; 69 | border-bottom-left-radius: 8px; 70 | border-bottom-right-radius: 8px; 71 | margin-bottom: 48px; 72 | height: 237px; 73 | font-weight: 500; 74 | font-size: 14px; 75 | } 76 | 77 | .banner__bottom ul { 78 | display: flex; 79 | justify-content: space-between; 80 | align-items: center; 81 | list-style-type: none; 82 | } 83 | 84 | .banner__featured-template img { 85 | width: 192px; 86 | margin-right: 24px; 87 | border-radius: 8px; 88 | margin-top: 24px; 89 | } 90 | -------------------------------------------------------------------------------- /src/features/counter/Counter.js: -------------------------------------------------------------------------------- 1 | import React, { useState } from 'react'; 2 | import { useSelector, useDispatch } from 'react-redux'; 3 | import { 4 | decrement, 5 | increment, 6 | incrementByAmount, 7 | incrementAsync, 8 | incrementIfOdd, 9 | selectCount, 10 | } from './counterSlice'; 11 | import styles from './Counter.module.css'; 12 | 13 | export function Counter() { 14 | const count = useSelector(selectCount); 15 | const dispatch = useDispatch(); 16 | const [incrementAmount, setIncrementAmount] = useState('2'); 17 | 18 | const incrementValue = Number(incrementAmount) || 0; 19 | 20 | return ( 21 |
22 |
23 | 30 | {count} 31 | 38 |
39 |
40 | setIncrementAmount(e.target.value)} 45 | /> 46 | 52 | 58 | 64 |
65 |
66 | ); 67 | } 68 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app), using the [Redux](https://redux.js.org/) and [Redux Toolkit](https://redux-toolkit.js.org/) template. 2 | 3 | ## Available Scripts 4 | 5 | In the project directory, you can run: 6 | 7 | ### `yarn start` 8 | 9 | Runs the app in the development mode.
10 | Open [http://localhost:3000](http://localhost:3000) to view it in the browser. 11 | 12 | The page will reload if you make edits.
13 | You will also see any lint errors in the console. 14 | 15 | ### `yarn test` 16 | 17 | Launches the test runner in the interactive watch mode.
18 | See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. 19 | 20 | ### `yarn build` 21 | 22 | Builds the app for production to the `build` folder.
23 | It correctly bundles React in production mode and optimizes the build for the best performance. 24 | 25 | The build is minified and the filenames include the hashes.
26 | Your app is ready to be deployed! 27 | 28 | See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. 29 | 30 | ### `yarn eject` 31 | 32 | **Note: this is a one-way operation. Once you `eject`, you can’t go back!** 33 | 34 | If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. 35 | 36 | Instead, it will copy all the configuration files and the transitive dependencies (Webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own. 37 | 38 | You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it. 39 | 40 | ## Learn More 41 | 42 | You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). 43 | 44 | To learn React, check out the [React documentation](https://reactjs.org/). 45 | -------------------------------------------------------------------------------- /src/Header.css: -------------------------------------------------------------------------------- 1 | .header { 2 | height: 72px; 3 | position: fixed; 4 | top: 0; 5 | display: flex; 6 | align-items: center; 7 | box-shadow: 0 1px 4px rgb(64 87 109 / 7%); 8 | background-color: white; 9 | padding: 0 32px; 10 | z-index: 999; 11 | } 12 | 13 | .header svg { 14 | height: 56px; 15 | } 16 | 17 | .header__links { 18 | display: flex; 19 | justify-content: space-evenly; 20 | align-items: center; 21 | } 22 | 23 | .header__links button { 24 | display: flex; 25 | justify-content: center; 26 | align-items: center; 27 | } 28 | 29 | .header__links svg { 30 | padding: 6px; 31 | color: gray; 32 | } 33 | 34 | .header__links button { 35 | width: 96px; 36 | text-align: center; 37 | font-size: 14px; 38 | font-weight: 300; 39 | background-color: white; 40 | border: none; 41 | margin: 0 5px; 42 | } 43 | 44 | .header__links button:hover { 45 | background-color: rgba(64,87,109,.07); 46 | height: 40px; 47 | border-radius: 4px; 48 | } 49 | 50 | .header__links .home-btn { 51 | background-color: rgba(64,87,109,.07); 52 | height: 40px; 53 | width: 66px; 54 | margin: 0 20px 0 10px; 55 | font-weight: 600; 56 | border-radius: 4px; 57 | line-height: 40px; 58 | display: flex; 59 | justify-content: center; 60 | align-items: center; 61 | } 62 | 63 | .header form { 64 | display: flex; 65 | align-items: center; 66 | } 67 | 68 | .header form svg { 69 | position: relative; 70 | right: -40px; 71 | z-index: 999; 72 | } 73 | 74 | .header__search-bar { 75 | position: relative; 76 | left: -30px; 77 | width: 410px; 78 | height: 40px; 79 | padding: 0 0 0 40px; 80 | margin: 0px; 81 | border: 1px solid #e1e1e1; 82 | font-size: 14px; 83 | border-radius: 4px; 84 | margin-left: 40px; 85 | } 86 | 87 | .header__right { 88 | display: flex; 89 | align-items: center; 90 | justify-content: flex-end; 91 | } 92 | 93 | .header__right { 94 | padding-left: 16px; 95 | } 96 | 97 | .header__icons { 98 | padding: 8px; 99 | } 100 | 101 | .header_create-btn { 102 | background: #7d2ae8; 103 | color: white; 104 | border-radius: 4px; 105 | width: 136px; 106 | height: 40px; 107 | margin: 16px; 108 | border: none; 109 | font-size: 14px; 110 | font-weight: 600; 111 | } 112 | 113 | .header_profile-btn { 114 | height: 40px; 115 | width: 40px; 116 | display: flex; 117 | justify-content: center; 118 | line-height: 40px; 119 | border-radius: 50%; 120 | border: none; 121 | background-color: #7d2ae8; 122 | color: white; 123 | font-size: 22px; 124 | } 125 | -------------------------------------------------------------------------------- /src/features/counter/counterSlice.js: -------------------------------------------------------------------------------- 1 | import { createAsyncThunk, createSlice } from '@reduxjs/toolkit'; 2 | import { fetchCount } from './counterAPI'; 3 | 4 | const initialState = { 5 | value: 0, 6 | status: 'idle', 7 | }; 8 | 9 | // The function below is called a thunk and allows us to perform async logic. It 10 | // can be dispatched like a regular action: `dispatch(incrementAsync(10))`. This 11 | // will call the thunk with the `dispatch` function as the first argument. Async 12 | // code can then be executed and other actions can be dispatched. Thunks are 13 | // typically used to make async requests. 14 | export const incrementAsync = createAsyncThunk( 15 | 'counter/fetchCount', 16 | async (amount) => { 17 | const response = await fetchCount(amount); 18 | // The value we return becomes the `fulfilled` action payload 19 | return response.data; 20 | } 21 | ); 22 | 23 | export const counterSlice = createSlice({ 24 | name: 'counter', 25 | initialState, 26 | // The `reducers` field lets us define reducers and generate associated actions 27 | reducers: { 28 | increment: (state) => { 29 | // Redux Toolkit allows us to write "mutating" logic in reducers. It 30 | // doesn't actually mutate the state because it uses the Immer library, 31 | // which detects changes to a "draft state" and produces a brand new 32 | // immutable state based off those changes 33 | state.value += 1; 34 | }, 35 | decrement: (state) => { 36 | state.value -= 1; 37 | }, 38 | // Use the PayloadAction type to declare the contents of `action.payload` 39 | incrementByAmount: (state, action) => { 40 | state.value += action.payload; 41 | }, 42 | }, 43 | // The `extraReducers` field lets the slice handle actions defined elsewhere, 44 | // including actions generated by createAsyncThunk or in other slices. 45 | extraReducers: (builder) => { 46 | builder 47 | .addCase(incrementAsync.pending, (state) => { 48 | state.status = 'loading'; 49 | }) 50 | .addCase(incrementAsync.fulfilled, (state, action) => { 51 | state.status = 'idle'; 52 | state.value += action.payload; 53 | }); 54 | }, 55 | }); 56 | 57 | export const { increment, decrement, incrementByAmount } = counterSlice.actions; 58 | 59 | // The function below is called a selector and allows us to select a value from 60 | // the state. Selectors can also be defined inline where they're used instead of 61 | // in the slice file. For example: `useSelector((state: RootState) => state.counter.value)` 62 | export const selectCount = (state) => state.counter.value; 63 | 64 | // We can also write thunks by hand, which may contain both sync and async logic. 65 | // Here's an example of conditionally dispatching actions based on current state. 66 | export const incrementIfOdd = (amount) => (dispatch, getState) => { 67 | const currentValue = selectCount(getState()); 68 | if (currentValue % 2 === 1) { 69 | dispatch(incrementByAmount(amount)); 70 | } 71 | }; 72 | 73 | export default counterSlice.reducer; 74 | -------------------------------------------------------------------------------- /src/App.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import './App.css'; 3 | import Banner from './Banner'; 4 | import Header from './Header'; 5 | import Sidebar from './Sidebar'; 6 | import Templates from './Templates'; 7 | 8 | function App() { 9 | return ( 10 |
11 |
12 | 13 |
14 | 15 | 23 | 31 | 39 | 47 | 55 | 63 | 71 | 79 | 87 |
88 |
89 | ); 90 | } 91 | 92 | export default App; 93 | -------------------------------------------------------------------------------- /src/serviceWorker.js: -------------------------------------------------------------------------------- 1 | // This optional code is used to register a service worker. 2 | // register() is not called by default. 3 | 4 | // This lets the app load faster on subsequent visits in production, and gives 5 | // it offline capabilities. However, it also means that developers (and users) 6 | // will only see deployed updates on subsequent visits to a page, after all the 7 | // existing tabs open on the page have been closed, since previously cached 8 | // resources are updated in the background. 9 | 10 | // To learn more about the benefits of this model and instructions on how to 11 | // opt-in, read https://bit.ly/CRA-PWA 12 | 13 | const isLocalhost = Boolean( 14 | window.location.hostname === 'localhost' || 15 | // [::1] is the IPv6 localhost address. 16 | window.location.hostname === '[::1]' || 17 | // 127.0.0.0/8 are considered localhost for IPv4. 18 | window.location.hostname.match( 19 | /^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/ 20 | ) 21 | ); 22 | 23 | export function register(config) { 24 | if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) { 25 | // The URL constructor is available in all browsers that support SW. 26 | const publicUrl = new URL(process.env.PUBLIC_URL, window.location.href); 27 | if (publicUrl.origin !== window.location.origin) { 28 | // Our service worker won't work if PUBLIC_URL is on a different origin 29 | // from what our page is served on. This might happen if a CDN is used to 30 | // serve assets; see https://github.com/facebook/create-react-app/issues/2374 31 | return; 32 | } 33 | 34 | window.addEventListener('load', () => { 35 | const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`; 36 | 37 | if (isLocalhost) { 38 | // This is running on localhost. Let's check if a service worker still exists or not. 39 | checkValidServiceWorker(swUrl, config); 40 | 41 | // Add some additional logging to localhost, pointing developers to the 42 | // service worker/PWA documentation. 43 | navigator.serviceWorker.ready.then(() => { 44 | console.log( 45 | 'This web app is being served cache-first by a service ' + 46 | 'worker. To learn more, visit https://bit.ly/CRA-PWA' 47 | ); 48 | }); 49 | } else { 50 | // Is not localhost. Just register service worker 51 | registerValidSW(swUrl, config); 52 | } 53 | }); 54 | } 55 | } 56 | 57 | function registerValidSW(swUrl, config) { 58 | navigator.serviceWorker 59 | .register(swUrl) 60 | .then((registration) => { 61 | registration.onupdatefound = () => { 62 | const installingWorker = registration.installing; 63 | if (installingWorker == null) { 64 | return; 65 | } 66 | installingWorker.onstatechange = () => { 67 | if (installingWorker.state === 'installed') { 68 | if (navigator.serviceWorker.controller) { 69 | // At this point, the updated precached content has been fetched, 70 | // but the previous service worker will still serve the older 71 | // content until all client tabs are closed. 72 | console.log( 73 | 'New content is available and will be used when all ' + 74 | 'tabs for this page are closed. See https://bit.ly/CRA-PWA.' 75 | ); 76 | 77 | // Execute callback 78 | if (config && config.onUpdate) { 79 | config.onUpdate(registration); 80 | } 81 | } else { 82 | // At this point, everything has been precached. 83 | // It's the perfect time to display a 84 | // "Content is cached for offline use." message. 85 | console.log('Content is cached for offline use.'); 86 | 87 | // Execute callback 88 | if (config && config.onSuccess) { 89 | config.onSuccess(registration); 90 | } 91 | } 92 | } 93 | }; 94 | }; 95 | }) 96 | .catch((error) => { 97 | console.error('Error during service worker registration:', error); 98 | }); 99 | } 100 | 101 | function checkValidServiceWorker(swUrl, config) { 102 | // Check if the service worker can be found. If it can't reload the page. 103 | fetch(swUrl, { 104 | headers: { 'Service-Worker': 'script' }, 105 | }) 106 | .then((response) => { 107 | // Ensure service worker exists, and that we really are getting a JS file. 108 | const contentType = response.headers.get('content-type'); 109 | if ( 110 | response.status === 404 || 111 | (contentType != null && contentType.indexOf('javascript') === -1) 112 | ) { 113 | // No service worker found. Probably a different app. Reload the page. 114 | navigator.serviceWorker.ready.then((registration) => { 115 | registration.unregister().then(() => { 116 | window.location.reload(); 117 | }); 118 | }); 119 | } else { 120 | // Service worker found. Proceed as normal. 121 | registerValidSW(swUrl, config); 122 | } 123 | }) 124 | .catch(() => { 125 | console.log( 126 | 'No internet connection found. App is running in offline mode.' 127 | ); 128 | }); 129 | } 130 | 131 | export function unregister() { 132 | if ('serviceWorker' in navigator) { 133 | navigator.serviceWorker.ready.then((registration) => { 134 | registration.unregister(); 135 | }); 136 | } 137 | } 138 | -------------------------------------------------------------------------------- /src/Sidebar.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import './Sidebar.css'; 3 | 4 | function Sidebar() { 5 | return ( 6 |
7 | 12 | 18 | 24 | 31 | 38 | 45 | 51 | 58 | 62 |
63 | ) 64 | } 65 | 66 | export default Sidebar 67 | -------------------------------------------------------------------------------- /src/Header.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import './Header.css'; 3 | 4 | function Header() { 5 | return ( 6 |
7 |
8 | 9 |
10 |
11 | 14 | 20 | 26 | 32 | 38 |
39 |
40 |
41 | 42 | 43 | 44 | 45 |
46 |
47 |
48 |
49 | 50 | 51 | 52 | 53 |
54 |
55 | 56 | 57 | 58 | 59 |
60 | 63 | 66 |
67 |
68 | ) 69 | } 70 | 71 | export default Header 72 | -------------------------------------------------------------------------------- /src/Banner.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import './Banner.css'; 3 | 4 | function Banner() { 5 | return ( 6 |
7 |
8 |

Design anything

9 | 76 |
77 |
78 | 111 |
112 |
113 | ) 114 | } 115 | 116 | export default Banner 117 | --------------------------------------------------------------------------------