🏗 Actions, reducers for Downloads
This commit is contained in:
@@ -17,6 +17,7 @@ import {
|
|||||||
AIRDCPP_FILE_DOWNLOAD_COMPLETED,
|
AIRDCPP_FILE_DOWNLOAD_COMPLETED,
|
||||||
LS_SINGLE_IMPORT,
|
LS_SINGLE_IMPORT,
|
||||||
IMS_COMIC_BOOK_DB_OBJECT_FETCHED,
|
IMS_COMIC_BOOK_DB_OBJECT_FETCHED,
|
||||||
|
AIRDCPP_TRANSFERS_FETCHED,
|
||||||
} from "../constants/action-types";
|
} from "../constants/action-types";
|
||||||
import { isNil } from "lodash";
|
import { isNil } from "lodash";
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
@@ -265,8 +266,13 @@ export const getTransfers =
|
|||||||
true,
|
true,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
const foo = await ADCPPSocket.get("queue/bundles/1/50", {});
|
const transfers = await ADCPPSocket.get("queue/bundles/1/50", {});
|
||||||
console.log(foo);
|
if (!isNil(transfers)) {
|
||||||
|
dispatch({
|
||||||
|
type: AIRDCPP_TRANSFERS_FETCHED,
|
||||||
|
transfers,
|
||||||
|
});
|
||||||
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
import React, { ReactElement, useCallback, useContext, useEffect } from "react";
|
import React, { ReactElement, useCallback, useContext, useEffect } from "react";
|
||||||
import { getSettings } from "../../actions/settings.actions";
|
|
||||||
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 AirDCPPSocket from "../../services/DcppSearchService";
|
|
||||||
import { isEmpty, isUndefined } from "lodash";
|
import { isEmpty, isUndefined } from "lodash";
|
||||||
|
|
||||||
interface IDownloadsProps {
|
interface IDownloadsProps {
|
||||||
@@ -11,41 +9,26 @@ interface IDownloadsProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const Downloads = (props: IDownloadsProps): ReactElement => {
|
export const Downloads = (props: IDownloadsProps): ReactElement => {
|
||||||
const { ADCPPSocket, setADCPPSocket } = useContext(AirDCPPSocketContext);
|
const airDCPPConfiguration = useContext(AirDCPPSocketContext);
|
||||||
|
const { AirDCPPSocket, settings } = airDCPPConfiguration;
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
const airDCPPClientSettings = useSelector(
|
|
||||||
(state: RootState) => state.settings.data,
|
|
||||||
);
|
|
||||||
useEffect(() => {
|
|
||||||
dispatch(getSettings());
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
useEffect(() => {
|
const AirDCPPTransfers = useSelector(
|
||||||
if (!isEmpty(airDCPPClientSettings)) {
|
(state: RootState) => state.airdcpp.transfers,
|
||||||
setADCPPSocket(
|
|
||||||
new AirDCPPSocket({
|
|
||||||
hostname: `${airDCPPClientSettings.directConnect.client.host.hostname}`,
|
|
||||||
protocol: `${airDCPPClientSettings.directConnect.client.host.protocol}`,
|
|
||||||
}),
|
|
||||||
);
|
);
|
||||||
}
|
|
||||||
}, [airDCPPClientSettings]);
|
|
||||||
|
|
||||||
console.log(airDCPPClientSettings);
|
|
||||||
// Make the call to get all transfers from AirDC++
|
// Make the call to get all transfers from AirDC++
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!isUndefined(ADCPPSocket) && !isEmpty(airDCPPClientSettings)) {
|
if (!isUndefined(AirDCPPSocket) && !isEmpty(airDCPPConfiguration)) {
|
||||||
dispatch(
|
dispatch(
|
||||||
getTransfers(ADCPPSocket, {
|
getTransfers(AirDCPPSocket, {
|
||||||
username: `${airDCPPClientSettings.directConnect.client.host.username}`,
|
username: `${settings.directConnect.client.host.username}`,
|
||||||
password: `${airDCPPClientSettings.directConnect.client.host.password}`,
|
password: `${settings.directConnect.client.host.password}`,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}, [ADCPPSocket]);
|
}, [AirDCPPSocket]);
|
||||||
// const getAllDownloads = useCallback(() => {});
|
// const getAllDownloads = useCallback(() => {});
|
||||||
|
return <pre>{JSON.stringify(AirDCPPTransfers, null, 2)}</pre>;
|
||||||
return <></>;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default Downloads;
|
export default Downloads;
|
||||||
|
|||||||
@@ -110,6 +110,9 @@ export const LS_SINGLE_IMPORT = "LS_SINGLE_IMPORT";
|
|||||||
export const AIRDCPP_BUNDLES_FETCHED = "AIRDCPP_BUNDLES_FETCHED";
|
export const AIRDCPP_BUNDLES_FETCHED = "AIRDCPP_BUNDLES_FETCHED";
|
||||||
export const AIRDCPP_DOWNLOAD_PROGRESS_TICK = "AIRDCPP_DOWNLOAD_PROGRESS_TICK";
|
export const AIRDCPP_DOWNLOAD_PROGRESS_TICK = "AIRDCPP_DOWNLOAD_PROGRESS_TICK";
|
||||||
|
|
||||||
|
// Transfers
|
||||||
|
export const AIRDCPP_TRANSFERS_FETCHED = "AIRDCPP_TRANSFERS_FETCHED";
|
||||||
|
|
||||||
// LIBRARY SOCKET ENDPOINT
|
// LIBRARY SOCKET ENDPOINT
|
||||||
export const LS_IMPORT = "LS_IMPORT";
|
export const LS_IMPORT = "LS_IMPORT";
|
||||||
export const LS_COVER_EXTRACTED = "LS_COVER_EXTRACTED";
|
export const LS_COVER_EXTRACTED = "LS_COVER_EXTRACTED";
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import {
|
|||||||
AIRDCPP_DOWNLOAD_PROGRESS_TICK,
|
AIRDCPP_DOWNLOAD_PROGRESS_TICK,
|
||||||
AIRDCPP_FILE_DOWNLOAD_COMPLETED,
|
AIRDCPP_FILE_DOWNLOAD_COMPLETED,
|
||||||
AIRDCPP_BUNDLES_FETCHED,
|
AIRDCPP_BUNDLES_FETCHED,
|
||||||
|
AIRDCPP_TRANSFERS_FETCHED,
|
||||||
} 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 { isUndefined } from "lodash";
|
||||||
@@ -21,6 +22,7 @@ const initialState = {
|
|||||||
bundleDBImportResult: null,
|
bundleDBImportResult: null,
|
||||||
downloadFileStatus: {},
|
downloadFileStatus: {},
|
||||||
bundles: [],
|
bundles: [],
|
||||||
|
transfers: [],
|
||||||
};
|
};
|
||||||
|
|
||||||
function airdcppReducer(state = initialState, action) {
|
function airdcppReducer(state = initialState, action) {
|
||||||
@@ -81,6 +83,11 @@ function airdcppReducer(state = initialState, action) {
|
|||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
};
|
};
|
||||||
|
case AIRDCPP_TRANSFERS_FETCHED:
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
transfers: action.transfers,
|
||||||
|
};
|
||||||
case LOCATION_CHANGE:
|
case LOCATION_CHANGE:
|
||||||
return {
|
return {
|
||||||
searchResults: [],
|
searchResults: [],
|
||||||
|
|||||||
Reference in New Issue
Block a user