Skip to content

Commit

Permalink
[TS migration] Migrate 'Download.js' lib to TypeScript
Browse files Browse the repository at this point in the history
  • Loading branch information
blazejkustra committed Sep 13, 2023
1 parent b7539df commit 6593db0
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions src/libs/actions/Download.js → src/libs/actions/Download.ts
Original file line number Diff line number Diff line change
@@ -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<void> {
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<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 6593db0

Please sign in to comment.