From 69f79c1ece3def7b5aa28a64db6d448300dbe044 Mon Sep 17 00:00:00 2001 From: Rishi Ghan Date: Tue, 1 Jun 2021 10:49:48 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=8C=20UI=20for=20socket=20connection?= =?UTF-8?q?=20status?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/client/actions/fileops.actions.tsx | 1 + src/client/components/Card.tsx | 1 - src/client/components/Dashboard.tsx | 28 +++++++++--------- src/client/components/Import.tsx | 15 +++++----- src/client/components/Navbar.tsx | 39 +++++++++++--------------- src/client/reducers/fileops.reducer.ts | 7 +++++ 6 files changed, 48 insertions(+), 43 deletions(-) diff --git a/src/client/actions/fileops.actions.tsx b/src/client/actions/fileops.actions.tsx index 7bb334a..84430c5 100644 --- a/src/client/actions/fileops.actions.tsx +++ b/src/client/actions/fileops.actions.tsx @@ -47,6 +47,7 @@ export const fetchComicBookMetadata = (options) => async (dispatch) => { console.log(`connect ${socket.id}`); dispatch({ type: IMS_SOCKET_CONNECTION_CONNECTED, + socketConnected: true, }); }); diff --git a/src/client/components/Card.tsx b/src/client/components/Card.tsx index 76e29f4..aaf741a 100644 --- a/src/client/components/Card.tsx +++ b/src/client/components/Card.tsx @@ -1,5 +1,4 @@ import * as React from "react"; - import { IExtractedComicBookCoverFile } from "../../server/interfaces/folder.interface"; import { map } from "lodash"; diff --git a/src/client/components/Dashboard.tsx b/src/client/components/Dashboard.tsx index 777addd..ce9ab4f 100644 --- a/src/client/components/Dashboard.tsx +++ b/src/client/components/Dashboard.tsx @@ -7,19 +7,21 @@ interface IState {} class Dashboard extends React.Component { public render() { return ( -
-

Dashboard

-

- A simple container to divide your page into sections, - like the one you're currently reading. -

- -
+
+
+

Dashboard

+

+ A simple container to divide your page into{" "} + sections, like the one you're currently reading. +

+ +
+
); } } diff --git a/src/client/components/Import.tsx b/src/client/components/Import.tsx index c3fc511..89ac8e0 100644 --- a/src/client/components/Import.tsx +++ b/src/client/components/Import.tsx @@ -5,6 +5,7 @@ import { fetchComicBookMetadata } from "../actions/fileops.actions"; import { IFolderData } from "../shared/interfaces/comicinfo.interfaces"; import Card from "./Card"; import { io, Socket } from "socket.io-client"; +import { SOCKET_BASE_URI } from "../constants/endpoints"; interface IProps { matches: unknown; @@ -25,13 +26,6 @@ class Import extends React.Component { folderWalkResults: [], searchPaneIndex: undefined, }; - socket = io("ws://localhost:3000/", { - reconnectionDelayMax: 10000, - }); - - socket.on("connect", () => { - console.log(`connect ${socket.id}`); - }); } public toggleSearchResultsPane(paneId: number): void { @@ -42,6 +36,13 @@ class Import extends React.Component { public initiateSocketConnection = () => { if (typeof this.props.path !== "undefined") { + socket = io(SOCKET_BASE_URI, { + reconnectionDelayMax: 10000, + }); + + socket.on("connect", () => { + console.log(`connect ${socket.id}`); + }); this.props.fetchComicMetadata(); } }; diff --git a/src/client/components/Navbar.tsx b/src/client/components/Navbar.tsx index db2a2ca..9a7b633 100644 --- a/src/client/components/Navbar.tsx +++ b/src/client/components/Navbar.tsx @@ -1,7 +1,10 @@ -import * as React from "react"; +import React from "react"; +import { useSelector } from "react-redux"; import { Link } from "react-router-dom"; const Navbar: React.FunctionComponent = (props) => { + const socketConnected = useSelector((state) => state.fileOps); + return (