From 878f03db9b40ee7740f472936738a07fb5929d7f Mon Sep 17 00:00:00 2001 From: Bartosz Grajdek Date: Thu, 7 Sep 2023 10:47:47 +0200 Subject: [PATCH 1/2] [TS migration] Migrate 'Growl.js' lib to TypeScript --- src/libs/Growl.js | 51 ----------------------------------------------- src/libs/Growl.ts | 49 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 51 deletions(-) delete mode 100644 src/libs/Growl.js create mode 100644 src/libs/Growl.ts diff --git a/src/libs/Growl.js b/src/libs/Growl.js deleted file mode 100644 index 81994dd4c255..000000000000 --- a/src/libs/Growl.js +++ /dev/null @@ -1,51 +0,0 @@ -import React from 'react'; -import CONST from '../CONST'; - -const growlRef = React.createRef(); -let resolveIsReadyPromise; -const isReadyPromise = new Promise((resolve) => { - resolveIsReadyPromise = resolve; -}); - -function setIsReady() { - resolveIsReadyPromise(); -} - -/** - * Show the growl notification - * - * @param {String} bodyText - * @param {String} type - * @param {Number} [duration] - */ -function show(bodyText, type, duration = CONST.GROWL.DURATION) { - isReadyPromise.then(() => growlRef.current.show(bodyText, type, duration)); -} - -/** - * Show error growl - * - * @param {String} bodyText - * @param {Number} [duration] - */ -function error(bodyText, duration = CONST.GROWL.DURATION) { - show(bodyText, CONST.GROWL.ERROR, duration); -} - -/** - * Show success growl - * - * @param {String} bodyText - * @param {Number} [duration] - */ -function success(bodyText, duration = CONST.GROWL.DURATION) { - show(bodyText, CONST.GROWL.SUCCESS, duration); -} - -export default { - show, - error, - success, -}; - -export {growlRef, setIsReady}; diff --git a/src/libs/Growl.ts b/src/libs/Growl.ts new file mode 100644 index 000000000000..3d433e00b64a --- /dev/null +++ b/src/libs/Growl.ts @@ -0,0 +1,49 @@ +import React from 'react'; +import CONST from '../CONST'; + +type GrowlRef = { + show?: (bodyText: string, type: string, duration: number) => void; +}; + +const growlRef = React.createRef(); +let resolveIsReadyPromise: undefined | ((value?: unknown) => void); +const isReadyPromise = new Promise((resolve) => { + resolveIsReadyPromise = resolve; +}); + +function setIsReady(): void { + if (!resolveIsReadyPromise) return; + resolveIsReadyPromise(); +} + +/** + * Show the growl notification + */ +function show(bodyText: string, type: string, duration: number = CONST.GROWL.DURATION): void { + isReadyPromise.then(() => { + if (!growlRef?.current?.show) return; + growlRef.current.show(bodyText, type, duration); + }); +} + +/** + * Show error growl + */ +function error(bodyText: string, duration: number = CONST.GROWL.DURATION): void { + show(bodyText, CONST.GROWL.ERROR, duration); +} + +/** + * Show success growl + */ +function success(bodyText: string, duration: number = CONST.GROWL.DURATION): void { + show(bodyText, CONST.GROWL.SUCCESS, duration); +} + +export default { + show, + error, + success, +}; + +export {growlRef, setIsReady}; From 0451f2ff68abf6c0712b627814c056865fc213b1 Mon Sep 17 00:00:00 2001 From: Bartosz Grajdek Date: Tue, 12 Sep 2023 11:34:54 +0200 Subject: [PATCH 2/2] Remove void return --- src/libs/Growl.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libs/Growl.ts b/src/libs/Growl.ts index 3d433e00b64a..99c728f0a210 100644 --- a/src/libs/Growl.ts +++ b/src/libs/Growl.ts @@ -11,7 +11,7 @@ const isReadyPromise = new Promise((resolve) => { resolveIsReadyPromise = resolve; }); -function setIsReady(): void { +function setIsReady() { if (!resolveIsReadyPromise) return; resolveIsReadyPromise(); } @@ -19,7 +19,7 @@ function setIsReady(): void { /** * Show the growl notification */ -function show(bodyText: string, type: string, duration: number = CONST.GROWL.DURATION): void { +function show(bodyText: string, type: string, duration: number = CONST.GROWL.DURATION) { isReadyPromise.then(() => { if (!growlRef?.current?.show) return; growlRef.current.show(bodyText, type, duration); @@ -29,14 +29,14 @@ function show(bodyText: string, type: string, duration: number = CONST.GROWL.DUR /** * Show error growl */ -function error(bodyText: string, duration: number = CONST.GROWL.DURATION): void { +function error(bodyText: string, duration: number = CONST.GROWL.DURATION) { show(bodyText, CONST.GROWL.ERROR, duration); } /** * Show success growl */ -function success(bodyText: string, duration: number = CONST.GROWL.DURATION): void { +function success(bodyText: string, duration: number = CONST.GROWL.DURATION) { show(bodyText, CONST.GROWL.SUCCESS, duration); }