diff --git a/src/client/actions/airdcpp.actions.tsx b/src/client/actions/airdcpp.actions.tsx index 62670f0..94a8998 100644 --- a/src/client/actions/airdcpp.actions.tsx +++ b/src/client/actions/airdcpp.actions.tsx @@ -6,10 +6,9 @@ import { SearchResponse, } from "threetwo-ui-typings"; import { - AIRDCPP_SEARCH_INSTANCE_CREATED, AIRDCPP_SEARCH_RESULTS_RECEIVED, AIRDCPP_HUB_SEARCHES_SENT, - AIRDCPP_HUB_USER_CONNECTED, + AIRDCPP_RESULT_DOWNLOAD_INITIATED, } from "../constants/action-types"; interface SearchData { @@ -30,10 +29,10 @@ export const search = (data: SearchData) => async (dispatch) => { `search/${instance.id}`, "search_hub_searches_sent", async (searchInfo) => { - console.log("As", searchInfo) - // Collect the results for 5 seconds before fetching them dispatch({ type: AIRDCPP_HUB_SEARCHES_SENT, + searchInfo, + instance, }); }, ); @@ -52,3 +51,17 @@ export const search = (data: SearchData) => async (dispatch) => { SocketService.disconnect(); return results; }; + +export const downloadAirDCPPItem = + (instanceId: string, resultId: string): void => + async (dispatch) => { + await SocketService.connect("admin", "password", true); + const downloadResult = await SocketService.post( + `search/${instanceId}/results/${resultId}/download`, + ); + dispatch({ + type: AIRDCPP_RESULT_DOWNLOAD_INITIATED, + downloadResult: downloadResult, + }); + SocketService.disconnect(); + }; diff --git a/src/client/components/AcquisitionPanel.tsx b/src/client/components/AcquisitionPanel.tsx index 3a84aa7..2c9163f 100644 --- a/src/client/components/AcquisitionPanel.tsx +++ b/src/client/components/AcquisitionPanel.tsx @@ -1,7 +1,7 @@ import React, { useState, useEffect, useCallback, ReactElement } from "react"; -import { search } from "../actions/airdcpp.actions"; +import { search, downloadAirDCPPItem } from "../actions/airdcpp.actions"; import { useDispatch, useSelector } from "react-redux"; -import { RootState } from "threetwo-ui-typings"; +import { RootState, SearchInstance } from "threetwo-ui-typings"; import { each, isNil, map } from "lodash"; interface IAcquisitionPanelProps { @@ -17,8 +17,14 @@ export const AcquisitionPanel = ( const airDCPPSearchResults = useSelector( (state: RootState) => state.airdcpp.results, ); - const searchStatus = useSelector( - (state: RootState) => state.airdcpp.searchStatus, + const isAirDCPPSearchInProgress = useSelector( + (state: RootState) => state.airdcpp.isAirDCPPSearchInProgress, + ); + const searchInfo = useSelector( + (state: RootState) => state.airdcpp.searchInfo, + ); + const searchInstance: SearchInstance = useSelector( + (state: RootState) => state.airdcpp.searchInstance, ); const dispatch = useDispatch(); const getDCPPSearchResults = useCallback( @@ -30,75 +36,133 @@ export const AcquisitionPanel = ( const dcppQuery = { query: { pattern: `${volumeName}`, - // file_type: "compressed", extensions: ["cbz", "cbr"], }, hub_urls: ["perfection.crabdance.com:777"], priority: 1, }; + + const downloadDCPPResult = useCallback( + (searchInstanceId, resultId) => + dispatch(downloadAirDCPPItem(searchInstanceId, resultId)), + [dispatch], + ); return ( -
{searchStatus}
- {/* results */} - {!isNil(airDCPPSearchResults) && ( -| Name | -Type | -Slots | -
|---|---|---|
|
- - {type.id === "directory" ? ( - - ) : null}{" "} - {name} - + <> +
+
+
+
+ {!isNil(searchInfo) && !isNil(searchInstance) && (
+ <>
+
+
+
+
|
- - - {type.id === "directory" ? "directory" : type.str} - - | -
-
- {slots.free} free
- {slots.total}
-
- |
-
| Name | +Type | +Slots | +Actions | +
|---|---|---|---|
|
+ + {type.id === "directory" ? ( + + ) : null}{" "} + {name} + +
|
+ + + {type.id === "directory" ? "directory" : type.str} + + | +
+
+
+ {slots.free} free
+
+ {slots.total}
+
+ |
+ + + downloadDCPPResult(searchInstance.id, id) + } + > + + + | +