Skip to content

Commit 3d5d31f

Browse files
committed
Release v0.1.14
1 parent 2ad9e7e commit 3d5d31f

File tree

6 files changed

+222
-16
lines changed

6 files changed

+222
-16
lines changed

Diff for: package-lock.json

+135
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "niwder-ui",
3-
"version": "0.1.13",
3+
"version": "0.1.14",
44
"private": true,
55
"dependencies": {
66
"@emotion/react": "^11.8.2",
@@ -44,6 +44,7 @@
4444
"redux-routines": "^3.0.6",
4545
"redux-thunk": "^2.4.1",
4646
"reselect": "^4.1.5",
47+
"socket.io-client": "^4.5.0",
4748
"stream-browserify": "^3.0.0",
4849
"stream-http": "^3.2.0",
4950
"url": "^0.11.0",

Diff for: public/firebase-messaging-sw.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,15 @@ try {
1010
"https://www.gstatic.com/firebasejs/9.6.10/firebase-messaging-compat.js"
1111
);
1212

13-
firebase.initializeApp();
13+
firebase.initializeApp({
14+
apiKey: "AIzaSyBmfOnN-L1e8AyfDdrWbnzV9Z5Vv4W7wNE",
15+
authDomain: "niwder-io.firebaseapp.com",
16+
databaseURL: "https://niwder-io-default-rtdb.firebaseio.com",
17+
projectId: "niwder-io",
18+
storageBucket: "niwder-io.appspot.com",
19+
messagingSenderId: "262286132985",
20+
appId: "1:262286132985:web:0e54a950650e7513a8c428",
21+
});
1422
}
1523

1624
if (firebase.messaging.isSupported()) {

Diff for: src/config/index.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ if (firebase.messaging.isSupported()) {
2121
}
2222

2323
export const API_BASE =
24-
process.env.NODE_ENV === "development" ? "" : "https://niwder-api.niweera.gq";
24+
process.env.NODE_ENV === "development"
25+
? "http://localhost:9091"
26+
: "https://niwder-api.niweera.gq";
2527
export const FCM_VAPID_KEY = process.env.REACT_APP_FCM_VAPID_KEY;
2628
export const messaging = firebaseMessaging;
2729

Diff for: src/helpers/Notification.js

+14-12
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,20 @@ const Notification = ({
2828
{...rest}
2929
>
3030
{alertTitle && <AlertTitle>{alertTitle}</AlertTitle>}
31-
<Typography
32-
sx={{
33-
display: "inline-block",
34-
maxWidth: "40vw",
35-
}}
36-
component="span"
37-
variant="body2"
38-
color="text.primary"
39-
noWrap
40-
>
41-
{message}
42-
</Typography>
31+
{message && (
32+
<Typography
33+
sx={{
34+
display: "inline-block",
35+
maxWidth: "40vw",
36+
}}
37+
component="span"
38+
variant="body2"
39+
color="text.primary"
40+
noWrap
41+
>
42+
{message}
43+
</Typography>
44+
)}
4345
</Alert>
4446
</Snackbar>
4547
);

Diff for: src/routes.js

+59-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from "react";
1+
import React, { useEffect, useState } from "react";
22
import { BrowserRouter as Router, Route, Routes } from "react-router-dom";
33
import Home from "./components/Home";
44
import Container from "@mui/material/Container";
@@ -37,6 +37,10 @@ import {
3737
TORRENTS_TO_GDRIVE_ROUTE,
3838
TORRENTS_TO_MEGA_ROUTE,
3939
} from "./config/Constants";
40+
import { io } from "socket.io-client";
41+
import { get } from "lodash";
42+
import { API_BASE } from "./config";
43+
import Message from "./helpers/Notification";
4044

4145
const AuthIsLoaded = ({ children }) => {
4246
const profile = useSelector(({ firebase: { profile } }) => profile);
@@ -49,10 +53,64 @@ const AuthIsLoaded = ({ children }) => {
4953
};
5054

5155
const RoutesComponent = () => {
56+
const [time, setTime] = useState(0);
57+
const [connected, setConnected] = useState(null);
58+
const [disconnected, setDisconnected] = useState(null);
59+
60+
const accessToken = useSelector(({ firebase: { auth } }) =>
61+
get(auth, "stsTokenManager.accessToken", "")
62+
);
63+
64+
useEffect(() => {
65+
if (accessToken) {
66+
const socket = io(API_BASE, {
67+
transports: ["websocket", "polling"],
68+
});
69+
70+
socket.on("api-alive", () => {
71+
setConnected(true);
72+
setDisconnected(false);
73+
});
74+
75+
socket.on("connect_error", () => {
76+
setConnected(false);
77+
setDisconnected(true);
78+
setTime(1);
79+
});
80+
}
81+
}, [accessToken]);
82+
83+
const onNotificationClose = (event, reason) => {
84+
if (reason === "clickaway") {
85+
return;
86+
}
87+
setConnected(null);
88+
setDisconnected(null);
89+
};
90+
5291
return (
5392
<Router>
5493
<AuthIsLoaded>
5594
<Navbar />
95+
{Boolean(time) && Boolean(connected) && (
96+
<Message
97+
severity={"success"}
98+
alertTitle={`Connected to Niwder-API`}
99+
onClose={onNotificationClose}
100+
message={"Connection is restored to Niwder-API."}
101+
open={connected}
102+
autoHideDuration={5000}
103+
/>
104+
)}
105+
{Boolean(disconnected) && (
106+
<Message
107+
severity={"error"}
108+
alertTitle={`Niwder-API is unreachable`}
109+
message={"Either you are offline or Niwder-API is down."}
110+
open={disconnected}
111+
autoHideDuration={5000}
112+
/>
113+
)}
56114
<Container maxWidth={false}>
57115
<Routes>
58116
<Route exact path={"/"} element={<Home />} />

0 commit comments

Comments
 (0)