Skip to content

Commit

Permalink
Merge pull request #26933 from software-mansion-labs/ts-migration/gro…
Browse files Browse the repository at this point in the history
…wl-lib
  • Loading branch information
francoisl authored Sep 13, 2023
2 parents 2435680 + 0451f2f commit da94df6
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 51 deletions.
51 changes: 0 additions & 51 deletions src/libs/Growl.js

This file was deleted.

49 changes: 49 additions & 0 deletions src/libs/Growl.ts
Original file line number Diff line number Diff line change
@@ -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<GrowlRef>();
let resolveIsReadyPromise: undefined | ((value?: unknown) => void);
const isReadyPromise = new Promise((resolve) => {
resolveIsReadyPromise = resolve;
});

function setIsReady() {
if (!resolveIsReadyPromise) return;
resolveIsReadyPromise();
}

/**
* Show the growl notification
*/
function show(bodyText: string, type: string, duration: number = CONST.GROWL.DURATION) {
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) {
show(bodyText, CONST.GROWL.ERROR, duration);
}

/**
* Show success growl
*/
function success(bodyText: string, duration: number = CONST.GROWL.DURATION) {
show(bodyText, CONST.GROWL.SUCCESS, duration);
}

export default {
show,
error,
success,
};

export {growlRef, setIsReady};

0 comments on commit da94df6

Please sign in to comment.