Skip to content

Commit

Permalink
Restyled by prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
restyled-commits committed Aug 29, 2020
1 parent a9c7985 commit 273b3ec
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 74 deletions.
8 changes: 3 additions & 5 deletions malarial-detection/src/components/router/router.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import React from "react";
import {BrowserRouter, Route, Switch} from "react-router-dom";
import { BrowserRouter, Route, Switch } from "react-router-dom";

const Router = () => (
<BrowserRouter>
<Switch>
<Route path="/about" component={
About} />
<Route path="/about" component={About} />
<Route path="/users " component={Users} />
<Route path="/" component={
Home} />
<Route path="/" component={Home} />
</Switch>
</BrowserRouter>
);
Expand Down
10 changes: 7 additions & 3 deletions malarial-detection/src/pages/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@ import Router from "components/router/router";
import React from "react";

function App() {
return (<div className = "App"><header className = "App-header"><Router />
</header>
</div>);
return (
<div className="App">
<header className="App-header">
<Router />
</header>
</div>
);
}

export default App;
4 changes: 2 additions & 2 deletions malarial-detection/src/pages/App.test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {render} from "@testing-library/react";
import { render } from "@testing-library/react";
import React from "react";

import App from "./App";

test("renders learn react link", () => {
const {getByText} = render(<App />);
const { getByText } = render(<App />);
const linkElement = getByText(/learn react/i);
expect(linkElement).toBeInTheDocument();
});
143 changes: 79 additions & 64 deletions malarial-detection/src/pages/serviceWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@
// To learn more about the benefits of this model and instructions on how to
// opt-in, read https://bit.ly/CRA-PWA

const isLocalhost =
Boolean(window.location.hostname === "localhost" ||
// [::1] is the IPv6 localhost address.
window.location.hostname === "[::1]" ||
// 127.0.0.0/8 are considered localhost for IPv4.
window.location.hostname.match(
/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/));
const isLocalhost = Boolean(
window.location.hostname === "localhost" ||
// [::1] is the IPv6 localhost address.
window.location.hostname === "[::1]" ||
// 127.0.0.0/8 are 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) {
Expand All @@ -41,8 +43,10 @@ export function register(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 https://bit.ly/CRA-PWA");
console.log(
"This web app is being served cache-first by a service " +
"worker. To learn more, visit https://bit.ly/CRA-PWA"
);
});
} else {
// Is not localhost. Just register service worker
Expand All @@ -53,77 +57,88 @@ export function register(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 https://bit.ly/CRA-PWA.");
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 https://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.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);
}
// Execute callback
if (config && config.onSuccess) {
config.onSuccess(registration);
}
}
};
}
};
})
.catch((error) => {
console.error("Error during service worker registration:", error);
});
};
})
.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, {
headers : {"Service-Worker" : "script"},
headers: { "Service-Worker": "script" },
})
.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(); });
.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.");
});
});
} 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(); })
.catch((error) => { console.error(error.message); });
.then((registration) => {
registration.unregister();
})
.catch((error) => {
console.error(error.message);
});
}
}

0 comments on commit 273b3ec

Please sign in to comment.