🪛 WIP on the DCPP search results
This commit is contained in:
@@ -8,6 +8,8 @@ import {
|
|||||||
import {
|
import {
|
||||||
AIRDCPP_SEARCH_INSTANCE_CREATED,
|
AIRDCPP_SEARCH_INSTANCE_CREATED,
|
||||||
AIRDCPP_SEARCH_RESULTS_RECEIVED,
|
AIRDCPP_SEARCH_RESULTS_RECEIVED,
|
||||||
|
AIRDCPP_HUB_SEARCHES_SENT,
|
||||||
|
AIRDCPP_HUB_USER_CONNECTED,
|
||||||
} from "../constants/action-types";
|
} from "../constants/action-types";
|
||||||
|
|
||||||
interface SearchData {
|
interface SearchData {
|
||||||
@@ -21,16 +23,28 @@ function sleep(ms: number): Promise<NodeJS.Timeout> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const search = (data: SearchData) => async (dispatch) => {
|
export const search = (data: SearchData) => async (dispatch) => {
|
||||||
await SocketService.connect("admin", "password");
|
await SocketService.connect("admin", "password", true);
|
||||||
await sleep(10000);
|
|
||||||
const instance: SearchInstance = await SocketService.post("search");
|
const instance: SearchInstance = await SocketService.post("search");
|
||||||
|
|
||||||
|
SocketService.addListener(
|
||||||
|
`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,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
await SocketService.post<SearchResponse>(
|
await SocketService.post<SearchResponse>(
|
||||||
`search/${instance.id}/hub_search`,
|
`search/${instance.id}/hub_search`,
|
||||||
data,
|
data,
|
||||||
);
|
);
|
||||||
|
|
||||||
await sleep(10000);
|
await sleep(10000);
|
||||||
const results = await SocketService.get(`search/${instance.id}/results/0/25`);
|
const results = await SocketService.get(`search/${instance.id}/results/0/25`);
|
||||||
console.log("results", results);
|
|
||||||
dispatch({
|
dispatch({
|
||||||
type: AIRDCPP_SEARCH_RESULTS_RECEIVED,
|
type: AIRDCPP_SEARCH_RESULTS_RECEIVED,
|
||||||
results,
|
results,
|
||||||
|
|||||||
@@ -17,6 +17,9 @@ export const AcquisitionPanel = (
|
|||||||
const airDCPPSearchResults = useSelector(
|
const airDCPPSearchResults = useSelector(
|
||||||
(state: RootState) => state.airdcpp.results,
|
(state: RootState) => state.airdcpp.results,
|
||||||
);
|
);
|
||||||
|
const searchStatus = useSelector(
|
||||||
|
(state: RootState) => state.airdcpp.searchStatus,
|
||||||
|
);
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
const getDCPPSearchResults = useCallback(
|
const getDCPPSearchResults = useCallback(
|
||||||
(searchQuery) => {
|
(searchQuery) => {
|
||||||
@@ -41,7 +44,7 @@ export const AcquisitionPanel = (
|
|||||||
>
|
>
|
||||||
Search on AirDC++
|
Search on AirDC++
|
||||||
</button>
|
</button>
|
||||||
|
<p>{searchStatus}</p>
|
||||||
{/* results */}
|
{/* results */}
|
||||||
{!isNil(airDCPPSearchResults) && (
|
{!isNil(airDCPPSearchResults) && (
|
||||||
<table className="table is-striped">
|
<table className="table is-striped">
|
||||||
@@ -66,15 +69,14 @@ export const AcquisitionPanel = (
|
|||||||
<dl>
|
<dl>
|
||||||
<dd>
|
<dd>
|
||||||
<div className="tags">
|
<div className="tags">
|
||||||
|
<span className="tag is-light is-info">
|
||||||
<span className="tag is-light is-info">
|
{users.user.nicks}
|
||||||
{users.user.nicks}
|
</span>
|
||||||
</span>
|
{users.user.flags.map((flag, idx) => (
|
||||||
{users.user.flags.map((flag, idx) => (
|
<span className="tag is-light" key={idx}>
|
||||||
<span className="tag is-light" key={idx}>
|
{flag}
|
||||||
{flag}
|
</span>
|
||||||
</span>
|
))}
|
||||||
))}
|
|
||||||
</div>
|
</div>
|
||||||
</dd>
|
</dd>
|
||||||
</dl>
|
</dl>
|
||||||
|
|||||||
@@ -36,3 +36,6 @@ export const AIRDCPP_SEARCH_INSTANCE_CREATED =
|
|||||||
export const AIRDCPP_SEARCH_IN_PROGRESS = "AIRDCPP_SEARCH_IN_PROGRESS";
|
export const AIRDCPP_SEARCH_IN_PROGRESS = "AIRDCPP_SEARCH_IN_PROGRESS";
|
||||||
export const AIRDCPP_SEARCH_RESULTS_RECEIVED =
|
export const AIRDCPP_SEARCH_RESULTS_RECEIVED =
|
||||||
"AIRDCPP_SEARCH_RESULTS_RECEIVED";
|
"AIRDCPP_SEARCH_RESULTS_RECEIVED";
|
||||||
|
|
||||||
|
export const AIRDCPP_HUB_SEARCHES_SENT = "AIRDCPP_HUB_SEARCHES_SENT";
|
||||||
|
export const AIRDCPP_HUB_USER_CONNECTED = "AIRDCPP_HUB_USER_CONNECTED";
|
||||||
|
|||||||
@@ -2,18 +2,27 @@ import {
|
|||||||
AIRDCPP_SEARCH_INSTANCE_CREATED,
|
AIRDCPP_SEARCH_INSTANCE_CREATED,
|
||||||
AIRDCPP_SEARCH_IN_PROGRESS,
|
AIRDCPP_SEARCH_IN_PROGRESS,
|
||||||
AIRDCPP_SEARCH_RESULTS_RECEIVED,
|
AIRDCPP_SEARCH_RESULTS_RECEIVED,
|
||||||
|
AIRDCPP_HUB_SEARCHES_SENT,
|
||||||
|
AIRDCPP_HUB_USER_CONNECTED,
|
||||||
} from "../constants/action-types";
|
} from "../constants/action-types";
|
||||||
|
|
||||||
const initialState = {
|
const initialState = {
|
||||||
isAirDCPPSearchInProgress: false,
|
isAirDCPPSearchInProgress: false,
|
||||||
|
searchStatus: "",
|
||||||
};
|
};
|
||||||
|
|
||||||
function airdcppReducer(state = initialState, action) {
|
function airdcppReducer(state = initialState, action) {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
|
case AIRDCPP_HUB_USER_CONNECTED:
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
searchStatus: "Hub user connected",
|
||||||
|
}
|
||||||
case AIRDCPP_SEARCH_INSTANCE_CREATED:
|
case AIRDCPP_SEARCH_INSTANCE_CREATED:
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
searchInstance: action.searchInstance,
|
searchInstance: action.searchInstance,
|
||||||
|
searchStatus: "Search Instance created",
|
||||||
};
|
};
|
||||||
|
|
||||||
case AIRDCPP_SEARCH_IN_PROGRESS:
|
case AIRDCPP_SEARCH_IN_PROGRESS:
|
||||||
@@ -28,6 +37,13 @@ function airdcppReducer(state = initialState, action) {
|
|||||||
isAirDCPPSearchInProgress: false,
|
isAirDCPPSearchInProgress: false,
|
||||||
results: action.results,
|
results: action.results,
|
||||||
};
|
};
|
||||||
|
case AIRDCPP_HUB_SEARCHES_SENT:
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
searchStatus: "Hub searches sent",
|
||||||
|
isAirDCPPSearchInProgress: true,
|
||||||
|
};
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user