👺 Fixed usage of context with sockets
This commit is contained in:
@@ -20,7 +20,7 @@ import {
|
|||||||
import { refineQuery } from "../shared/utils/filenameparser.utils";
|
import { refineQuery } from "../shared/utils/filenameparser.utils";
|
||||||
import sortBy from "array-sort-by";
|
import sortBy from "array-sort-by";
|
||||||
import { success } from "react-notification-system-redux";
|
import { success } from "react-notification-system-redux";
|
||||||
import { WebSocketContext } from "../context/socket/socket.context";
|
import { Socket } from "socket.io-client";
|
||||||
|
|
||||||
export async function walkFolder(path: string): Promise<Array<IFolderData>> {
|
export async function walkFolder(path: string): Promise<Array<IFolderData>> {
|
||||||
return axios
|
return axios
|
||||||
@@ -48,8 +48,9 @@ export async function walkFolder(path: string): Promise<Array<IFolderData>> {
|
|||||||
* @param {Object} options
|
* @param {Object} options
|
||||||
* @return {Promise<string>} HTML of the page
|
* @return {Promise<string>} HTML of the page
|
||||||
*/
|
*/
|
||||||
export const fetchComicBookMetadata = (options) => async (dispatch) => {
|
export const fetchComicBookMetadata =
|
||||||
const socket = useContext(WebSocketContext);
|
(options, socketInstance: Socket) => async (dispatch) => {
|
||||||
|
const socket = socketInstance.socket;
|
||||||
const extractionOptions = {
|
const extractionOptions = {
|
||||||
extractTarget: "cover",
|
extractTarget: "cover",
|
||||||
targetExtractionFolder: "./userdata/covers",
|
targetExtractionFolder: "./userdata/covers",
|
||||||
|
|||||||
@@ -213,7 +213,7 @@ export const ComicDetail = ({}: ComicDetailProps): ReactElement => {
|
|||||||
<dl>
|
<dl>
|
||||||
<dt>Raw File Details</dt>
|
<dt>Raw File Details</dt>
|
||||||
<dd>{props.data.containedIn}</dd>
|
<dd>{props.data.containedIn}</dd>
|
||||||
<dd>{props.data.path}</dd>
|
<dd className="is-size-7">{props.data.path}</dd>
|
||||||
<dd>
|
<dd>
|
||||||
<div className="field is-grouped">
|
<div className="field is-grouped">
|
||||||
<div className="control">
|
<div className="control">
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import { useDispatch, useSelector } from "react-redux";
|
|||||||
import { RootState } from "threetwo-ui-typings";
|
import { RootState } from "threetwo-ui-typings";
|
||||||
import { isNil, map } from "lodash";
|
import { isNil, map } from "lodash";
|
||||||
import prettyBytes from "pretty-bytes";
|
import prettyBytes from "pretty-bytes";
|
||||||
|
import dayjs from "dayjs";
|
||||||
import ellipsize from "ellipsize";
|
import ellipsize from "ellipsize";
|
||||||
|
|
||||||
interface IDownloadsPanelProps {
|
interface IDownloadsPanelProps {
|
||||||
@@ -73,7 +74,7 @@ export const DownloadsPanel = (
|
|||||||
<tr>
|
<tr>
|
||||||
<th>Filename</th>
|
<th>Filename</th>
|
||||||
<th>Size</th>
|
<th>Size</th>
|
||||||
<th>Time</th>
|
<th>Download Time</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
@@ -86,6 +87,11 @@ export const DownloadsPanel = (
|
|||||||
<span className="is-size-7">{bundle.target}</span>
|
<span className="is-size-7">{bundle.target}</span>
|
||||||
</td>
|
</td>
|
||||||
<td>{prettyBytes(bundle.size)}</td>
|
<td>{prettyBytes(bundle.size)}</td>
|
||||||
|
<td>
|
||||||
|
{dayjs
|
||||||
|
.unix(bundle.time_finished)
|
||||||
|
.format("h:mm on ddd, D MMM, YYYY")}
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
))}
|
))}
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
import React, { ReactElement, useCallback } from "react";
|
import React, { ReactElement, useCallback, useContext } from "react";
|
||||||
import { isEmpty, isNil, isUndefined } from "lodash";
|
import { isEmpty, isNil, isUndefined } from "lodash";
|
||||||
import { useSelector, useDispatch } from "react-redux";
|
import { useSelector, useDispatch } from "react-redux";
|
||||||
import { fetchComicBookMetadata } from "../actions/fileops.actions";
|
import { fetchComicBookMetadata } from "../actions/fileops.actions";
|
||||||
|
import { WebSocketContext } from "../context/socket/socket.context";
|
||||||
import { IFolderData } from "threetwo-ui-typings";
|
import { IFolderData } from "threetwo-ui-typings";
|
||||||
import { LazyLog, ScrollFollow } from "react-lazylog";
|
import { LazyLog, ScrollFollow } from "react-lazylog";
|
||||||
import DynamicList, { createCache } from "react-window-dynamic-list";
|
import DynamicList, { createCache } from "react-window-dynamic-list";
|
||||||
@@ -29,6 +30,7 @@ interface IProps {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
export const Import = (props: IProps): ReactElement => {
|
export const Import = (props: IProps): ReactElement => {
|
||||||
|
const socket = useContext(WebSocketContext);
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
const isSocketConnected = useSelector((state: RootState) => {
|
const isSocketConnected = useSelector((state: RootState) => {
|
||||||
console.log(state);
|
console.log(state);
|
||||||
@@ -43,7 +45,7 @@ export const Import = (props: IProps): ReactElement => {
|
|||||||
const initiateImport = useCallback(() => {
|
const initiateImport = useCallback(() => {
|
||||||
if (typeof props.path !== "undefined") {
|
if (typeof props.path !== "undefined") {
|
||||||
console.log("asdasd");
|
console.log("asdasd");
|
||||||
dispatch(fetchComicBookMetadata(props.path));
|
dispatch(fetchComicBookMetadata(props.path, socket));
|
||||||
}
|
}
|
||||||
}, [dispatch]);
|
}, [dispatch]);
|
||||||
const cache = createCache();
|
const cache = createCache();
|
||||||
|
|||||||
@@ -1,18 +1,13 @@
|
|||||||
import React, { createContext } from "react";
|
import React, { createContext, ReactElement } from "react";
|
||||||
import io, { Socket } from "socket.io-client";
|
import io, { Socket } from "socket.io-client";
|
||||||
import { SOCKET_BASE_URI } from "../../constants/endpoints";
|
import { SOCKET_BASE_URI } from "../../constants/endpoints";
|
||||||
import { useDispatch } from "react-redux";
|
import { useDispatch } from "react-redux";
|
||||||
import { RMQ_SOCKET_CONNECTED } from "../../constants/action-types";
|
import { RMQ_SOCKET_CONNECTED } from "../../constants/action-types";
|
||||||
import { isNil } from "lodash";
|
|
||||||
|
|
||||||
const WebSocketContext = createContext(null);
|
const WebSocketContext = createContext(null);
|
||||||
export const WebSocketProvider = ({ children }) => {
|
export const WebSocketProvider = ({ children }): ReactElement => {
|
||||||
let socket: Socket;
|
|
||||||
let ws;
|
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
|
const socket: Socket = io(SOCKET_BASE_URI);
|
||||||
if (!isNil(socket)) {
|
|
||||||
socket = io(SOCKET_BASE_URI);
|
|
||||||
|
|
||||||
socket.on("connect", () => {
|
socket.on("connect", () => {
|
||||||
dispatch({
|
dispatch({
|
||||||
@@ -25,10 +20,9 @@ export const WebSocketProvider = ({ children }) => {
|
|||||||
console.log(`disconnect`);
|
console.log(`disconnect`);
|
||||||
});
|
});
|
||||||
|
|
||||||
ws = {
|
const ws: any = {
|
||||||
socket: socket,
|
socket,
|
||||||
};
|
};
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<WebSocketContext.Provider value={ws}>{children}</WebSocketContext.Provider>
|
<WebSocketContext.Provider value={ws}>{children}</WebSocketContext.Provider>
|
||||||
|
|||||||
@@ -1,10 +1,8 @@
|
|||||||
import * as React from "react";
|
import React from "react";
|
||||||
import { render } from "react-dom";
|
import { render } from "react-dom";
|
||||||
import { Provider } from "react-redux";
|
import { Provider } from "react-redux";
|
||||||
import { ConnectedRouter } from "connected-react-router";
|
import { ConnectedRouter } from "connected-react-router";
|
||||||
import WebSocketProvider, {
|
import WebSocketProvider from "./context/socket/socket.context";
|
||||||
WebSocketContext,
|
|
||||||
} from "./context/socket/socket.context";
|
|
||||||
import configureStore, { history } from "./store/index";
|
import configureStore, { history } from "./store/index";
|
||||||
import App from "./components/App";
|
import App from "./components/App";
|
||||||
const store = configureStore({});
|
const store = configureStore({});
|
||||||
|
|||||||
Reference in New Issue
Block a user