Skip to content

Commit

Permalink
Merge pull request #27351 from software-mansion-labs/ts-migration/Don…
Browse files Browse the repository at this point in the history
…wload

[No QA][TS migration] Migrate 'Download.js' lib to TypeScript
  • Loading branch information
MonilBhavsar authored Sep 19, 2023
2 parents ae30313 + 7d11afc commit e90b043
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/libs/actions/Download.js → src/libs/actions/Download.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
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<void> {
return Onyx.merge(`${ONYXKEYS.COLLECTION.DOWNLOAD}${sourceID}`, {isDownloading});
}

Expand All @@ -19,9 +14,12 @@ function clearDownloads() {
waitForCollectionCallback: true,
callback: (records) => {
Onyx.disconnect(connectionID);
const downloadsToDelete = {};
_.each(_.keys(records), (recordKey) => (downloadsToDelete[recordKey] = null));
if (!_.isEmpty(downloadsToDelete)) {
const downloadsToDelete: Record<string, null> = {};
Object.keys(records ?? {}).forEach((recordKey) => {
downloadsToDelete[recordKey] = null;
});

if (Object.keys(downloadsToDelete).length > 0) {
Onyx.multiSet(downloadsToDelete);
}
},
Expand Down

0 comments on commit e90b043

Please sign in to comment.