From 52daf4781bb5883f2d4544372fe627a7b39d6a9e Mon Sep 17 00:00:00 2001 From: Rishi Ghan Date: Mon, 25 Apr 2022 12:50:54 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20Refactoring?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/client/actions/airdcpp.actions.tsx | 28 ++++++++++++++------------ src/client/constants/action-types.ts | 1 + 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/client/actions/airdcpp.actions.tsx b/src/client/actions/airdcpp.actions.tsx index 52e1a89..d2938b2 100644 --- a/src/client/actions/airdcpp.actions.tsx +++ b/src/client/actions/airdcpp.actions.tsx @@ -15,10 +15,10 @@ import { AIRDCPP_BUNDLES_FETCHED, AIRDCPP_SEARCH_IN_PROGRESS, AIRDCPP_FILE_DOWNLOAD_COMPLETED, + LS_SINGLE_IMPORT, IMS_COMIC_BOOK_DB_OBJECT_FETCHED, } from "../constants/action-types"; -import { difference } from "../shared/utils/object.utils"; -import { isNil, isEmpty, isUndefined } from "lodash"; +import { isNil, isUndefined } from "lodash"; import axios from "axios"; interface SearchData { @@ -133,6 +133,19 @@ export const downloadAirDCPPItem = const downloadResult = await ADCPPSocket.post( `search/${instanceId}/results/${resultId}/download`, ); + let downloadStatus = undefined; + // download status check + await ADCPPSocket.addListener(`queue`, "queue_file_status", (status) => { + if (status.status.completed) { + downloadStatus = status; + + dispatch({ + type: LS_SINGLE_IMPORT, + meta: { remote: true }, + data: { downloadStatus }, + }); + } + }); let bundleId; let directoryIds; @@ -197,17 +210,6 @@ export const getDownloadProgress = }); }, ); - let downloadStatus = undefined; - // download status check - await ADCPPSocket.addListener(`queue`, "queue_file_status", (status) => { - if (isUndefined(downloadStatus)) { - downloadStatus = status; - dispatch({ - type: AIRDCPP_FILE_DOWNLOAD_COMPLETED, - status, - }); - } - }); } catch (error) { throw error; } diff --git a/src/client/constants/action-types.ts b/src/client/constants/action-types.ts index f0b8bfd..3ed9600 100644 --- a/src/client/constants/action-types.ts +++ b/src/client/constants/action-types.ts @@ -105,6 +105,7 @@ export const AIRDCPP_RESULT_DOWNLOAD_INITIATED = "AIRDCPP_RESULT_DOWNLOAD_INITIATED"; export const AIRDCPP_FILE_DOWNLOAD_COMPLETED = "AIRDCPP_FILE_DOWNLOAD_COMPLETED"; +export const LS_SINGLE_IMPORT = "LS_SINGLE_IMPORT"; export const AIRDCPP_BUNDLES_FETCHED = "AIRDCPP_BUNDLES_FETCHED"; export const AIRDCPP_DOWNLOAD_PROGRESS_TICK = "AIRDCPP_DOWNLOAD_PROGRESS_TICK";