Skip to content

Commit

Permalink
code review updates
Browse files Browse the repository at this point in the history
  • Loading branch information
TMisiukiewicz committed Feb 14, 2024
1 parent bbbdd16 commit 025a9a0
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 11 deletions.
3 changes: 2 additions & 1 deletion src/libs/localFileCreate/index.native.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import RNFetchBlob from 'react-native-blob-util';
import * as FileUtils from '@libs/fileDownload/FileUtils';
import type LocalFileCreate from './types';

/**
* Creates a blob file using RN Fetch Blob
* @param fileName name of the file
* @param textContent content of the file
* @returns path, filename and size of the newly created file
*/
const localFileCreate = (fileName: string, textContent: string) => {
const localFileCreate: LocalFileCreate = (fileName, textContent) => {
const newFileName = FileUtils.appendTimeToFileName(fileName);
const dir = RNFetchBlob.fs.dirs.DocumentDir;
const path = `${dir}/${newFileName}.txt`;
Expand Down
3 changes: 2 additions & 1 deletion src/libs/localFileCreate/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import * as FileUtils from '@libs/fileDownload/FileUtils';
import type LocalFileCreate from './types';

/**
* Creates a Blob file
* @param fileName name of the file
* @param textContent content of the file
* @returns path, filename and size of the newly created file
*/
const localFileCreate = (fileName: string, textContent: string) => {
const localFileCreate: LocalFileCreate = (fileName, textContent) => {
const newFileName = FileUtils.appendTimeToFileName(fileName);
const blob = new Blob([textContent], {type: 'text/plain'});
const url = URL.createObjectURL(blob);
Expand Down
3 changes: 3 additions & 0 deletions src/libs/localFileCreate/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
type LocalFileCreate = (fileName: string, textContent: string) => Promise<{path: string; newFileName: string; size: number}>;

export default LocalFileCreate;
2 changes: 1 addition & 1 deletion src/libs/localFileDownload/index.ios.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {Share} from 'react-native';
import RNFetchBlob from 'react-native-blob-util';
import localFileCreate from '@libs/localFileCreate/index.native';
import localFileCreate from '@libs/localFileCreate';
import type LocalFileDownload from './types';

/**
Expand Down
5 changes: 2 additions & 3 deletions src/libs/localFileDownload/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as FileUtils from '@libs/fileDownload/FileUtils';
import localFileCreate from '@libs/localFileCreate';
import type LocalFileDownload from './types';

Expand All @@ -8,9 +7,9 @@ import type LocalFileDownload from './types';
* is downloaded by the browser.
*/
const localFileDownload: LocalFileDownload = (fileName, textContent) => {
localFileCreate(fileName, textContent).then(({path}) => {
localFileCreate(`${fileName}.txt`, textContent).then(({path, newFileName}) => {
const link = document.createElement('a');
link.download = FileUtils.appendTimeToFileName(`${fileName}.txt`);
link.download = newFileName;
link.href = path;
link.click();
});
Expand Down
9 changes: 4 additions & 5 deletions src/pages/settings/AboutPage/ConsolePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type ConsolePageProps = ConsolePageOnyxProps;
* @param logs Logs captured on the current device
* @returns CapturedLogs with parsed messages
*/
const parseStingifiedMessages = (logs: Log[]) => {
const parseStringifyMessages = (logs: Log[]) => {
if (isEmpty(logs)) {
return;
}
Expand Down Expand Up @@ -77,8 +77,7 @@ function ConsolePage({capturedLogs, shouldStoreLogs}: ConsolePageProps) {
}

setLogs((prevLogs) => ({...prevLogs, ...capturedLogs}));
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [capturedLogs]);
}, [capturedLogs, shouldStoreLogs]);

const executeArbitraryCode = () => {
const sanitizedInput = sanitizeConsoleInput(input);
Expand All @@ -91,14 +90,14 @@ function ConsolePage({capturedLogs, shouldStoreLogs}: ConsolePageProps) {
useKeyboardShortcut(CONST.KEYBOARD_SHORTCUTS.ENTER, executeArbitraryCode);

const saveLogs = () => {
const logsWithParsedMessages = parseStingifiedMessages(logsList);
const logsWithParsedMessages = parseStringifyMessages(logsList);

localFileDownload('logs', JSON.stringify(logsWithParsedMessages, null, 2));
};

const shareLogs = () => {
setIsGeneratingLogsFile(true);
const logsWithParsedMessages = parseStingifiedMessages(logsList);
const logsWithParsedMessages = parseStringifyMessages(logsList);

// Generate a file with the logs and pass its path to the list of reports to share it with
localFileCreate('logs', JSON.stringify(logsWithParsedMessages, null, 2)).then(({path, size}) => {
Expand Down

0 comments on commit 025a9a0

Please sign in to comment.