├── src ├── api │ └── api.js ├── containers │ ├── SEGA.woff │ ├── App.css │ └── App.js ├── index.css ├── constants.js ├── components │ ├── Scroll.js │ ├── Card.js │ ├── SearchBox.js │ ├── Header.js │ ├── ErrorBoundry.js │ ├── CardList.js │ └── CounterButton.js ├── actions.js ├── index.js ├── reducers.js └── serviceWorker.js ├── public ├── favicon.ico ├── manifest.json └── index.html ├── README.md ├── .gitignore └── package.json /src/api/api.js: -------------------------------------------------------------------------------- 1 | export const apiCall = (link) => 2 | fetch(link).then(response => response.json()) 3 | 4 | -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aneagoie/Center-For-Robotos-Who-Cant-Be-In-The-App-Store-And-Wanna-Learn-To-Do-Other-Stuff-Good-Too-update/HEAD/public/favicon.ico -------------------------------------------------------------------------------- /src/containers/SEGA.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aneagoie/Center-For-Robotos-Who-Cant-Be-In-The-App-Store-And-Wanna-Learn-To-Do-Other-Stuff-Good-Too-update/HEAD/src/containers/SEGA.woff -------------------------------------------------------------------------------- /src/index.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 0; 3 | padding: 0; 4 | font-family: sans-serif; 5 | background: linear-gradient(to left, rgba(7,27,82,1) 0%, rgba(0,128,128,1) 100%); /* w3c */ 6 | } 7 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # robofriends 2 | React + Redux + PWA 3 | 4 | To run the project: 5 | 6 | 1. Clone this repo 7 | 2. Run `npm install` 8 | 3. Run `npm start` 9 | 10 | *visist https://zerotomastery.io/ for more* 11 | 12 | 13 | -------------------------------------------------------------------------------- /src/constants.js: -------------------------------------------------------------------------------- 1 | export const CHANGE_SEARCHFIELD = 'CHANGE_SEARCHFIELD'; 2 | 3 | export const REQUEST_ROBOTS_PENDING = 'REQUEST_ROBOTS_PENDING'; 4 | export const REQUEST_ROBOTS_SUCCESS = 'REQUEST_ROBOTS_SUCCESS'; 5 | export const REQUEST_ROBOTS_FAILED = 'REQUEST_ROBOTS_FAILED'; -------------------------------------------------------------------------------- /src/components/Scroll.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | 3 | const Scroll = (props) => { 4 | return ( 5 |
6 | {props.children} 7 |
8 | ); 9 | }; 10 | 11 | export default Scroll; 12 | -------------------------------------------------------------------------------- /src/containers/App.css: -------------------------------------------------------------------------------- 1 | /* #### Generated By: http://www.cufonfonts.com #### */ 2 | 3 | @font-face { 4 | font-family: 'SEGA LOGO FONT'; 5 | font-style: normal; 6 | font-weight: normal; 7 | src: local('SEGA LOGO FONT'), url('SEGA.woff') format('woff'); 8 | } 9 | 10 | h1 { 11 | font-family: 'SEGA LOGO FONT'; 12 | font-weight: 200; 13 | color: #0ccac4; 14 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | 6 | # testing 7 | /coverage 8 | 9 | # production 10 | /build 11 | 12 | # misc 13 | .DS_Store 14 | .env.local 15 | .env.development.local 16 | .env.test.local 17 | .env.production.local 18 | npm-debug.log* 19 | yarn-debug.log* 20 | yarn-error.log* 21 | 22 | -------------------------------------------------------------------------------- /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 | "start_url": "./index.html", 12 | "display": "standalone", 13 | "theme_color": "#000000", 14 | "background_color": "#ffffff" 15 | } 16 | -------------------------------------------------------------------------------- /src/components/Card.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | 3 | const Card = ({ name, email, id }) => { 4 | return ( 5 |
6 | robots 7 |
8 |

{name}

9 |

{email}

10 |
11 |
12 | ); 13 | } 14 | 15 | export default Card; -------------------------------------------------------------------------------- /src/components/SearchBox.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | 3 | const SearchBox = ({ searchfield, searchChange }) => { 4 | console.log('SearchBox') 5 | return ( 6 |
7 | 13 |
14 | ); 15 | } 16 | 17 | export default SearchBox; -------------------------------------------------------------------------------- /src/components/Header.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react'; 2 | import CounterButton from './CounterButton'; 3 | 4 | class Header extends Component { 5 | // shouldComponentUpdate(nextProps, nextState) { 6 | // return false; 7 | // } 8 | 9 | render() { 10 | console.log('Header') 11 | return ( 12 |
13 |

RoboFriends

14 | 15 |
16 | ); 17 | } 18 | } 19 | 20 | export default Header; 21 | -------------------------------------------------------------------------------- /src/components/ErrorBoundry.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react' 2 | 3 | class ErrorBoundary extends Component { 4 | constructor (props) { 5 | super(props) 6 | this.state = { hasError: false } 7 | } 8 | 9 | componentDidCatch (error, info) { 10 | this.setState({ hasError: true }) 11 | } 12 | 13 | render () { 14 | if (this.state.hasError) { 15 | return

Something went wrong.

16 | } 17 | return this.props.children 18 | } 19 | } 20 | 21 | export default ErrorBoundary -------------------------------------------------------------------------------- /src/components/CardList.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import Card from './Card'; 3 | 4 | const CardList = ({ robots }) => { 5 | console.log('CardList') 6 | return ( 7 |
8 | { 9 | robots.map((user, i) => { 10 | return ( 11 | 17 | ); 18 | }) 19 | } 20 |
21 | ); 22 | } 23 | 24 | export default CardList; -------------------------------------------------------------------------------- /src/actions.js: -------------------------------------------------------------------------------- 1 | import { apiCall } from './api/api' 2 | import { 3 | CHANGE_SEARCHFIELD, 4 | REQUEST_ROBOTS_PENDING, 5 | REQUEST_ROBOTS_SUCCESS, 6 | REQUEST_ROBOTS_FAILED 7 | } from './constants' 8 | 9 | 10 | export const setSearchField = (text) => ({ type: CHANGE_SEARCHFIELD, payload: text }) 11 | 12 | export const requestRobots = () => (dispatch) => { 13 | dispatch({ type: REQUEST_ROBOTS_PENDING }) 14 | apiCall('https://jsonplaceholder.typicode.com/users') 15 | .then(data => dispatch({ type: REQUEST_ROBOTS_SUCCESS, payload: data })) 16 | .catch(error => dispatch({ type: REQUEST_ROBOTS_FAILED, payload: error })) 17 | } -------------------------------------------------------------------------------- /src/components/CounterButton.js: -------------------------------------------------------------------------------- 1 | import React, { PureComponent } from 'react'; 2 | 3 | class CounterButton extends PureComponent { 4 | constructor() { 5 | super(); 6 | this.state = { 7 | count: 0 8 | } 9 | } 10 | 11 | //below is not needed if we extend PureComponent 12 | //like we have above 13 | // shouldComponentUpdate(nextProps, nextState) { 14 | // if (this.state.count !== nextState.count) { 15 | // return true 16 | // } 17 | // return false 18 | // } 19 | 20 | updateCount = () => { 21 | this.setState(state => { 22 | return {count: state.count + 1} 23 | }) 24 | } 25 | 26 | render() { 27 | console.log('CounterButton') 28 | return ( 29 | 32 | ); 33 | } 34 | } 35 | 36 | export default CounterButton; -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | // import ReactDOM from 'react-dom'; The new way to import createRoot: 3 | import { createRoot } from "react-dom/client"; 4 | import { createStore, combineReducers, applyMiddleware } from 'redux'; 5 | import { Provider } from 'react-redux'; 6 | import { thunk } from 'redux-thunk'; 7 | import { createLogger } from 'redux-logger'; 8 | import 'tachyons'; 9 | 10 | import App from './containers/App'; 11 | import * as serviceWorker from './serviceWorker'; 12 | import { requestRobots, searchRobots } from './reducers' 13 | 14 | import './index.css'; 15 | 16 | const logger = createLogger() 17 | 18 | const rootReducers = combineReducers({requestRobots, searchRobots}) 19 | 20 | const store = createStore(rootReducers, applyMiddleware(thunk)) 21 | 22 | const root = createRoot(document.getElementById('root')); 23 | root.render( 24 | 25 | 26 | , 27 | ); 28 | 29 | serviceWorker.register(); 30 | -------------------------------------------------------------------------------- /src/reducers.js: -------------------------------------------------------------------------------- 1 | import { 2 | CHANGE_SEARCHFIELD, 3 | REQUEST_ROBOTS_PENDING, 4 | REQUEST_ROBOTS_SUCCESS, 5 | REQUEST_ROBOTS_FAILED 6 | } from './constants'; 7 | 8 | const initialStateSearch = { 9 | searchField: '' 10 | } 11 | 12 | export const searchRobots = (state=initialStateSearch, action={}) => { 13 | switch (action.type) { 14 | case CHANGE_SEARCHFIELD: 15 | return Object.assign({}, state, {searchField: action.payload}) 16 | default: 17 | return state 18 | } 19 | } 20 | 21 | const initialStateRobots = { 22 | robots: [], 23 | isPending: true 24 | } 25 | 26 | export const requestRobots = (state=initialStateRobots, action={}) => { 27 | switch (action.type) { 28 | case REQUEST_ROBOTS_PENDING: 29 | return Object.assign({}, state, {isPending: true}) 30 | case REQUEST_ROBOTS_SUCCESS: 31 | return Object.assign({}, state, {robots: action.payload, isPending: false}) 32 | case REQUEST_ROBOTS_FAILED: 33 | return Object.assign({}, state, {error: action.payload}) 34 | default: 35 | return state 36 | } 37 | } -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "robofriends", 3 | "version": "0.1.0", 4 | "private": true, 5 | "homepage": "https://aneagoie.github.io/Center-For-Robotos-Who-Cant-Be-In-The-App-Store-And-Wanna-Learn-To-Do-Other-Stuff-Good-Too-update", 6 | "dependencies": { 7 | "gh-pages": "^6.3.0", 8 | "react": "^19.1.1", 9 | "react-dom": "^19.1.1", 10 | "react-redux": "^9.2.0", 11 | "react-scripts": "^5.0.1", 12 | "redux": "^5.0.1", 13 | "redux-logger": "^3.0.6", 14 | "redux-thunk": "^3.1.0", 15 | "tachyons": "^4.12.0" 16 | }, 17 | "scripts": { 18 | "start": "react-scripts start", 19 | "build": "react-scripts build", 20 | "test": "react-scripts test --env=jsdom", 21 | "eject": "react-scripts eject", 22 | "predeploy": "npm run build", 23 | "deploy": "gh-pages -d build" 24 | }, 25 | "browserslist": { 26 | "production": [ 27 | ">0.2%", 28 | "not dead", 29 | "not op_mini all" 30 | ], 31 | "development": [ 32 | "last 1 chrome version", 33 | "last 1 firefox version", 34 | "last 1 safari version" 35 | ] 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/containers/App.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react'; 2 | import { connect } from 'react-redux'; 3 | import { setSearchField, requestRobots } from '../actions'; 4 | 5 | import CardList from '../components/CardList'; 6 | import SearchBox from '../components/SearchBox'; 7 | import Scroll from '../components/Scroll'; 8 | import ErrorBoundry from '../components/ErrorBoundry'; 9 | import Header from '../components/Header'; 10 | 11 | import './App.css'; 12 | 13 | 14 | const mapStateToProps = (state) => { 15 | return { 16 | searchField: state.searchRobots.searchField, 17 | robots: state.requestRobots.robots, 18 | isPending: state.requestRobots.isPending 19 | } 20 | } 21 | 22 | const mapDispatchToProps = (dispatch) => { 23 | return { 24 | onSearchChange: (event) => dispatch(setSearchField(event.target.value)), 25 | onRequestRobots: () => dispatch(requestRobots()) 26 | } 27 | } 28 | 29 | class App extends Component { 30 | componentDidMount() { 31 | this.props.onRequestRobots(); 32 | } 33 | 34 | render() { 35 | const { robots, searchField, onSearchChange, isPending } = this.props; 36 | const filteredRobots = robots.filter(robot => { 37 | return robot.name.toLowerCase().includes(searchField.toLowerCase()); 38 | }) 39 | return ( 40 |
41 |
42 | 43 | 44 | { isPending ?

Loading

: 45 | 46 | 47 | 48 | } 49 |
50 |
51 | ); 52 | } 53 | } 54 | 55 | export default connect(mapStateToProps, mapDispatchToProps)(App) 56 | -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 11 | 12 | 13 | 22 | React App 23 | 24 | 25 | 28 |
29 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /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.1/8 is 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 | .then(response => { 105 | // Ensure service worker exists, and that we really are getting a JS file. 106 | const contentType = response.headers.get('content-type'); 107 | if ( 108 | response.status === 404 || 109 | (contentType != null && contentType.indexOf('javascript') === -1) 110 | ) { 111 | // No service worker found. Probably a different app. Reload the page. 112 | navigator.serviceWorker.ready.then(registration => { 113 | registration.unregister().then(() => { 114 | window.location.reload(); 115 | }); 116 | }); 117 | } else { 118 | // Service worker found. Proceed as normal. 119 | registerValidSW(swUrl, config); 120 | } 121 | }) 122 | .catch(() => { 123 | console.log( 124 | 'No internet connection found. App is running in offline mode.' 125 | ); 126 | }); 127 | } 128 | 129 | export function unregister() { 130 | if ('serviceWorker' in navigator) { 131 | navigator.serviceWorker.ready.then(registration => { 132 | registration.unregister(); 133 | }); 134 | } 135 | } 136 | --------------------------------------------------------------------------------