🔌 UI for socket connection status

This commit is contained in:
2021-06-01 10:49:48 -07:00
parent 773491429a
commit 69f79c1ece
6 changed files with 48 additions and 43 deletions

View File

@@ -47,6 +47,7 @@ export const fetchComicBookMetadata = (options) => async (dispatch) => {
console.log(`connect ${socket.id}`); console.log(`connect ${socket.id}`);
dispatch({ dispatch({
type: IMS_SOCKET_CONNECTION_CONNECTED, type: IMS_SOCKET_CONNECTION_CONNECTED,
socketConnected: true,
}); });
}); });

View File

@@ -1,5 +1,4 @@
import * as React from "react"; import * as React from "react";
import { IExtractedComicBookCoverFile } from "../../server/interfaces/folder.interface"; import { IExtractedComicBookCoverFile } from "../../server/interfaces/folder.interface";
import { map } from "lodash"; import { map } from "lodash";

View File

@@ -7,11 +7,12 @@ interface IState {}
class Dashboard extends React.Component<IProps, IState> { class Dashboard extends React.Component<IProps, IState> {
public render() { public render() {
return ( return (
<div className="container">
<section className="section"> <section className="section">
<h1 className="title">Dashboard</h1> <h1 className="title">Dashboard</h1>
<h2 className="subtitle"> <h2 className="subtitle">
A simple container to divide your page into <strong>sections</strong>, A simple container to divide your page into{" "}
like the one you're currently reading. <strong>sections</strong>, like the one you're currently reading.
</h2> </h2>
<ZeroState <ZeroState
header={"Set the source directory"} header={"Set the source directory"}
@@ -20,6 +21,7 @@ class Dashboard extends React.Component<IProps, IState> {
} }
/> />
</section> </section>
</div>
); );
} }
} }

View File

@@ -5,6 +5,7 @@ import { fetchComicBookMetadata } from "../actions/fileops.actions";
import { IFolderData } from "../shared/interfaces/comicinfo.interfaces"; import { IFolderData } from "../shared/interfaces/comicinfo.interfaces";
import Card from "./Card"; import Card from "./Card";
import { io, Socket } from "socket.io-client"; import { io, Socket } from "socket.io-client";
import { SOCKET_BASE_URI } from "../constants/endpoints";
interface IProps { interface IProps {
matches: unknown; matches: unknown;
@@ -25,13 +26,6 @@ class Import extends React.Component<IProps, IState> {
folderWalkResults: [], folderWalkResults: [],
searchPaneIndex: undefined, searchPaneIndex: undefined,
}; };
socket = io("ws://localhost:3000/", {
reconnectionDelayMax: 10000,
});
socket.on("connect", () => {
console.log(`connect ${socket.id}`);
});
} }
public toggleSearchResultsPane(paneId: number): void { public toggleSearchResultsPane(paneId: number): void {
@@ -42,6 +36,13 @@ class Import extends React.Component<IProps, IState> {
public initiateSocketConnection = () => { public initiateSocketConnection = () => {
if (typeof this.props.path !== "undefined") { if (typeof this.props.path !== "undefined") {
socket = io(SOCKET_BASE_URI, {
reconnectionDelayMax: 10000,
});
socket.on("connect", () => {
console.log(`connect ${socket.id}`);
});
this.props.fetchComicMetadata(); this.props.fetchComicMetadata();
} }
}; };

View File

@@ -1,7 +1,10 @@
import * as React from "react"; import React from "react";
import { useSelector } from "react-redux";
import { Link } from "react-router-dom"; import { Link } from "react-router-dom";
const Navbar: React.FunctionComponent = (props) => { const Navbar: React.FunctionComponent = (props) => {
const socketConnected = useSelector((state) => state.fileOps);
return ( return (
<nav className="navbar "> <nav className="navbar ">
<div className="navbar-brand"> <div className="navbar-brand">
@@ -14,23 +17,15 @@ const Navbar: React.FunctionComponent = (props) => {
/> />
</a> </a>
<a <a className="navbar-item is-hidden-desktop">
className="navbar-item is-hidden-desktop"
href="https://github.com/jgthms/bulma"
target="_blank"
>
<span className="icon"> <span className="icon">
<i className="fa fa-github"></i> <i className="fas fa-github"></i>
</span> </span>
</a> </a>
<a <a className="navbar-item is-hidden-desktop">
className="navbar-item is-hidden-desktop"
href="https://twitter.com/jgthms"
target="_blank"
>
<span className="icon"> <span className="icon">
<i className="fa fa-twitter"></i> <i className="fas fa-twitter"></i>
</span> </span>
</a> </a>
@@ -87,9 +82,7 @@ const Navbar: React.FunctionComponent = (props) => {
</div> </div>
</div> </div>
<div className="navbar-item has-dropdown is-hoverable is-mega"> <div className="navbar-item has-dropdown is-hoverable is-mega">
<div className="navbar-link flex"> <div className="navbar-link flex">Blog</div>
Blog
</div>
<div id="blogDropdown" className="navbar-dropdown"> <div id="blogDropdown" className="navbar-dropdown">
<div className="container is-fluid"> <div className="container is-fluid">
<div className="columns"> <div className="columns">
@@ -192,14 +185,16 @@ const Navbar: React.FunctionComponent = (props) => {
</div> </div>
<div className="navbar-end"> <div className="navbar-end">
<a <a className="navbar-item is-hidden-desktop-only"></a>
className="navbar-item is-hidden-desktop-only"
href="https://github.com/jgthms/bulma"
target="_blank"
></a>
<div className="navbar-item"> <div className="navbar-item">
<div className="field is-grouped"> <div className="field is-grouped">
<p className="control"></p> <p className="control">
{socketConnected.socketConnected ? (
<span className="icon is-small has-text-success">
<i className="fas fa-plug"></i>
</span>
) : null}
</p>
<p className="control">Settings</p> <p className="control">Settings</p>
</div> </div>
</div> </div>

View File

@@ -7,6 +7,7 @@ import {
const initialState = { const initialState = {
dataTransferred: false, dataTransferred: false,
comicBookMetadata: [], comicBookMetadata: [],
socketConnected: false,
}; };
function fileOpsReducer(state = initialState, action) { function fileOpsReducer(state = initialState, action) {
@@ -17,6 +18,12 @@ function fileOpsReducer(state = initialState, action) {
comicBookMetadata: [...state.comicBookMetadata, action.data.data], comicBookMetadata: [...state.comicBookMetadata, action.data.data],
dataTransferred: true, dataTransferred: true,
}; };
case IMS_SOCKET_CONNECTION_CONNECTED:
return {
...state,
socketConnected: action.socketConnected,
};
default: default:
return state; return state;
} }