🔧 Refactoring

This commit is contained in:
2021-08-27 09:30:35 -07:00
parent 4ebe543f6a
commit 482e890d95
3 changed files with 16 additions and 46 deletions

View File

@@ -33,34 +33,6 @@ export const search = (data: SearchData) => async (dispatch) => {
}
const instance: SearchInstance = await SocketService.post("search");
// We want to get notified about every new result in order to make the user experience better
await SocketService.addListener(
`search/${instance.id}`,
"search_result_added",
(groupedResult) => {
dispatch({
type: AIRDCPP_SEARCH_RESULTS_RECEIVED,
groupedResult: groupedResult.result,
});
// ...add the received result in the UI
// (it's probably a good idea to have some kind of throttling for the UI updates as there can be thousands of results)
},
);
// We also want to update the existing items in our list when new hits arrive for the previously listed files/directories
await SocketService.addListener(
`search/${instance.id}`,
"search_result_updated",
async (groupedResult) => {
console.log(groupedResult);
dispatch({
type: AIRDCPP_SEARCH_RESULTS_RECEIVED,
results: groupedResult,
});
// ...update properties of the existing result in the UI
},
);
await SocketService.addListener(
`search/${instance.id}`,
"search_hub_searches_sent",
@@ -90,15 +62,15 @@ export const search = (data: SearchData) => async (dispatch) => {
data,
);
// await sleep(10000);
// const results = await SocketService.get(
// `search/${instance.id}/results/0/25`,
// );
await sleep(10000);
const results = await SocketService.get(
`search/${instance.id}/results/0/125`,
);
// dispatch({
// type: AIRDCPP_SEARCH_RESULTS_RECEIVED,
// results,
// });
dispatch({
type: AIRDCPP_SEARCH_RESULTS_RECEIVED,
results,
});
} catch (error) {
console.log("ERO", error);
throw error;

View File

@@ -15,9 +15,9 @@ export const AcquisitionPanel = (
props.comicBookMetadata.sourcedMetadata.comicvine.volumeInformation.name;
const sanitizedVolumeName = volumeName.replace(/[^a-zA-Z0-9 ]/g, "");
const issueName = props.comicBookMetadata.sourcedMetadata.comicvine.name;
const airDCPPSearchResults = useSelector(
(state: RootState) => { console.log(state); return state.airdcpp.results;}
);
const airDCPPSearchResults = useSelector((state: RootState) => {
return state.airdcpp.searchResults;
});
const isAirDCPPSearchInProgress = useSelector(
(state: RootState) => state.airdcpp.isAirDCPPSearchInProgress,
);
@@ -104,8 +104,7 @@ export const AcquisitionPanel = (
</div>
{/* AirDC++ results */}
<div>
ASDASD {JSON.stringify(airDCPPSearchResults)}
{/* {!isNil(airDCPPSearchResults) && (
{!isNil(airDCPPSearchResults) && (
<table className="table is-striped">
<thead>
<tr>
@@ -172,7 +171,7 @@ export const AcquisitionPanel = (
})}
</tbody>
</table>
)} */}
)}
</div>
</>
);

View File

@@ -9,22 +9,21 @@ import {
import { LOCATION_CHANGE } from "connected-react-router";
const initialState = {
searchResults: [],
isAirDCPPSearchInProgress: false,
searchInfo: null,
searchInstance: null,
downloadResult: null,
bundleDBImportResult: null,
searchResults: [],
};
function airdcppReducer(state = initialState, action) {
switch (action.type) {
case AIRDCPP_SEARCH_RESULTS_RECEIVED:
console.log("mad", state.searchResults);
return {
...state,
isAirDCPPSearchInProgress: true,
searchResults: [...state.searchResults, action.groupedResult],
searchResults: action.results,
isAirDCPPSearchInProgress: false,
};
case AIRDCPP_SEARCH_IN_PROGRESS:
return {