Skip to content

Commit a9c7985

Browse files
Restyled by clang-format
1 parent 82a0baf commit a9c7985

File tree

4 files changed

+76
-92
lines changed

4 files changed

+76
-92
lines changed

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
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={About} />
7+
<Route path="/about" component={
8+
About} />
89
<Route path="/users " component={Users} />
9-
<Route path="/" component={Home} />
10+
<Route path="/" component={
11+
Home} />
1012
</Switch>
1113
</BrowserRouter>
1214
);
Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
import "pages/App.css";
2-
import React from "react";
2+
33
import Router from "components/router/router";
4+
import React from "react";
45

56
function App() {
6-
return (
7-
<div className="App">
8-
<header className="App-header">
9-
<Router />
10-
</header>
11-
</div>
12-
);
7+
return (<div className = "App"><header className = "App-header"><Router />
8+
</header>
9+
</div>);
1310
}
1411

1512
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: 64 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,13 @@
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 = 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-
);
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}$/));
2220

2321
export function register(config) {
2422
if (process.env.NODE_ENV === "production" && "serviceWorker" in navigator) {
@@ -43,10 +41,8 @@ export function register(config) {
4341
// Add some additional logging to localhost, pointing developers to the
4442
// service worker/PWA documentation.
4543
navigator.serviceWorker.ready.then(() => {
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-
);
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");
5046
});
5147
} else {
5248
// Is not localhost. Just register service worker
@@ -57,88 +53,77 @@ export function register(config) {
5753
}
5854

5955
function registerValidSW(swUrl, config) {
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-
);
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.");
7872

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.");
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.");
8882

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

10397
function checkValidServiceWorker(swUrl, config) {
10498
// Check if the service worker can be found. If it can't reload the page.
10599
fetch(swUrl, {
106-
headers: { "Service-Worker": "script" },
100+
headers : {"Service-Worker" : "script"},
107101
})
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();
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(); });
120111
});
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-
});
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+
});
132121
}
133122

134123
export function unregister() {
135124
if ("serviceWorker" in navigator) {
136125
navigator.serviceWorker.ready
137-
.then((registration) => {
138-
registration.unregister();
139-
})
140-
.catch((error) => {
141-
console.error(error.message);
142-
});
126+
.then((registration) => { registration.unregister(); })
127+
.catch((error) => { console.error(error.message); });
143128
}
144129
}

0 commit comments

Comments
 (0)