From 025a9a0d3e35975734329f9002b43960bbe99850 Mon Sep 17 00:00:00 2001 From: Tomasz Misiukiewicz Date: Wed, 14 Feb 2024 15:48:39 +0100 Subject: [PATCH] code review updates --- src/libs/localFileCreate/index.native.ts | 3 ++- src/libs/localFileCreate/index.ts | 3 ++- src/libs/localFileCreate/types.ts | 3 +++ src/libs/localFileDownload/index.ios.ts | 2 +- src/libs/localFileDownload/index.ts | 5 ++--- src/pages/settings/AboutPage/ConsolePage.tsx | 9 ++++----- 6 files changed, 14 insertions(+), 11 deletions(-) create mode 100644 src/libs/localFileCreate/types.ts diff --git a/src/libs/localFileCreate/index.native.ts b/src/libs/localFileCreate/index.native.ts index a6a5630998f5..418701ae3ff5 100644 --- a/src/libs/localFileCreate/index.native.ts +++ b/src/libs/localFileCreate/index.native.ts @@ -1,5 +1,6 @@ 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 @@ -7,7 +8,7 @@ import * as FileUtils from '@libs/fileDownload/FileUtils'; * @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`; diff --git a/src/libs/localFileCreate/index.ts b/src/libs/localFileCreate/index.ts index 0bb8ebc585cd..0178a6c76f7c 100644 --- a/src/libs/localFileCreate/index.ts +++ b/src/libs/localFileCreate/index.ts @@ -1,4 +1,5 @@ import * as FileUtils from '@libs/fileDownload/FileUtils'; +import type LocalFileCreate from './types'; /** * Creates a Blob file @@ -6,7 +7,7 @@ import * as FileUtils from '@libs/fileDownload/FileUtils'; * @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); diff --git a/src/libs/localFileCreate/types.ts b/src/libs/localFileCreate/types.ts new file mode 100644 index 000000000000..e8e8084cb567 --- /dev/null +++ b/src/libs/localFileCreate/types.ts @@ -0,0 +1,3 @@ +type LocalFileCreate = (fileName: string, textContent: string) => Promise<{path: string; newFileName: string; size: number}>; + +export default LocalFileCreate; diff --git a/src/libs/localFileDownload/index.ios.ts b/src/libs/localFileDownload/index.ios.ts index 0e57cb4a23c5..778d19d9449b 100644 --- a/src/libs/localFileDownload/index.ios.ts +++ b/src/libs/localFileDownload/index.ios.ts @@ -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'; /** diff --git a/src/libs/localFileDownload/index.ts b/src/libs/localFileDownload/index.ts index e63455f243a9..a1a20a0e3d4a 100644 --- a/src/libs/localFileDownload/index.ts +++ b/src/libs/localFileDownload/index.ts @@ -1,4 +1,3 @@ -import * as FileUtils from '@libs/fileDownload/FileUtils'; import localFileCreate from '@libs/localFileCreate'; import type LocalFileDownload from './types'; @@ -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(); }); diff --git a/src/pages/settings/AboutPage/ConsolePage.tsx b/src/pages/settings/AboutPage/ConsolePage.tsx index 40c114e3409b..5c5e9ba91874 100644 --- a/src/pages/settings/AboutPage/ConsolePage.tsx +++ b/src/pages/settings/AboutPage/ConsolePage.tsx @@ -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; } @@ -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); @@ -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}) => {