Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[No QA] [TS migration] Migrate 'localFileDownload' lib to TypeScript  #27857

Merged
merged 6 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import RNFetchBlob from 'react-native-blob-util';
import * as FileUtils from '../fileDownload/FileUtils';
import LocalFileDownload from './types';

/**
* Writes a local file to the app's internal directory with the given fileName
* and textContent, so we're able to copy it to the Android public download dir.
* After the file is copied, it is removed from the internal dir.
*
* @param {String} fileName
* @param {String} textContent
*/
export default function localFileDownload(fileName, textContent) {
export default function localFileDownload({fileName, textContent}: LocalFileDownload) {
const newFileName = FileUtils.appendTimeToFileName(fileName);
const dir = RNFetchBlob.fs.dirs.DocumentDir;
const path = `${dir}/${newFileName}.txt`;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import {Share} from 'react-native';
import RNFetchBlob from 'react-native-blob-util';
import * as FileUtils from '../fileDownload/FileUtils';
import LocalFileDownload from './types';

/**
* Writes a local file to the app's internal directory with the given fileName
* and textContent, so we're able to share it using iOS' share API.
* After the file is shared, it is removed from the internal dir.
*
* @param {String} fileName
* @param {String} textContent
*/
export default function localFileDownload(fileName, textContent) {
export default function localFileDownload({fileName, textContent}: LocalFileDownload) {
teneeto marked this conversation as resolved.
Show resolved Hide resolved
const newFileName = FileUtils.appendTimeToFileName(fileName);
const dir = RNFetchBlob.fs.dirs.DocumentDir;
const path = `${dir}/${newFileName}.txt`;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import * as FileUtils from '../fileDownload/FileUtils';
import LocalFileDownload from './types';

/**
* Creates a Blob with the given fileName and textContent, then dynamically
* creates a temporary anchor, just to programmatically click it, so the file
* is downloaded by the browser.
*
* @param {String} fileName
* @param {String} textContent
*/
export default function localFileDownload(fileName, textContent) {
export default function localFileDownload({fileName, textContent}: LocalFileDownload) {
const blob = new Blob([textContent], {type: 'text/plain'});
const url = URL.createObjectURL(blob);
const link = document.createElement('a');
Expand Down
5 changes: 5 additions & 0 deletions src/libs/localFileDownload/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type LocalFileDownload = {
fileName: string;
textContent: string;
};
teneeto marked this conversation as resolved.
Show resolved Hide resolved
export default LocalFileDownload;
teneeto marked this conversation as resolved.
Show resolved Hide resolved
Loading