Skip to content

Commit 273b3ec

Browse files
Restyled by prettier
1 parent a9c7985 commit 273b3ec

File tree

4 files changed

+91
-74
lines changed

4 files changed

+91
-74
lines changed

malarial-detection/src/components/router/router.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
import React from "react";
2-
import {BrowserRouter, Route, Switch} from "react-router-dom";
2+
import { BrowserRouter, Route, Switch } from "react-router-dom";
33

44
const Router = () => (
55
<BrowserRouter>
66
<Switch>
7-
<Route path="/about" component={
8-
About} />
7+
<Route path="/about" component={About} />
98
<Route path="/users " component={Users} />
10-
<Route path="/" component={
11-
Home} />
9+
<Route path="/" component={Home} />
1210
</Switch>
1311
</BrowserRouter>
1412
);

malarial-detection/src/pages/App.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,13 @@ import Router from "components/router/router";
44
import React from "react";
55

66
function App() {
7-
return (<div className = "App"><header className = "App-header"><Router />
8-
</header>
9-
</div>);
7+
return (
8+
<div className="App">
9+
<header className="App-header">
10+
<Router />
11+
</header>
12+
</div>
13+
);
1014
}
1115

1216
export default App;
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import {render} from "@testing-library/react";
1+
import { render } from "@testing-library/react";
22
import React from "react";
33

44
import App from "./App";
55

66
test("renders learn react link", () => {
7-
const {getByText} = render(<App />);
7+
const { getByText } = render(<App />);
88
const linkElement = getByText(/learn react/i);
99
expect(linkElement).toBeInTheDocument();
1010
});

malarial-detection/src/pages/serviceWorker.js

Lines changed: 79 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@
1010
// To learn more about the benefits of this model and instructions on how to
1111
// opt-in, read https://bit.ly/CRA-PWA
1212

13-
const isLocalhost =
14-
Boolean(window.location.hostname === "localhost" ||
15-
// [::1] is the IPv6 localhost address.
16-
window.location.hostname === "[::1]" ||
17-
// 127.0.0.0/8 are 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}$/));
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.0/8 are 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+
);
2022

2123
export function register(config) {
2224
if (process.env.NODE_ENV === "production" && "serviceWorker" in navigator) {
@@ -41,8 +43,10 @@ export function register(config) {
4143
// Add some additional logging to localhost, pointing developers to the
4244
// service worker/PWA documentation.
4345
navigator.serviceWorker.ready.then(() => {
44-
console.log("This web app is being served cache-first by a service " +
45-
"worker. To learn more, visit https://bit.ly/CRA-PWA");
46+
console.log(
47+
"This web app is being served cache-first by a service " +
48+
"worker. To learn more, visit https://bit.ly/CRA-PWA"
49+
);
4650
});
4751
} else {
4852
// Is not localhost. Just register service worker
@@ -53,77 +57,88 @@ export function register(config) {
5357
}
5458

5559
function registerValidSW(swUrl, config) {
56-
navigator.serviceWorker.register(swUrl)
57-
.then((registration) => {
58-
registration.onupdatefound = () => {
59-
const installingWorker = registration.installing;
60-
if (installingWorker == null) {
61-
return;
62-
}
63-
installingWorker.onstatechange = () => {
64-
if (installingWorker.state === "installed") {
65-
if (navigator.serviceWorker.controller) {
66-
// At this point, the updated precached content has been
67-
// fetched, but the previous service worker will still serve the
68-
// older content until all client tabs are closed.
69-
console.log(
70-
"New content is available and will be used when all " +
71-
"tabs for this page are closed. See https://bit.ly/CRA-PWA.");
60+
navigator.serviceWorker
61+
.register(swUrl)
62+
.then((registration) => {
63+
registration.onupdatefound = () => {
64+
const installingWorker = registration.installing;
65+
if (installingWorker == null) {
66+
return;
67+
}
68+
installingWorker.onstatechange = () => {
69+
if (installingWorker.state === "installed") {
70+
if (navigator.serviceWorker.controller) {
71+
// At this point, the updated precached content has been
72+
// fetched, but the previous service worker will still serve the
73+
// older content until all client tabs are closed.
74+
console.log(
75+
"New content is available and will be used when all " +
76+
"tabs for this page are closed. See https://bit.ly/CRA-PWA."
77+
);
7278

73-
// Execute callback
74-
if (config && config.onUpdate) {
75-
config.onUpdate(registration);
76-
}
77-
} else {
78-
// At this point, everything has been precached.
79-
// It's the perfect time to display a
80-
// "Content is cached for offline use." message.
81-
console.log("Content is cached for offline use.");
79+
// Execute callback
80+
if (config && config.onUpdate) {
81+
config.onUpdate(registration);
82+
}
83+
} else {
84+
// At this point, everything has been precached.
85+
// It's the perfect time to display a
86+
// "Content is cached for offline use." message.
87+
console.log("Content is cached for offline use.");
8288

83-
// Execute callback
84-
if (config && config.onSuccess) {
85-
config.onSuccess(registration);
86-
}
89+
// Execute callback
90+
if (config && config.onSuccess) {
91+
config.onSuccess(registration);
8792
}
8893
}
89-
};
94+
}
9095
};
91-
})
92-
.catch((error) => {
93-
console.error("Error during service worker registration:", error);
94-
});
96+
};
97+
})
98+
.catch((error) => {
99+
console.error("Error during service worker registration:", error);
100+
});
95101
}
96102

97103
function checkValidServiceWorker(swUrl, config) {
98104
// Check if the service worker can be found. If it can't reload the page.
99105
fetch(swUrl, {
100-
headers : {"Service-Worker" : "script"},
106+
headers: { "Service-Worker": "script" },
101107
})
102-
.then((response) => {
103-
// Ensure service worker exists, and that we really are getting a JS
104-
// file.
105-
const contentType = response.headers.get("content-type");
106-
if (response.status === 404 ||
107-
(contentType != null && contentType.indexOf("javascript") === -1)) {
108-
// No service worker found. Probably a different app. Reload the page.
109-
navigator.serviceWorker.ready.then((registration) => {
110-
registration.unregister().then(() => { window.location.reload(); });
108+
.then((response) => {
109+
// Ensure service worker exists, and that we really are getting a JS
110+
// file.
111+
const contentType = response.headers.get("content-type");
112+
if (
113+
response.status === 404 ||
114+
(contentType != null && contentType.indexOf("javascript") === -1)
115+
) {
116+
// No service worker found. Probably a different app. Reload the page.
117+
navigator.serviceWorker.ready.then((registration) => {
118+
registration.unregister().then(() => {
119+
window.location.reload();
111120
});
112-
} else {
113-
// Service worker found. Proceed as normal.
114-
registerValidSW(swUrl, config);
115-
}
116-
})
117-
.catch(() => {
118-
console.log(
119-
"No internet connection found. App is running in offline mode.");
120-
});
121+
});
122+
} else {
123+
// Service worker found. Proceed as normal.
124+
registerValidSW(swUrl, config);
125+
}
126+
})
127+
.catch(() => {
128+
console.log(
129+
"No internet connection found. App is running in offline mode."
130+
);
131+
});
121132
}
122133

123134
export function unregister() {
124135
if ("serviceWorker" in navigator) {
125136
navigator.serviceWorker.ready
126-
.then((registration) => { registration.unregister(); })
127-
.catch((error) => { console.error(error.message); });
137+
.then((registration) => {
138+
registration.unregister();
139+
})
140+
.catch((error) => {
141+
console.error(error.message);
142+
});
128143
}
129144
}

0 commit comments

Comments
 (0)