From 6593db0c090916d68af5bfcf837eabf7fd7f0a6d Mon Sep 17 00:00:00 2001 From: Blazej Kustra Date: Wed, 13 Sep 2023 15:55:28 +0200 Subject: [PATCH 1/2] [TS migration] Migrate 'Download.js' lib to TypeScript --- src/libs/actions/{Download.js => Download.ts} | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) rename src/libs/actions/{Download.js => Download.ts} (60%) diff --git a/src/libs/actions/Download.js b/src/libs/actions/Download.ts similarity index 60% rename from src/libs/actions/Download.js rename to src/libs/actions/Download.ts index 41e3cb136e3a..0ecda432a244 100644 --- a/src/libs/actions/Download.js +++ b/src/libs/actions/Download.ts @@ -1,27 +1,25 @@ -import _ from 'underscore'; import Onyx from 'react-native-onyx'; import ONYXKEYS from '../../ONYXKEYS'; /** * Set whether an attachment is being downloaded so that a spinner can be shown. - * - * @param {String} sourceID - * @param {Boolean} isDownloading - * @returns {Promise} */ -function setDownload(sourceID, isDownloading) { +function setDownload(sourceID: string, isDownloading: boolean): Promise { return Onyx.merge(`${ONYXKEYS.COLLECTION.DOWNLOAD}${sourceID}`, {isDownloading}); } -function clearDownloads() { +function clearDownloads(): void { const connectionID = Onyx.connect({ key: ONYXKEYS.COLLECTION.DOWNLOAD, waitForCollectionCallback: true, callback: (records) => { Onyx.disconnect(connectionID); - const downloadsToDelete = {}; - _.each(_.keys(records), (recordKey) => (downloadsToDelete[recordKey] = null)); - if (!_.isEmpty(downloadsToDelete)) { + const downloadsToDelete: Record = {}; + Object.keys(records ?? {}).forEach((recordKey) => { + downloadsToDelete[recordKey] = null; + }); + + if (Object.keys(downloadsToDelete).length > 0) { Onyx.multiSet(downloadsToDelete); } }, From 7d11afc341944e2a6c1628273e30f2c85ae0a626 Mon Sep 17 00:00:00 2001 From: Blazej Kustra Date: Thu, 14 Sep 2023 09:19:41 +0200 Subject: [PATCH 2/2] Remove void return type --- src/libs/actions/Download.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/Download.ts b/src/libs/actions/Download.ts index 0ecda432a244..06b97d735d39 100644 --- a/src/libs/actions/Download.ts +++ b/src/libs/actions/Download.ts @@ -8,7 +8,7 @@ function setDownload(sourceID: string, isDownloading: boolean): Promise { return Onyx.merge(`${ONYXKEYS.COLLECTION.DOWNLOAD}${sourceID}`, {isDownloading}); } -function clearDownloads(): void { +function clearDownloads() { const connectionID = Onyx.connect({ key: ONYXKEYS.COLLECTION.DOWNLOAD, waitForCollectionCallback: true,