🔌 UI for socket connection status
This commit is contained in:
@@ -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,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -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";
|
||||||
|
|
||||||
|
|||||||
@@ -7,19 +7,21 @@ interface IState {}
|
|||||||
class Dashboard extends React.Component<IProps, IState> {
|
class Dashboard extends React.Component<IProps, IState> {
|
||||||
public render() {
|
public render() {
|
||||||
return (
|
return (
|
||||||
<section className="section">
|
<div className="container">
|
||||||
<h1 className="title">Dashboard</h1>
|
<section className="section">
|
||||||
<h2 className="subtitle">
|
<h1 className="title">Dashboard</h1>
|
||||||
A simple container to divide your page into <strong>sections</strong>,
|
<h2 className="subtitle">
|
||||||
like the one you're currently reading.
|
A simple container to divide your page into{" "}
|
||||||
</h2>
|
<strong>sections</strong>, like the one you're currently reading.
|
||||||
<ZeroState
|
</h2>
|
||||||
header={"Set the source directory"}
|
<ZeroState
|
||||||
message={
|
header={"Set the source directory"}
|
||||||
"No comics were found! Please point ThreeTwo! to a directory..."
|
message={
|
||||||
}
|
"No comics were found! Please point ThreeTwo! to a directory..."
|
||||||
/>
|
}
|
||||||
</section>
|
/>
|
||||||
|
</section>
|
||||||
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -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>
|
||||||
|
|||||||
@@ -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;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user