From 3fc22c74efad9bdcd0bcadcacf15d5459d62ab1d Mon Sep 17 00:00:00 2001 From: Rishi Ghan Date: Thu, 2 Sep 2021 08:18:58 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20Adding=20corrected=20AirDCPP=20i?= =?UTF-8?q?ntegration?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. Search event listeners 2. Reducer refactoring --- package.json | 2 +- src/client/actions/airdcpp.actions.tsx | 58 ++++++++++++++-------- src/client/components/AcquisitionPanel.tsx | 10 ++-- src/client/reducers/airdcpp.reducer.ts | 3 +- yarn.lock | 8 +-- 5 files changed, 52 insertions(+), 29 deletions(-) diff --git a/package.json b/package.json index 2df1c48..2231e7b 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,7 @@ "@types/socket.io": "^3.0.2", "@types/socket.io-client": "^3.0.0", "@types/through2": "^2.0.36", - "airdcpp-apisocket": "^2.4.2", + "airdcpp-apisocket": "^2.4.4", "array-sort-by": "^1.2.1", "babel-polyfill": "^6.26.0", "better-docs": "^2.3.2", diff --git a/src/client/actions/airdcpp.actions.tsx b/src/client/actions/airdcpp.actions.tsx index e10a623..b20f4d2 100644 --- a/src/client/actions/airdcpp.actions.tsx +++ b/src/client/actions/airdcpp.actions.tsx @@ -33,44 +33,62 @@ 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`, + "search_result_added", + async (groupedResult) => { + // ...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) + + dispatch({ + type: AIRDCPP_SEARCH_RESULTS_RECEIVED, + groupedResult, + }); + }, + instance.id, + ); + + // 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`, + "search_result_updated", + async (groupedResult) => { + // ...update properties of the existing result in the UI + }, + instance.id, + ); + + // We need to show something to the user in case the search won't yield any results so that he won't be waiting forever) + // Wait for 5 seconds for any results to arrive after the searches were sent to the hubs + await SocketService.addListener( + `search`, "search_hub_searches_sent", async (searchInfo) => { await sleep(5000); + // The search can now be considered to be "complete" + dispatch({ + type: AIRDCPP_HUB_SEARCHES_SENT, + searchInfo, + instance, + }); // Check the number of received results (in real use cases we should know that even without calling the API) const currentInstance = await SocketService.get( `search/${instance.id}`, ); if (currentInstance.result_count === 0) { - console.log("ASDASDASDASDD"); // ...nothing was received, show an informative message to the user } // If there's an "in progress" indicator in the UI, that could also be disabled here - dispatch({ - type: AIRDCPP_HUB_SEARCHES_SENT, - searchInfo, - instance, - }); }, - ); - await SocketService.post( - `search/${instance.id}/hub_search`, - data, + instance.id, ); - await sleep(10000); - const results = await SocketService.get( - `search/${instance.id}/results/0/125`, - ); - - dispatch({ - type: AIRDCPP_SEARCH_RESULTS_RECEIVED, - results, - }); + // Finally, perform the actual search + await SocketService.post(`search/${instance.id}/hub_search`, data); } catch (error) { console.log("ERO", error); throw error; diff --git a/src/client/components/AcquisitionPanel.tsx b/src/client/components/AcquisitionPanel.tsx index 732c7d7..ba5e8dd 100644 --- a/src/client/components/AcquisitionPanel.tsx +++ b/src/client/components/AcquisitionPanel.tsx @@ -42,7 +42,9 @@ export const AcquisitionPanel = ( // pattern: "Templier T2.cbr", extensions: ["cbz", "cbr"], }, - hub_urls: ["nmdcs://piter.feardc.net:411"], + hub_urls: [ + "adcs://novosibirsk.dc-dev.club:7111/?kp=SHA256/4XFHJFFBFEI2RS75FPRPPXPZMMKPXR764ABVVCC2QGJPQ34SDZGA", + ], priority: 5, }; @@ -115,7 +117,9 @@ export const AcquisitionPanel = ( - {map(airDCPPSearchResults, ({ name, type, slots, users, id }) => { + + {JSON.stringify(airDCPPSearchResults)} + {/* {map(airDCPPSearchResults, ({ name, type, slots, users, id }) => { return ( @@ -168,7 +172,7 @@ export const AcquisitionPanel = ( ); - })} + })} */} )} diff --git a/src/client/reducers/airdcpp.reducer.ts b/src/client/reducers/airdcpp.reducer.ts index a75ec8c..8c3f891 100644 --- a/src/client/reducers/airdcpp.reducer.ts +++ b/src/client/reducers/airdcpp.reducer.ts @@ -20,9 +20,10 @@ const initialState = { function airdcppReducer(state = initialState, action) { switch (action.type) { case AIRDCPP_SEARCH_RESULTS_RECEIVED: + console.log("Badan", action) return { ...state, - searchResults: action.results, + searchResults: action.groupedResult.result, isAirDCPPSearchInProgress: false, }; case AIRDCPP_SEARCH_IN_PROGRESS: diff --git a/yarn.lock b/yarn.lock index fc32e02..df5d19d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2275,10 +2275,10 @@ aggregate-error@^3.0.0: clean-stack "^2.0.0" indent-string "^4.0.0" -airdcpp-apisocket@^2.4.2: - version "2.4.2" - resolved "https://registry.npmjs.org/airdcpp-apisocket/-/airdcpp-apisocket-2.4.2.tgz" - integrity sha512-OxrrYe/iNOfle4RhqgaoUNJrgc7LDWCK+WhMQyfprDRxRqkvgPDuWjOavlmf89cAMIgwJ7x5DESpJKWvNGaS/w== +airdcpp-apisocket@^2.4.4: + version "2.4.4" + resolved "https://registry.yarnpkg.com/airdcpp-apisocket/-/airdcpp-apisocket-2.4.4.tgz#94c3b8082022982557b8cad2fc77a670709f0b2c" + integrity sha512-Xn0kWSVdLJwPpOoHcdI2wzzfzZW2jTpuyZR2wCNs2UIlZhO+FTwMf3QQfNCt5gYTOld9LaiCEulxFuXDA8qrLA== dependencies: chalk "^4.1.2" events "^3.3.0"