🔄 Fixed a redux store issue with download counts
This commit is contained in:
@@ -12,8 +12,9 @@ import {
|
|||||||
AIRDCPP_DOWNLOAD_PROGRESS_TICK,
|
AIRDCPP_DOWNLOAD_PROGRESS_TICK,
|
||||||
AIRDCPP_BUNDLES_FETCHED,
|
AIRDCPP_BUNDLES_FETCHED,
|
||||||
AIRDCPP_SEARCH_IN_PROGRESS,
|
AIRDCPP_SEARCH_IN_PROGRESS,
|
||||||
|
IMS_COMIC_BOOK_DB_OBJECT_FETCHED,
|
||||||
} from "../constants/action-types";
|
} from "../constants/action-types";
|
||||||
import { each, isNil, isUndefined } from "lodash";
|
import { each, isNil, isUndefined, result } from "lodash";
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
|
|
||||||
interface SearchData {
|
interface SearchData {
|
||||||
@@ -32,7 +33,7 @@ export const search = (data: SearchData) => async (dispatch) => {
|
|||||||
await SocketService.connect("admin", "password", true);
|
await SocketService.connect("admin", "password", true);
|
||||||
}
|
}
|
||||||
const instance: SearchInstance = await SocketService.post("search");
|
const instance: SearchInstance = await SocketService.post("search");
|
||||||
console.log(instance)
|
console.log(instance);
|
||||||
dispatch({
|
dispatch({
|
||||||
type: AIRDCPP_SEARCH_IN_PROGRESS,
|
type: AIRDCPP_SEARCH_IN_PROGRESS,
|
||||||
});
|
});
|
||||||
@@ -145,6 +146,11 @@ export const downloadAirDCPPItem =
|
|||||||
downloadResult: downloadResult,
|
downloadResult: downloadResult,
|
||||||
bundleDBImportResult,
|
bundleDBImportResult,
|
||||||
});
|
});
|
||||||
|
dispatch({
|
||||||
|
type: IMS_COMIC_BOOK_DB_OBJECT_FETCHED,
|
||||||
|
comicBookDetail: bundleDBImportResult.data,
|
||||||
|
IMS_inProgress: false,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw error;
|
throw error;
|
||||||
@@ -179,7 +185,7 @@ export const getBundlesForComic =
|
|||||||
if (!SocketService.isConnected()) {
|
if (!SocketService.isConnected()) {
|
||||||
await SocketService.connect("admin", "password", true);
|
await SocketService.connect("admin", "password", true);
|
||||||
}
|
}
|
||||||
const bundles = await SocketService.get("queue/bundles/0/500");
|
// const bundles = await SocketService.get("queue/bundles/0/50");
|
||||||
const comicObject = await axios({
|
const comicObject = await axios({
|
||||||
method: "POST",
|
method: "POST",
|
||||||
url: "http://localhost:3000/api/import/getComicBookById",
|
url: "http://localhost:3000/api/import/getComicBookById",
|
||||||
@@ -191,18 +197,14 @@ export const getBundlesForComic =
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
// get only the bundles applicable for the comic
|
// get only the bundles applicable for the comic
|
||||||
const filteredBundles = [];
|
const filteredBundles = comicObject.data.acquisition.directconnect.map(
|
||||||
comicObject.data.acquisition.directconnect.map(({ bundleId }) => {
|
async ({ bundleId }) => {
|
||||||
each(bundles, (bundle) => {
|
return await SocketService.get(`queue/bundles/${bundleId}`);
|
||||||
if (bundle.id === bundleId) {
|
},
|
||||||
filteredBundles.push(bundle);
|
);
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
dispatch({
|
dispatch({
|
||||||
type: AIRDCPP_BUNDLES_FETCHED,
|
type: AIRDCPP_BUNDLES_FETCHED,
|
||||||
bundles: filteredBundles,
|
bundles: await Promise.all(filteredBundles),
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw error;
|
throw error;
|
||||||
|
|||||||
@@ -183,6 +183,18 @@ $border-color: red;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Comic Detail
|
||||||
|
.tabs {
|
||||||
|
.download-icon-labels {
|
||||||
|
.downloads-count {
|
||||||
|
margin: 0 1em 0 0.4em;
|
||||||
|
border: 1px solid #CCC;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.download-tab-name {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.comic-vine-match-drawer {
|
.comic-vine-match-drawer {
|
||||||
// comic detail drawer
|
// comic detail drawer
|
||||||
.search-criteria-card {
|
.search-criteria-card {
|
||||||
@@ -207,6 +219,9 @@ $border-color: red;
|
|||||||
.slide-pane__header {
|
.slide-pane__header {
|
||||||
margin-top: 52px;
|
margin-top: 52px;
|
||||||
}
|
}
|
||||||
|
.slide-pane__close {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
.search-results-container {
|
.search-results-container {
|
||||||
margin: 15px 0 0 0;
|
margin: 15px 0 0 0;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
|
|||||||
@@ -1,8 +1,13 @@
|
|||||||
import React, { useCallback, ReactElement } from "react";
|
import React, { useCallback, ReactElement } from "react";
|
||||||
import { search, downloadAirDCPPItem } from "../actions/airdcpp.actions";
|
import {
|
||||||
|
search,
|
||||||
|
downloadAirDCPPItem,
|
||||||
|
getBundlesForComic,
|
||||||
|
} from "../actions/airdcpp.actions";
|
||||||
import { useDispatch, useSelector } from "react-redux";
|
import { useDispatch, useSelector } from "react-redux";
|
||||||
import { RootState, SearchInstance } from "threetwo-ui-typings";
|
import { RootState, SearchInstance } from "threetwo-ui-typings";
|
||||||
import { isNil, map } from "lodash";
|
import ellipsize from "ellipsize";
|
||||||
|
import { isEmpty, isNil, map } from "lodash";
|
||||||
|
|
||||||
interface IAcquisitionPanelProps {
|
interface IAcquisitionPanelProps {
|
||||||
comicBookMetadata: any;
|
comicBookMetadata: any;
|
||||||
@@ -47,10 +52,12 @@ export const AcquisitionPanel = (
|
|||||||
};
|
};
|
||||||
|
|
||||||
const downloadDCPPResult = useCallback(
|
const downloadDCPPResult = useCallback(
|
||||||
(searchInstanceId, resultId, comicBookObjectId) =>
|
(searchInstanceId, resultId, comicBookObjectId) => {
|
||||||
dispatch(
|
dispatch(
|
||||||
downloadAirDCPPItem(searchInstanceId, resultId, comicBookObjectId),
|
downloadAirDCPPItem(searchInstanceId, resultId, comicBookObjectId),
|
||||||
),
|
);
|
||||||
|
dispatch(getBundlesForComic(comicBookObjectId));
|
||||||
|
},
|
||||||
[dispatch],
|
[dispatch],
|
||||||
);
|
);
|
||||||
return (
|
return (
|
||||||
@@ -104,7 +111,7 @@ export const AcquisitionPanel = (
|
|||||||
</div>
|
</div>
|
||||||
{/* AirDC++ results */}
|
{/* AirDC++ results */}
|
||||||
<div>
|
<div>
|
||||||
{!isNil(airDCPPSearchResults) && (
|
{!isNil(airDCPPSearchResults) && !isEmpty(airDCPPSearchResults) && (
|
||||||
<table className="table is-striped">
|
<table className="table is-striped">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
@@ -123,7 +130,7 @@ export const AcquisitionPanel = (
|
|||||||
{result.type.id === "directory" ? (
|
{result.type.id === "directory" ? (
|
||||||
<i className="fas fa-folder"></i>
|
<i className="fas fa-folder"></i>
|
||||||
) : null}{" "}
|
) : null}{" "}
|
||||||
{result.name}
|
{ellipsize(result.name, 70)}
|
||||||
</p>
|
</p>
|
||||||
<dl>
|
<dl>
|
||||||
<dd>
|
<dd>
|
||||||
|
|||||||
@@ -1,4 +1,10 @@
|
|||||||
import React, { useState, useEffect, useCallback, ReactElement } from "react";
|
import React, {
|
||||||
|
useState,
|
||||||
|
useEffect,
|
||||||
|
useLayoutEffect,
|
||||||
|
useCallback,
|
||||||
|
ReactElement,
|
||||||
|
} from "react";
|
||||||
import { useParams } from "react-router-dom";
|
import { useParams } from "react-router-dom";
|
||||||
import Card from "./Carda";
|
import Card from "./Carda";
|
||||||
import MatchResult from "./MatchResult";
|
import MatchResult from "./MatchResult";
|
||||||
@@ -15,6 +21,7 @@ import { isEmpty, isUndefined, isNil } from "lodash";
|
|||||||
import { RootState } from "threetwo-ui-typings";
|
import { RootState } from "threetwo-ui-typings";
|
||||||
import { fetchComicVineMatches } from "../actions/fileops.actions";
|
import { fetchComicVineMatches } from "../actions/fileops.actions";
|
||||||
import { getComicBookDetailById } from "../actions/comicinfo.actions";
|
import { getComicBookDetailById } from "../actions/comicinfo.actions";
|
||||||
|
import { getBundlesForComic } from "../actions/airdcpp.actions";
|
||||||
import dayjs from "dayjs";
|
import dayjs from "dayjs";
|
||||||
const prettyBytes = require("pretty-bytes");
|
const prettyBytes = require("pretty-bytes");
|
||||||
|
|
||||||
@@ -154,9 +161,20 @@ export const ComicDetail = ({}: ComicDetailProps): ReactElement => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 4,
|
id: 4,
|
||||||
icon: <i className="fas fa-cloud-download-alt"></i>,
|
icon: null,
|
||||||
name: "Downloads",
|
name:
|
||||||
content: <DownloadsPanel data={comicBookDetailData} key={4} />,
|
!isNil(comicBookDetailData) && !isEmpty(comicBookDetailData) ? (
|
||||||
|
<span className="download-tab-name">Downloads</span>
|
||||||
|
) : (
|
||||||
|
"Downloads"
|
||||||
|
),
|
||||||
|
content: !isNil(comicBookDetailData) && !isEmpty(comicBookDetailData) && (
|
||||||
|
<DownloadsPanel
|
||||||
|
data={comicBookDetailData.acquisition.directconnect}
|
||||||
|
comicObjectId={comicObjectId}
|
||||||
|
key={4}
|
||||||
|
/>
|
||||||
|
),
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
const MetadataTabGroup = () => {
|
const MetadataTabGroup = () => {
|
||||||
@@ -171,7 +189,18 @@ export const ComicDetail = ({}: ComicDetailProps): ReactElement => {
|
|||||||
onClick={() => setActive(id)}
|
onClick={() => setActive(id)}
|
||||||
>
|
>
|
||||||
<a>
|
<a>
|
||||||
<span className="icon is-small">{icon}</span>
|
{id === 4 &&
|
||||||
|
!isNil(comicBookDetailData) &&
|
||||||
|
!isEmpty(comicBookDetailData) ? (
|
||||||
|
<span className="download-icon-labels">
|
||||||
|
<i className="fas fa-cloud-download-alt"></i>
|
||||||
|
<span className="tag downloads-count">
|
||||||
|
{comicBookDetailData.acquisition.directconnect.length}
|
||||||
|
</span>
|
||||||
|
</span>
|
||||||
|
) : (
|
||||||
|
<span className="icon is-small">{icon}</span>
|
||||||
|
)}
|
||||||
{name}
|
{name}
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
|
|||||||
@@ -1,8 +1,5 @@
|
|||||||
import React, { useEffect, ReactElement } from "react";
|
import React, { useEffect, ReactElement } from "react";
|
||||||
import {
|
import { getDownloadProgress } from "../actions/airdcpp.actions";
|
||||||
getDownloadProgress,
|
|
||||||
getBundlesForComic,
|
|
||||||
} from "../actions/airdcpp.actions";
|
|
||||||
import { useDispatch, useSelector } from "react-redux";
|
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";
|
||||||
@@ -10,6 +7,7 @@ import prettyBytes from "pretty-bytes";
|
|||||||
|
|
||||||
interface IDownloadsPanelProps {
|
interface IDownloadsPanelProps {
|
||||||
data: any;
|
data: any;
|
||||||
|
comicObjectId: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const DownloadsPanel = (
|
export const DownloadsPanel = (
|
||||||
@@ -18,16 +16,11 @@ export const DownloadsPanel = (
|
|||||||
const downloadProgressTick = useSelector(
|
const downloadProgressTick = useSelector(
|
||||||
(state: RootState) => state.airdcpp.downloadProgressData,
|
(state: RootState) => state.airdcpp.downloadProgressData,
|
||||||
);
|
);
|
||||||
const bundles = useSelector((state: RootState) => state.airdcpp.bundles);
|
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
// useEffect(() => {
|
// useEffect(() => {
|
||||||
// dispatch(getDownloadProgress(props.data._id));
|
// dispatch(getDownloadProgress(props.data._id));
|
||||||
// }, [dispatch]);
|
// }, [dispatch]);
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
dispatch(getBundlesForComic(props.data._id));
|
|
||||||
}, [dispatch]);
|
|
||||||
|
|
||||||
const ProgressTick = (props) => (
|
const ProgressTick = (props) => (
|
||||||
<div className="column is-one-quarter">
|
<div className="column is-one-quarter">
|
||||||
{JSON.stringify(props.downloadProgressTick)}
|
{JSON.stringify(props.downloadProgressTick)}
|
||||||
@@ -71,7 +64,7 @@ export const DownloadsPanel = (
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
return !isNil(bundles) ? <Bundles data={bundles} /> : null;
|
return !isNil(props.data) ? <Bundles data={props.data} /> : null;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default DownloadsPanel;
|
export default DownloadsPanel;
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ const Navbar: React.FunctionComponent = (props) => {
|
|||||||
const socketConnection = useSelector((state: RootState) => state.fileOps);
|
const socketConnection = useSelector((state: RootState) => state.fileOps);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<nav className="navbar ">
|
<nav className="navbar is-fixed-top">
|
||||||
<div className="navbar-brand">
|
<div className="navbar-brand">
|
||||||
<a className="navbar-item" href="http://bulma.io">
|
<a className="navbar-item" href="http://bulma.io">
|
||||||
<img
|
<img
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ const initialState = {
|
|||||||
searchInstance: null,
|
searchInstance: null,
|
||||||
downloadResult: null,
|
downloadResult: null,
|
||||||
bundleDBImportResult: null,
|
bundleDBImportResult: null,
|
||||||
|
bundles: [],
|
||||||
};
|
};
|
||||||
|
|
||||||
function airdcppReducer(state = initialState, action) {
|
function airdcppReducer(state = initialState, action) {
|
||||||
@@ -38,6 +39,7 @@ function airdcppReducer(state = initialState, action) {
|
|||||||
searchInstance: action.instance,
|
searchInstance: action.instance,
|
||||||
};
|
};
|
||||||
case AIRDCPP_RESULT_DOWNLOAD_INITIATED:
|
case AIRDCPP_RESULT_DOWNLOAD_INITIATED:
|
||||||
|
console.log(action)
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
downloadResult: action.downloadResult,
|
downloadResult: action.downloadResult,
|
||||||
@@ -61,6 +63,7 @@ function airdcppReducer(state = initialState, action) {
|
|||||||
searchInstance: null,
|
searchInstance: null,
|
||||||
downloadResult: null,
|
downloadResult: null,
|
||||||
bundleDBImportResult: null,
|
bundleDBImportResult: null,
|
||||||
|
// bundles: [],
|
||||||
};
|
};
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|||||||
Reference in New Issue
Block a user