🔽 Wiring up downloads API calls and actions

This commit is contained in:
2022-07-26 22:26:24 -07:00
parent a3aa46bca3
commit fb40fe86b5
7 changed files with 66 additions and 27 deletions

View File

@@ -17,6 +17,7 @@ import {
LS_SINGLE_IMPORT, LS_SINGLE_IMPORT,
IMS_COMIC_BOOK_DB_OBJECT_FETCHED, IMS_COMIC_BOOK_DB_OBJECT_FETCHED,
AIRDCPP_TRANSFERS_FETCHED, AIRDCPP_TRANSFERS_FETCHED,
LIBRARY_ISSUE_BUNDLES,
} from "../constants/action-types"; } from "../constants/action-types";
import { isNil } from "lodash"; import { isNil } from "lodash";
import axios from "axios"; import axios from "axios";
@@ -233,11 +234,15 @@ export const getTransfers =
}); });
const bundleIds = bundles.map((bundle) => bundle.id); const bundleIds = bundles.map((bundle) => bundle.id);
// get issues with matching bundleIds // get issues with matching bundleIds
const issues = await axios({ const issue_bundles = await axios({
url: `${SEARCH_SERVICE_BASE_URI}/groupIssuesByBundles`, url: `${SEARCH_SERVICE_BASE_URI}/groupIssuesByBundles`,
method: "POST", method: "POST",
data: { bundleIds }, data: { bundleIds },
}); });
dispatch({
type: LIBRARY_ISSUE_BUNDLES,
issue_bundles,
});
} }
} catch (err) { } catch (err) {

View File

@@ -1,6 +1,5 @@
import React, { useEffect, useContext, ReactElement } from "react"; import React, { useEffect, useContext, ReactElement } from "react";
import { import {
getDownloadProgress,
getBundlesForComic, getBundlesForComic,
} from "../../actions/airdcpp.actions"; } from "../../actions/airdcpp.actions";
import { useDispatch, useSelector } from "react-redux"; import { useDispatch, useSelector } from "react-redux";

View File

@@ -1,9 +1,11 @@
import React, { ReactElement, useCallback, useContext, useEffect } from "react"; import React, { ReactElement, useCallback, useContext, useEffect, useState } from "react";
import { getTransfers } from "../../actions/airdcpp.actions"; import { getTransfers } from "../../actions/airdcpp.actions";
import { useDispatch, useSelector } from "react-redux"; import { useDispatch, useSelector } from "react-redux";
import { AirDCPPSocketContext } from "../../context/AirDCPPSocket"; import { AirDCPPSocketContext } from "../../context/AirDCPPSocket";
import { isEmpty, isUndefined } from "lodash"; import { isEmpty, isNil, isUndefined } from "lodash";
import { searchIssue } from "../../actions/fileops.actions"; import { searchIssue } from "../../actions/fileops.actions";
import { determineCoverFile } from "../../shared/utils/metadata.utils";
import MetadataPanel from "../shared/MetadataPanel";
interface IDownloadsProps { interface IDownloadsProps {
data: any; data: any;
@@ -19,22 +21,8 @@ export const Downloads = (props: IDownloadsProps): ReactElement => {
const airDCPPTransfers = useSelector( const airDCPPTransfers = useSelector(
(state: RootState) => state.airdcpp.transfers, (state: RootState) => state.airdcpp.transfers,
); );
useEffect(() => { const issueBundles = useSelector((state: RootState) => state.airdcpp.issue_bundles);
dispatch( const [bundles, setBundles] = useState([]);
searchIssue(
{
query: {},
},
{
pagination: {
size: 25,
from: 0,
},
type: "wanted",
},
),
);
}, []);
// Make the call to get all transfers from AirDC++ // Make the call to get all transfers from AirDC++
useEffect(() => { useEffect(() => {
if (!isUndefined(socket) && !isEmpty(settings)) { if (!isUndefined(socket) && !isEmpty(settings)) {
@@ -47,9 +35,47 @@ export const Downloads = (props: IDownloadsProps): ReactElement => {
} }
}, [socket]); }, [socket]);
useEffect(() => {
// const getAllDownloads = useCallback(() => {}); if (!isUndefined(issueBundles)) {
return <pre>{JSON.stringify(airDCPPTransfers, null, 2)}</pre>; const foo = issueBundles.data.map((bundle) => {
const { rawFileDetails, inferredMetadata, acquisition: { directconnect: { downloads } }, sourcedMetadata: { locg, comicvine } } = bundle;
const { issueName, url } = determineCoverFile({
rawFileDetails, comicvine, locg,
});
return { ...bundle, issueName, url }
})
setBundles(foo);
}
}, [issueBundles])
return !isNil(bundles) ?
<div className="container">
<section className="section">
<h1 className="title">Downloads</h1>
<div className="columns">
<div className="column is-half">
{bundles.map(bundle => {
console.log(bundle);
return <>
<MetadataPanel
data={bundle}
imageStyle={{ maxWidth: 100 }}
titleStyle={{ fontSize: "0.8rem" }}
tagsStyle={{ fontSize: "0.7rem" }}
containerStyle={{
padding: 0,
margin: "0 0 8px 0",
}} />
<pre>{JSON.stringify(bundle.acquisition.directconnect.downloads, null, 2)}</pre>
</>
})}
</div>
</div>
</section>
</div> : <div>asd</div>;
}; };
export default Downloads; export default Downloads;

View File

@@ -101,6 +101,9 @@ export const AIRDCPP_SEARCH_RESULTS_ADDED = "AIRDCPP_SEARCH_RESULTS_ADDED";
export const AIRDCPP_SEARCH_RESULTS_UPDATED = "AIRDCPP_SEARCH_RESULTS_UPDATED"; export const AIRDCPP_SEARCH_RESULTS_UPDATED = "AIRDCPP_SEARCH_RESULTS_UPDATED";
export const AIRDCPP_SEARCH_COMPLETE = "AIRDCPP_SEARCH_COMPLETE"; export const AIRDCPP_SEARCH_COMPLETE = "AIRDCPP_SEARCH_COMPLETE";
// AirDC++ related library query for issues with bundles associated with them
export const LIBRARY_ISSUE_BUNDLES = "LIBRARY_ISSUE_BUNDLES";
export const AIRDCPP_HUB_SEARCHES_SENT = "AIRDCPP_HUB_SEARCHES_SENT"; export const AIRDCPP_HUB_SEARCHES_SENT = "AIRDCPP_HUB_SEARCHES_SENT";
export const AIRDCPP_RESULT_DOWNLOAD_INITIATED = export const AIRDCPP_RESULT_DOWNLOAD_INITIATED =
"AIRDCPP_RESULT_DOWNLOAD_INITIATED"; "AIRDCPP_RESULT_DOWNLOAD_INITIATED";

View File

@@ -8,9 +8,10 @@ import {
AIRDCPP_FILE_DOWNLOAD_COMPLETED, AIRDCPP_FILE_DOWNLOAD_COMPLETED,
AIRDCPP_BUNDLES_FETCHED, AIRDCPP_BUNDLES_FETCHED,
AIRDCPP_TRANSFERS_FETCHED, AIRDCPP_TRANSFERS_FETCHED,
LIBRARY_ISSUE_BUNDLES,
} from "../constants/action-types"; } from "../constants/action-types";
import { LOCATION_CHANGE } from "redux-first-history"; import { LOCATION_CHANGE } from "redux-first-history";
import { isUndefined } from "lodash"; import { isNil, isUndefined } from "lodash";
import { difference } from "../shared/utils/object.utils"; import { difference } from "../shared/utils/object.utils";
const initialState = { const initialState = {
@@ -40,8 +41,9 @@ function airdcppReducer(state = initialState, action) {
const updatedState = [...state.searchResults]; const updatedState = [...state.searchResults];
if ( if (
difference(updatedState[bundleToUpdateIndex], action.groupedResult) !== !isNil(
{} difference(updatedState[bundleToUpdateIndex], action.groupedResult),
)
) { ) {
updatedState[bundleToUpdateIndex] = action.groupedResult; updatedState[bundleToUpdateIndex] = action.groupedResult;
} }
@@ -78,6 +80,11 @@ function airdcppReducer(state = initialState, action) {
...state, ...state,
bundles: action.bundles, bundles: action.bundles,
}; };
case LIBRARY_ISSUE_BUNDLES:
return {
...state,
issue_bundles: action.issue_bundles,
};
case AIRDCPP_FILE_DOWNLOAD_COMPLETED: case AIRDCPP_FILE_DOWNLOAD_COMPLETED:
console.log("COMPLETED", action); console.log("COMPLETED", action);
return { return {

View File

@@ -194,7 +194,6 @@ function fileOpsReducer(state = initialState, action) {
}; };
} }
case SS_SEARCH_RESULTS_FETCHED_SPECIAL: { case SS_SEARCH_RESULTS_FETCHED_SPECIAL: {
console.log(action)
const foo = []; const foo = [];
if (!isUndefined(action.data.hits)) { if (!isUndefined(action.data.hits)) {
map(action.data.hits.hits, ({ _source }) => { map(action.data.hits.hits, ({ _source }) => {