diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0d712e8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,24 @@ +# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. + +# dependencies +/node_modules +/.vscode +/.pnp +.pnp.js + +# testing +/coverage + +# production +/build + +# misc +.DS_Store +.env.local +.env.development.local +.env.test.local +.env.production.local + +npm-debug.log* +yarn-debug.log* +yarn-error.log* diff --git a/README.md b/README.md index 1fa7f63..3f4ddea 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,156 @@ -# gi2challenge -Created with CodeSandbox +![The G2i Logo](https://raw.githubusercontent.com/g2i/code-challenge-static-assets/master/g2i-web-150px.png "The G2i logo") + +# Trivia Game Coding Challenge + +## Overview + +Your challenge is to create a 10 question, true or false, trivia app in React Web. **You should not just implement the most basic solution. This is a chance to show off your abilities and impress.** + +**The application code will be reviewed and scored on these key areas with many subset areas for each:** + +- Functionality +- Code Format +- Project Structure +- Scalability +- Maintainability +- Use of industry best practices + +Some specific things that we are looking for: + +- State manager +- Navigation solution +- Componentization +- Communiation in the repo and/or code +- Best practices with API calls and data +- Separation of concerns between business and UI logic + +## Goals + +Implement the screens based off the wireframes, HTML/CSS starter code and api below using **advanced techniques** and **industry best practices** for your platform. Use your best judgment for UI/UX implementation. We have provided boilerplate code for a standard CRA project with Redux. In addition, we have given you some starter HTML and CSS in the designs folder. You can reference those as a starting place for your layout. We want to see how you structure the rest of the project and what tooling you use from here. + +## Specifications + +Layout: + +See the designs folder for basic HTML and CSS already provided + +Data: + +The api url is: https://opentdb.com/api.php?amount=10&difficulty=hard&type=boolean + +Sample returned json: + +```javascript +{ + "response_code": 0, + "results": [ + { + "category": "Entertainment: Video Games", + "type": "boolean", + "difficulty": "hard", + "question": "Unturned originally started as a Roblox game.", + "correct_answer": "True", + "incorrect_answers": [ + "False" + ] + },…]} +``` + +### Intro / Home Screen: + +![The Intro screen for the app](https://raw.githubusercontent.com/g2i/code-challenge-static-assets/master/Intro.png "The intro screen for the app") + +- Static Text +- BEGIN button navigates to the Quiz screen and starts the Quiz + +### Quiz Screen: + +![The Quiz screen for the app](https://raw.githubusercontent.com/g2i/code-challenge-static-assets/master/Quiz.png "The quiz screen for the app") + +- The headline is from question category +- The card element contains the current question +- The next question should appear after the current question is answered True or False +- After all questions have been answered, navigate to the Results Screen + +### Results screen: + +![The Results screen for the app](https://raw.githubusercontent.com/g2i/code-challenge-static-assets/master/Score.png "The score screen for the app") + +- The Score shows correct and total +- Displays a list of the questions and whether the answer was correct or not +- PLAY AGAIN starts over and navigates to the Home Screen + +--- + +© 2018 G2i Inc. All rights reserved. Certain information contained herein is derived from information which is protected by copyrights held by G2i Inc. This code challenge, including any parts of it, cannot be duplicated, distributed, copied, modified, used to make a derivative work or used in any way without the prior written consent of G2i Inc. + +--- + +This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). + +## Available Scripts + +In the project directory, you can run: + +### `npm start` + +Runs the app in the development mode.
+Open [http://localhost:3000](http://localhost:3000) to view it in the browser. + +The page will reload if you make edits.
+You will also see any lint errors in the console. + +### `npm test` + +Launches the test runner in the interactive watch mode.
+See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. + +### `npm run build` + +Builds the app for production to the `build` folder.
+It correctly bundles React in production mode and optimizes the build for the best performance. + +The build is minified and the filenames include the hashes.
+Your app is ready to be deployed! + +See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. + +### `npm run eject` + +**Note: this is a one-way operation. Once you `eject`, you can’t go back!** + +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. + +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. + +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. + +## Learn More + +You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). + +To learn React, check out the [React documentation](https://reactjs.org/). + +### Code Splitting + +This section has moved here: https://facebook.github.io/create-react-app/docs/code-splitting + +### Analyzing the Bundle Size + +This section has moved here: https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size + +### Making a Progressive Web App + +This section has moved here: https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app + +### Advanced Configuration + +This section has moved here: https://facebook.github.io/create-react-app/docs/advanced-configuration + +### Deployment + +This section has moved here: https://facebook.github.io/create-react-app/docs/deployment + +### `npm run build` fails to minify + +This section has moved here: https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify diff --git a/package.json b/package.json new file mode 100644 index 0000000..182928d --- /dev/null +++ b/package.json @@ -0,0 +1,28 @@ +{ + "name": "g2i-code-challenge-web-template", + "version": "0.1.0", + "private": true, + "dependencies": { + "react": "^16.8.3", + "react-dom": "^16.8.3", + "react-icons": "^3.4.0", + "react-redux": "^6.0.1", + "react-scripts": "2.1.5", + "redux": "^4.0.1" + }, + "scripts": { + "start": "react-scripts start", + "build": "react-scripts build", + "test": "react-scripts test", + "eject": "react-scripts eject" + }, + "eslintConfig": { + "extends": "react-app" + }, + "browserslist": [ + ">0.2%", + "not dead", + "not ie <= 11", + "not op_mini all" + ] +} diff --git a/public/favicon.ico b/public/favicon.ico new file mode 100644 index 0000000..a11777c Binary files /dev/null and b/public/favicon.ico differ diff --git a/public/index.html b/public/index.html new file mode 100644 index 0000000..75980d5 --- /dev/null +++ b/public/index.html @@ -0,0 +1,41 @@ + + + + + + + + + + + React App + + + +
+ + + diff --git a/public/manifest.json b/public/manifest.json new file mode 100644 index 0000000..1f2f141 --- /dev/null +++ b/public/manifest.json @@ -0,0 +1,15 @@ +{ + "short_name": "React App", + "name": "Create React App Sample", + "icons": [ + { + "src": "favicon.ico", + "sizes": "64x64 32x32 24x24 16x16", + "type": "image/x-icon" + } + ], + "start_url": ".", + "display": "standalone", + "theme_color": "#000000", + "background_color": "#ffffff" +} diff --git a/src/App.css b/src/App.css new file mode 100644 index 0000000..b41d297 --- /dev/null +++ b/src/App.css @@ -0,0 +1,33 @@ +.App { + text-align: center; +} + +.App-logo { + animation: App-logo-spin infinite 20s linear; + height: 40vmin; + pointer-events: none; +} + +.App-header { + background-color: #282c34; + min-height: 100vh; + display: flex; + flex-direction: column; + align-items: center; + justify-content: center; + font-size: calc(10px + 2vmin); + color: white; +} + +.App-link { + color: #61dafb; +} + +@keyframes App-logo-spin { + from { + transform: rotate(0deg); + } + to { + transform: rotate(360deg); + } +} diff --git a/src/App.js b/src/App.js new file mode 100644 index 0000000..0cf5a31 --- /dev/null +++ b/src/App.js @@ -0,0 +1,17 @@ +import React, { Component } from "react"; +import Home from "./screens/home"; +import "./App.css"; +import { store } from "./redux"; +import { Provider } from "react-redux"; + +class App extends Component { + render() { + return ( + + + + ); + } +} + +export default App; diff --git a/src/App.test.js b/src/App.test.js new file mode 100644 index 0000000..a754b20 --- /dev/null +++ b/src/App.test.js @@ -0,0 +1,9 @@ +import React from 'react'; +import ReactDOM from 'react-dom'; +import App from './App'; + +it('renders without crashing', () => { + const div = document.createElement('div'); + ReactDOM.render(, div); + ReactDOM.unmountComponentAtNode(div); +}); diff --git a/src/designs/app.css b/src/designs/app.css new file mode 100644 index 0000000..676b662 --- /dev/null +++ b/src/designs/app.css @@ -0,0 +1,33 @@ +/*Classes*/ +.button { + font-size: 20px; + padding: 5px; +} + +.container { + display: flex; + flex-flow: column; + align-items: center; + justify-content: center; +} + +.list-item { + display: flex; + align-items: center; +} + +/*IDs*/ +#box { + display: flex; + justify-content: center; + align-items: center; + border: solid 1px black; + width: 400px; + height: 400px; +} +#list { + list-style: none; +} +#question { + text-align: center; +} diff --git a/src/designs/home.html b/src/designs/home.html new file mode 100644 index 0000000..d1eab55 --- /dev/null +++ b/src/designs/home.html @@ -0,0 +1,14 @@ + + + + + + +
+

Welcome to the Trivia Challenge!

+

You will be presented with 10 True or False questions.

+

Can you score 100%?

+ +
+ + diff --git a/src/designs/quiz.html b/src/designs/quiz.html new file mode 100644 index 0000000..4dad2dd --- /dev/null +++ b/src/designs/quiz.html @@ -0,0 +1,17 @@ + + + + + + +
+

Entertainment: Video Games

+
+

}> Unturned originally started as a Roblox game.

+
+

1 of 10

+ + +
+ + diff --git a/src/designs/results.html b/src/designs/results.html new file mode 100644 index 0000000..656d40b --- /dev/null +++ b/src/designs/results.html @@ -0,0 +1,66 @@ + + + + + + + +
+

You scored

+

3/10

+ + +
+ + diff --git a/src/designs/wireframes/Home.png b/src/designs/wireframes/Home.png new file mode 100644 index 0000000..87e24d9 Binary files /dev/null and b/src/designs/wireframes/Home.png differ diff --git a/src/designs/wireframes/Quiz.png b/src/designs/wireframes/Quiz.png new file mode 100644 index 0000000..079ab0b Binary files /dev/null and b/src/designs/wireframes/Quiz.png differ diff --git a/src/designs/wireframes/Results.png b/src/designs/wireframes/Results.png new file mode 100644 index 0000000..82c5b79 Binary files /dev/null and b/src/designs/wireframes/Results.png differ diff --git a/src/index.css b/src/index.css new file mode 100644 index 0000000..cee5f34 --- /dev/null +++ b/src/index.css @@ -0,0 +1,14 @@ +body { + margin: 0; + padding: 0; + font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", + "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", + sans-serif; + -webkit-font-smoothing: antialiased; + -moz-osx-font-smoothing: grayscale; +} + +code { + font-family: source-code-pro, Menlo, Monaco, Consolas, "Courier New", + monospace; +} diff --git a/src/index.js b/src/index.js new file mode 100644 index 0000000..0c5e75d --- /dev/null +++ b/src/index.js @@ -0,0 +1,12 @@ +import React from 'react'; +import ReactDOM from 'react-dom'; +import './index.css'; +import App from './App'; +import * as serviceWorker from './serviceWorker'; + +ReactDOM.render(, document.getElementById('root')); + +// If you want your app to work offline and load faster, you can change +// unregister() to register() below. Note this comes with some pitfalls. +// Learn more about service workers: http://bit.ly/CRA-PWA +serviceWorker.unregister(); diff --git a/src/logo.svg b/src/logo.svg new file mode 100644 index 0000000..6b60c10 --- /dev/null +++ b/src/logo.svg @@ -0,0 +1,7 @@ + + + + + + + diff --git a/src/redux/index.js b/src/redux/index.js new file mode 100644 index 0000000..0a724c1 --- /dev/null +++ b/src/redux/index.js @@ -0,0 +1,3 @@ +import store from "./reducers"; + +export { store }; diff --git a/src/redux/reducers/index.js b/src/redux/reducers/index.js new file mode 100644 index 0000000..cb3eb1c --- /dev/null +++ b/src/redux/reducers/index.js @@ -0,0 +1,7 @@ +import { createStore, combineReducers } from "redux"; + +const root = combineReducers({}); + +const store = createStore(root); + +export default store; diff --git a/src/screens/home.js b/src/screens/home.js new file mode 100644 index 0000000..fcf6ffb --- /dev/null +++ b/src/screens/home.js @@ -0,0 +1,5 @@ +import React from "react"; + +const Home = () => null; + +export default Home; diff --git a/src/screens/quiz.js b/src/screens/quiz.js new file mode 100644 index 0000000..e09150a --- /dev/null +++ b/src/screens/quiz.js @@ -0,0 +1,5 @@ +import React from "react"; + +const Quiz = () => null; + +export default Quiz; diff --git a/src/screens/results.js b/src/screens/results.js new file mode 100644 index 0000000..3406dac --- /dev/null +++ b/src/screens/results.js @@ -0,0 +1,6 @@ +import React from "react"; +import { FaPlus, FaMinus } from "react-icons/fa"; + +const Results = () => null; + +export default Results; diff --git a/src/serviceWorker.js b/src/serviceWorker.js new file mode 100644 index 0000000..2283ff9 --- /dev/null +++ b/src/serviceWorker.js @@ -0,0 +1,135 @@ +// This optional code is used to register a service worker. +// register() is not called by default. + +// This lets the app load faster on subsequent visits in production, and gives +// it offline capabilities. However, it also means that developers (and users) +// will only see deployed updates on subsequent visits to a page, after all the +// existing tabs open on the page have been closed, since previously cached +// resources are updated in the background. + +// To learn more about the benefits of this model and instructions on how to +// opt-in, read http://bit.ly/CRA-PWA + +const isLocalhost = Boolean( + window.location.hostname === 'localhost' || + // [::1] is the IPv6 localhost address. + window.location.hostname === '[::1]' || + // 127.0.0.1/8 is considered localhost for IPv4. + window.location.hostname.match( + /^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/ + ) +); + +export function register(config) { + if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) { + // The URL constructor is available in all browsers that support SW. + const publicUrl = new URL(process.env.PUBLIC_URL, window.location.href); + if (publicUrl.origin !== window.location.origin) { + // Our service worker won't work if PUBLIC_URL is on a different origin + // from what our page is served on. This might happen if a CDN is used to + // serve assets; see https://github.com/facebook/create-react-app/issues/2374 + return; + } + + window.addEventListener('load', () => { + const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`; + + if (isLocalhost) { + // This is running on localhost. Let's check if a service worker still exists or not. + checkValidServiceWorker(swUrl, config); + + // Add some additional logging to localhost, pointing developers to the + // service worker/PWA documentation. + navigator.serviceWorker.ready.then(() => { + console.log( + 'This web app is being served cache-first by a service ' + + 'worker. To learn more, visit http://bit.ly/CRA-PWA' + ); + }); + } else { + // Is not localhost. Just register service worker + registerValidSW(swUrl, config); + } + }); + } +} + +function registerValidSW(swUrl, config) { + navigator.serviceWorker + .register(swUrl) + .then(registration => { + registration.onupdatefound = () => { + const installingWorker = registration.installing; + if (installingWorker == null) { + return; + } + installingWorker.onstatechange = () => { + if (installingWorker.state === 'installed') { + if (navigator.serviceWorker.controller) { + // At this point, the updated precached content has been fetched, + // but the previous service worker will still serve the older + // content until all client tabs are closed. + console.log( + 'New content is available and will be used when all ' + + 'tabs for this page are closed. See http://bit.ly/CRA-PWA.' + ); + + // Execute callback + if (config && config.onUpdate) { + config.onUpdate(registration); + } + } else { + // At this point, everything has been precached. + // It's the perfect time to display a + // "Content is cached for offline use." message. + console.log('Content is cached for offline use.'); + + // Execute callback + if (config && config.onSuccess) { + config.onSuccess(registration); + } + } + } + }; + }; + }) + .catch(error => { + console.error('Error during service worker registration:', error); + }); +} + +function checkValidServiceWorker(swUrl, config) { + // Check if the service worker can be found. If it can't reload the page. + fetch(swUrl) + .then(response => { + // Ensure service worker exists, and that we really are getting a JS file. + const contentType = response.headers.get('content-type'); + if ( + response.status === 404 || + (contentType != null && contentType.indexOf('javascript') === -1) + ) { + // No service worker found. Probably a different app. Reload the page. + navigator.serviceWorker.ready.then(registration => { + registration.unregister().then(() => { + window.location.reload(); + }); + }); + } else { + // Service worker found. Proceed as normal. + registerValidSW(swUrl, config); + } + }) + .catch(() => { + console.log( + 'No internet connection found. App is running in offline mode.' + ); + }); +} + +export function unregister() { + if ('serviceWorker' in navigator) { + navigator.serviceWorker.ready.then(registration => { + registration.unregister(); + }); + } +}