[
  {
    "path": ".gitignore",
    "content": "# See https://help.github.com/ignore-files/ for more about ignoring files.\n\n# dependencies\n/node_modules \n\n# testing\n/coverage\n\n# production\n/build\n\n# misc\n.DS_Store\n.env.local\n.env.development.local\n.env.test.local\n.env.production.local\n\nnpm-debug.log*\nyarn-debug.log*\nyarn-error.log*\n\n\n"
  },
  {
    "path": "README.md",
    "content": "# robofriends\nReact + Redux \n\nTo run the project:\n\n1. Clone this repo\n2. Run `npm install`\n3. Run `npm start`\n\n*visit https://zerotomastery.io/ for more*\n\n\n"
  },
  {
    "path": "package.json",
    "content": "{\n  \"name\": \"robofriends\",\n  \"version\": \"0.1.0\",\n  \"private\": true,\n  \"dependencies\": {\n    \"react\": \"^19.1.1\",\n    \"react-dom\": \"^19.1.1\",\n    \"react-redux\": \"^9.2.0\",\n    \"react-scripts\": \"^5.0.1\",\n    \"redux\": \"^5.0.1\",\n    \"redux-logger\": \"^3.0.6\",\n    \"redux-thunk\": \"^3.1.0\",\n    \"tachyons\": \"^4.12.0\"\n  },\n  \"scripts\": {\n    \"start\": \"react-scripts start\",\n    \"build\": \"react-scripts build\",\n    \"test\": \"react-scripts test --env=jsdom\",\n    \"eject\": \"react-scripts eject\"\n  },\n  \"browserslist\": {\n    \"production\": [\n      \">0.2%\",\n      \"not dead\",\n      \"not op_mini all\"\n    ],\n    \"development\": [\n      \"last 1 chrome version\",\n      \"last 1 firefox version\",\n      \"last 1 safari version\"\n    ]\n  }\n}\n"
  },
  {
    "path": "public/index.html",
    "content": "<!DOCTYPE html>\n<html lang=\"en\">\n  <head>\n    <meta charset=\"utf-8\">\n    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1, shrink-to-fit=no\">\n    <meta name=\"theme-color\" content=\"#000000\">\n    <!-- \n      manifest.json provides metadata used when your web app is added to the\n      homescreen on Android. See  https://developers.google.com/web/fundamentals/engage-and-retain/web-app-manifest/\n    -->\n    <link rel=\"manifest\" href=\"%PUBLIC_URL%/manifest.json\">\n    <link rel=\"shortcut icon\" href=\"%PUBLIC_URL%/favicon.ico\">\n    <!--\n      Notice the use of %PUBLIC_URL% in the tags above. \n      It will be replaced with the URL of the `public` folder during the build.\n      Only files inside the `public` folder can be referenced from the HTML.\n\n      Unlike \"/favicon.ico\" or \"favicon.ico\", \"%PUBLIC_URL%/favicon.ico\" will\n      work correctly both with client-side routing and a non-root public URL.\n      Learn how to configure a non-root public URL by running `npm run build`.\n    -->\n    <title>React App</title>\n  </head>\n  <body>\n    <noscript>\n      You need to enable JavaScript to run this app.\n    </noscript>\n    <div id=\"root\"></div>\n    <!--\n      This HTML file is a template.\n      If you open it directly in the browser, you will see an empty page.\n\n      You can add webfonts, meta tags, or analytics to this file.\n      The build step will place the bundled scripts into the <body> tag.\n\n      To begin the development, run `npm start` or `yarn start`.\n      To create a production bundle, use `npm run build` or `yarn build`.\n    -->\n  </body>\n</html>\n"
  },
  {
    "path": "public/manifest.json",
    "content": "{\n  \"short_name\": \"React App\",\n  \"name\": \"Create React App Sample\",\n  \"icons\": [\n    {\n      \"src\": \"favicon.ico\",\n      \"sizes\": \"64x64 32x32 24x24 16x16\",\n      \"type\": \"image/x-icon\"\n    }\n  ],\n  \"start_url\": \"./index.html\",\n  \"display\": \"standalone\",\n  \"theme_color\": \"#000000\",\n  \"background_color\": \"#ffffff\"\n}\n"
  },
  {
    "path": "src/actions.js",
    "content": "import { apiCall } from './api/api'\nimport {\n  CHANGE_SEARCHFIELD,\n  REQUEST_ROBOTS_PENDING,\n  REQUEST_ROBOTS_SUCCESS,\n  REQUEST_ROBOTS_FAILED\n } from './constants'\n\n\nexport const setSearchField = (text) => ({ type: CHANGE_SEARCHFIELD, payload: text })\n\nexport const requestRobots = () => (dispatch) => {\n  dispatch({ type: REQUEST_ROBOTS_PENDING })\n  apiCall('https://jsonplaceholder.typicode.com/users')\n    .then(data => dispatch({ type: REQUEST_ROBOTS_SUCCESS, payload: data }))\n    .catch(error => dispatch({ type: REQUEST_ROBOTS_FAILED, payload: error }))\n}"
  },
  {
    "path": "src/api/api.js",
    "content": "export const apiCall = (link) =>\n  fetch(link).then(response => response.json())"
  },
  {
    "path": "src/components/Card.js",
    "content": "import React from 'react';\n\nconst Card = ({ name, email, id }) => {\n  return (\n    <div className='tc grow bg-light-green br3 pa3 ma2 dib bw2 shadow-5'>\n      <img alt='robots' src={`https://robohash.org/${id}?200x200`} />\n      <div>\n        <h2>{name}</h2>\n        <p>{email}</p>\n      </div>\n    </div>\n  );\n}\n\nexport default Card;"
  },
  {
    "path": "src/components/CardList.js",
    "content": "import React from 'react';\nimport Card from './Card';\n\nconst CardList = ({ robots }) => {\n  return (\n    <div>\n      {\n        robots.map((user, i) => {\n          return (\n            <Card\n              key={i}\n              id={robots[i].id}\n              name={robots[i].name}\n              email={robots[i].email}\n              />\n          );\n        })\n      }\n    </div>\n  );\n}\n\nexport default CardList;"
  },
  {
    "path": "src/components/ErrorBoundry.js",
    "content": "import React, { Component } from 'react'\n\nclass ErrorBoundary extends Component {\n  constructor (props) {\n    super(props)\n    this.state = { hasError: false }\n  }\n\n  componentDidCatch (error, info) {\n    this.setState({ hasError: true })\n  }\n\n  render () {\n    if (this.state.hasError) {\n      return <h1>Something went wrong.</h1>\n    }\n    return this.props.children\n  }\n}\n\nexport default ErrorBoundary"
  },
  {
    "path": "src/components/Scroll.js",
    "content": "import React from 'react';\n\nconst Scroll = (props) => {\n  return (\n    <div style={{ overflow: 'scroll', border: '5px solid black', height: '800px'}}>\n      {props.children}\n    </div>\n  );\n};\n\nexport default Scroll;"
  },
  {
    "path": "src/components/SearchBox.js",
    "content": "import React from 'react';\n\nconst SearchBox = ({ searchfield, searchChange }) => {\n  return (\n    <div className='pa2'>\n      <input\n        className='pa3 ba b--green bg-lightest-blue'\n        type='search'\n        placeholder='search robots'\n        onChange={searchChange}\n      />\n    </div>\n  );\n}\n\nexport default SearchBox;"
  },
  {
    "path": "src/constants.js",
    "content": "export const CHANGE_SEARCHFIELD = 'CHANGE_SEARCHFIELD';\n\nexport const REQUEST_ROBOTS_PENDING = 'REQUEST_ROBOTS_PENDING';\nexport const REQUEST_ROBOTS_SUCCESS = 'REQUEST_ROBOTS_SUCCESS';\nexport const REQUEST_ROBOTS_FAILED = 'REQUEST_ROBOTS_FAILED';"
  },
  {
    "path": "src/containers/App.css",
    "content": "/* #### Generated By: http://www.cufonfonts.com #### */\n\n@font-face {\nfont-family: 'SEGA LOGO FONT';\nfont-style: normal;\nfont-weight: normal;\nsrc: local('SEGA LOGO FONT'), url('SEGA.woff') format('woff');\n}\n\nh1 {\n  font-family: 'SEGA LOGO FONT';\n  font-weight: 200;\n  color: #0ccac4;\n}"
  },
  {
    "path": "src/containers/App.js",
    "content": "import React, { Component } from 'react';\nimport { connect } from 'react-redux';\nimport { setSearchField, requestRobots } from '../actions';\n\nimport CardList from '../components/CardList';\nimport SearchBox from '../components/SearchBox';\nimport Scroll from '../components/Scroll';\nimport ErrorBoundry from '../components/ErrorBoundry';\n\nimport './App.css';\n\n// parameter state comes from index.js provider store state(rootReducers)\nconst mapStateToProps = (state) => {\n  return {\n    searchField: state.searchRobots.searchField,\n    robots: state.requestRobots.robots,\n    isPending: state.requestRobots.isPending\n  }\n}\n\n// dispatch the DOM changes to call an action. note mapStateToProps returns object, mapDispatchToProps returns function\n// the function returns an object then uses connect to change the data from redecers.\nconst mapDispatchToProps = (dispatch) => {\n  return {\n    onSearchChange: (event) => dispatch(setSearchField(event.target.value)),\n    onRequestRobots: () => dispatch(requestRobots())\n  }\n}\n\nclass App extends Component {\n  componentDidMount() {\n    this.props.onRequestRobots();\n  }\n\n  render() {\n    const { robots, searchField, onSearchChange, isPending } = this.props;\n    const filteredRobots = robots.filter(robot => {\n      return robot.name.toLowerCase().includes(searchField.toLowerCase());\n    })\n    return (\n      <div className='tc'>\n        <h1 className='f1'>RoboFriends</h1>\n        <SearchBox searchChange={onSearchChange}/>\n        <Scroll>\n          { isPending ? <h1>Loading</h1> :\n            <ErrorBoundry>\n              <CardList robots={filteredRobots} />\n            </ErrorBoundry>\n          }\n        </Scroll>\n      </div>\n    );\n  }\n}\n\n// action done from mapDispatchToProps will channge state from mapStateToProps\nexport default connect(mapStateToProps, mapDispatchToProps)(App)\n"
  },
  {
    "path": "src/index.css",
    "content": "body {\n  margin: 0;\n  padding: 0;\n  font-family: sans-serif;\n  background: linear-gradient(to left, rgba(7,27,82,1) 0%, rgba(0,128,128,1) 100%); /* w3c */\n}\n"
  },
  {
    "path": "src/index.js",
    "content": "import React from 'react';\n// import ReactDOM from 'react-dom'; The new way to import createRoot:\nimport { createRoot } from \"react-dom/client\";\nimport { createStore, combineReducers, applyMiddleware } from 'redux';\nimport { Provider } from 'react-redux';\n\n//import thunkMiddleware from 'redux-thunk';\n//NEW way of importing redux-thunk:\nimport { thunk } from 'redux-thunk';\nimport { createLogger } from 'redux-logger';\nimport 'tachyons';\n\nimport App from './containers/App';\nimport registerServiceWorker from './registerServiceWorker';\nimport { requestRobots, searchRobots } from './reducers'\n\nimport './index.css';\n\nconst logger = createLogger() \n\nconst rootReducers = combineReducers({requestRobots, searchRobots})\n\nconst store = createStore(rootReducers, applyMiddleware(thunk, logger))\n\nconst root = createRoot(document.getElementById('root'));\nroot.render(\n<Provider store={store}>\n  <App/>\n</Provider>\n);\n\n// ReactDOM.render(\n//   <Provider store={store}>\n//     <App/>\n//   </Provider>,\n//   document.getElementById('root')\n// );\nregisterServiceWorker();\n\n"
  },
  {
    "path": "src/reducers.js",
    "content": "import {\n  CHANGE_SEARCHFIELD,\n  REQUEST_ROBOTS_PENDING,\n  REQUEST_ROBOTS_SUCCESS,\n  REQUEST_ROBOTS_FAILED\n } from './constants';\n\nconst initialStateSearch = {\n  searchField: ''\n}\n\nexport const searchRobots = (state=initialStateSearch, action={}) => {\n  switch (action.type) {\n    case CHANGE_SEARCHFIELD:\n      return Object.assign({}, state, {searchField: action.payload})\n    default:\n      return state\n  }\n}\n\nconst initialStateRobots = {\n  robots: [],\n  isPending: true\n}\n\nexport const requestRobots = (state=initialStateRobots, action={}) => {\n  switch (action.type) {\n    case REQUEST_ROBOTS_PENDING:\n      return Object.assign({}, state, {isPending: true})\n    case REQUEST_ROBOTS_SUCCESS:\n      return Object.assign({}, state, {robots: action.payload, isPending: false})\n    case REQUEST_ROBOTS_FAILED:\n      return Object.assign({}, state, {error: action.payload})\n    default:\n      return state\n  }\n}\n"
  },
  {
    "path": "src/registerServiceWorker.js",
    "content": "// In production, we register a service worker to serve assets from local cache.\n\n// This lets the app load faster on subsequent visits in production, and gives\n// it offline capabilities. However, it also means that developers (and users)\n// will only see deployed updates on the \"N+1\" visit to a page, since previously\n// cached resources are updated in the background.\n\n// To learn more about the benefits of this model, read https://goo.gl/KwvDNy.\n// This link also includes instructions on opting out of this behavior.\n\nconst isLocalhost = Boolean(\n  window.location.hostname === 'localhost' ||\n    // [::1] is the IPv6 localhost address.\n    window.location.hostname === '[::1]' ||\n    // 127.0.0.1/8 is considered localhost for IPv4.\n    window.location.hostname.match(\n      /^127(?:\\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/\n    )\n);\n\nexport default function register() {\n  if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {\n    // The URL constructor is available in all browsers that support SW.\n    const publicUrl = new URL(process.env.PUBLIC_URL, window.location);\n    if (publicUrl.origin !== window.location.origin) {\n      // Our service worker won't work if PUBLIC_URL is on a different origin\n      // from what our page is served on. This might happen if a CDN is used to\n      // serve assets; see https://github.com/facebookincubator/create-react-app/issues/2374\n      return;\n    }\n\n    window.addEventListener('load', () => {\n      const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`;\n\n      if (isLocalhost) {\n        // This is running on localhost. Lets check if a service worker still exists or not.\n        checkValidServiceWorker(swUrl);\n      } else {\n        // Is not local host. Just register service worker\n        registerValidSW(swUrl);\n      }\n    });\n  }\n}\n\nfunction registerValidSW(swUrl) {\n  navigator.serviceWorker\n    .register(swUrl)\n    .then(registration => {\n      registration.onupdatefound = () => {\n        const installingWorker = registration.installing;\n        installingWorker.onstatechange = () => {\n          if (installingWorker.state === 'installed') {\n            if (navigator.serviceWorker.controller) {\n              // At this point, the old content will have been purged and\n              // the fresh content will have been added to the cache.\n              // It's the perfect time to display a \"New content is\n              // available; please refresh.\" message in your web app.\n              console.log('New content is available; please refresh.');\n            } else {\n              // At this point, everything has been precached.\n              // It's the perfect time to display a\n              // \"Content is cached for offline use.\" message.\n              console.log('Content is cached for offline use.');\n            }\n          }\n        };\n      };\n    })\n    .catch(error => {\n      console.error('Error during service worker registration:', error);\n    });\n}\n\nfunction checkValidServiceWorker(swUrl) {\n  // Check if the service worker can be found. If it can't reload the page.\n  fetch(swUrl)\n    .then(response => {\n      // Ensure service worker exists, and that we really are getting a JS file.\n      if (\n        response.status === 404 ||\n        response.headers.get('content-type').indexOf('javascript') === -1\n      ) {\n        // No service worker found. Probably a different app. Reload the page.\n        navigator.serviceWorker.ready.then(registration => {\n          registration.unregister().then(() => {\n            window.location.reload();\n          });\n        });\n      } else {\n        // Service worker found. Proceed as normal.\n        registerValidSW(swUrl);\n      }\n    })\n    .catch(() => {\n      console.log(\n        'No internet connection found. App is running in offline mode.'\n      );\n    });\n}\n\nexport function unregister() {\n  if ('serviceWorker' in navigator) {\n    navigator.serviceWorker.ready.then(registration => {\n      registration.unregister();\n    });\n  }\n}\n"
  }
]