}
60 |
61 | )}
62 |
63 | )
64 | }
65 |
66 | export default CardsByPage
67 |
--------------------------------------------------------------------------------
/src/serviceWorker.js:
--------------------------------------------------------------------------------
1 | const isLocalhost = Boolean(
2 | window.location.hostname === 'localhost' ||
3 | window.location.hostname === '[::1]' ||
4 | window.location.hostname.match(
5 | /^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/
6 | )
7 | )
8 |
9 | export function register(config) {
10 | if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {
11 | const publicUrl = new URL(process.env.PUBLIC_URL, window.location.href)
12 | if (publicUrl.origin !== window.location.origin) {return}
13 |
14 | window.addEventListener('load', () => {
15 | const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`
16 |
17 | if (isLocalhost) {
18 | checkValidServiceWorker(swUrl, config)
19 | navigator.serviceWorker.ready.then(() => {
20 | console.log('This web app is being served cache-first by a service worker. To learn more, visit http://bit.ly/CRA-PWA')
21 | })
22 | } else {
23 | registerValidSW(swUrl, config)
24 | }
25 | })
26 | }
27 | }
28 |
29 | function registerValidSW(swUrl, config) {
30 | navigator.serviceWorker
31 | .register(swUrl)
32 | .then(registration => {
33 | registration.onupdatefound = () => {
34 | const installingWorker = registration.installing
35 | if (installingWorker == null) {return}
36 | installingWorker.onstatechange = () => {
37 | if (installingWorker.state === 'installed') {
38 | if (navigator.serviceWorker.controller) {
39 | console.log('New content is available and will be used when all tabs for this page are closed. See http://bit.ly/CRA-PWA.')
40 | if (config && config.onUpdate) {
41 | config.onUpdate(registration)
42 | }
43 | } else {
44 | console.log('Content is cached for offline use.')
45 | if (config && config.onSuccess) {config.onSuccess(registration)}
46 | }
47 | }
48 | }
49 | }
50 | })
51 | .catch(error => {
52 | console.error('Error during service worker registration:', error)
53 | })
54 | }
55 |
56 | function checkValidServiceWorker(swUrl, config) {
57 | fetch(swUrl)
58 | .then(response => {
59 | const contentType = response.headers.get('content-type')
60 | if (
61 | response.status === 404 ||
62 | (contentType != null && contentType.indexOf('javascript') === -1)
63 | ) {
64 | navigator.serviceWorker.ready.then(registration => {
65 | registration.unregister().then(() => {
66 | window.location.reload()
67 | })
68 | })
69 | } else {registerValidSW(swUrl, config)}
70 | })
71 | .catch(() => {
72 | console.log('No internet connection found. App is running in offline mode.')
73 | })
74 | }
75 |
76 | export function unregister() {
77 | if ('serviceWorker' in navigator) {
78 | navigator.serviceWorker.ready.then(registration => {
79 | registration.unregister()
80 | })
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Movies react-app for movie related search
2 |
3 | [![netlify status][netlify-badge]][netlify-url]
4 |
5 | [](https://movies.vitordino.com)
6 |
7 | **This repo contains all the code for the [movies.vitordino.com](https://movies.vitordino.com) app.**
8 |
9 | this project is built upon [significa/frontend-challenge](https://github.com/Significa/frontend-challenge/), all design credits go for them.
10 |
11 | This product uses the [TMDb](https://www.themoviedb.org/) API but is not endorsed or certified by TMDb.
12 |
13 |
14 |
15 |
16 | ## Development Quick Start
17 |
18 | > Make sure your system meets the [required dependencies and versions](#system-dependencies) before proceeding.
19 |
20 | > Get one [themoviedb.org](https://themoviedb.org/documentation/api) API key, and set it as a environment variable named REACT_APP_TMDB_KEY (you can use a `.env.local` file for that)
21 |
22 |
23 | ```bash
24 | # Install project dependencies
25 | $ yarn
26 |
27 | # Development server
28 | $ yarn dev # starts dev server
29 |
30 | # Build app
31 | $ yarn build # Outputs to ./build directory
32 | $ npx serve build # Static server for the built website
33 | ```
34 |
35 |
36 |
37 | **Development Server Options**
38 |
39 | To change the port set the **`PORT`** environment variable:
40 |
41 | ```bash
42 | $ PORT=9000 yarn dev
43 | # => starts server at http://localhost:9000
44 | ```
45 |
46 |
47 |
48 | ## Tech Stack
49 |
50 | #### Key Front-End Packages
51 |
52 | | name | license | description |
53 | | :-- | :-: | :-- |
54 | | [`react`](https://reactjs.org/) | [`MIT`](https://api.github.com/repos/facebook/react/license) | Declarative, component-based, functional aproach to user interfaces |
55 | | [`create-react-app` `v2`](https://github.com/facebook/create-react-app) | [`MIT`](https://api.github.com/repos/facebook/create-react-app/license) | create `react` apps with no build configuration. |
56 | | [`styled-components`](https://styled-components.com/) | [`MIT`](https://api.github.com/repos/styled-components/styled-components/license) | `css-in-js` library, composable styling |
57 | | [`@reach/router`](https://reach.tech/router) | [`MIT`](https://api.github.com/repos/reach/router/license) | Next Generation Routing for `react` |
58 | | [`rescripts`](https://github.com/harrysolovay/rescripts) | [`MIT`](https://api.github.com/repos/harrysolovay/rescripts/license) | Use the latest react-scripts with custom configurations for Babel, ESLint, TSLint, Webpack,... ∞ |
59 | | [`react-snap`](https://github.com/stereobooster/react-snap) | [`MIT`](https://api.github.com/repos/stereobooster/react-snap/license) | Zero-configuration framework-agnostic static prerendering for SPAs |
60 |
61 |
62 |
63 | This app is heavily built on react new features — eg.: `hooks`, `lazy` and `Suspense`.
64 |
65 |