Add new functions

Zack 2019-05-22 00:41:44 -04:00
parent eb929a3444
commit 57bab31867
1 changed files with 59 additions and 0 deletions

@ -173,6 +173,28 @@ Searches for an internal Discord webpack module that has every property passed.
***
#### `findModuleByPrototypes(...protos)`
Searches for an internal Discord webpack module that has every property passed on its prototype.
|Parameter|Type|Description|
|-|-|:-|
|`protos`|...string|A series of prototype properties to check for.|
**@Returns** `{any|null}` - the module found or null if none were found.
***
#### `findModuleByDisplayName(name)`
Searches for an internal Discord webpack module with a specific `displayName` value.
|Parameter|Type|Description|
|-|-|:-|
|`name`|string|The `displayName` to look for.|
**@Returns** `{any|null}` - the module found or null if none were found.
***
#### `getCore()`
Returns BandagedBD's instance of the core module. Only use this if you know what you are doing.
@ -289,6 +311,43 @@ Alias for [saveData(pluginName, key, data)](#savedatapluginname-key-data)
***
#### `showConfirmationModal(title, content, options = {})`
Shows a generic but very customizable confirmation modal with optional confirm and cancel callbacks.
|Parameter|Type|Description|
|-|-|:-|
|`title`|string|Title of the modal.|
|`children`|string \| ReactElement \| Array<string\|ReactElement>|A single or mixed array of react elements and strings. Everything is wrapped in Discord's `TextElement` component so strings will show and render properly.|
|`[options]`|object|Options to modify the modal.|
|`[options.danger=false]`|boolean|Whether the main button should be red or not.|
|`[options.confirmText=Okay]`|string|Text for the confirmation/submit button.|
|`[options.cancelText=Cancel]`|string|Text for the cancel button.|
|`[options.onConfirm=NOOP]`|function|Callback to occur when clicking the submit button.|
|`[options.onCancel=NOOP]`|function|Callback to occur when clicking the cancel button.|
**Example**
```js
BdApi.showConfirmationModal("Test",
[
"This is not a link. ",
BdApi.React.createElement("a", {href: "https://google.com", target: "_blank"}, "This is a link."),
" This is not."
],
{
danger: true,
confirmText: "Oh No",
cancelText: "Go Back"
}
);
```
In the snippet above we can see that the `children` parameter has a mix of strings and React Elements. This should still result in them being in the same level of the DOM and rendering properly.
In the `options` parameter, `danger` is set to `true` so the main button should be red. `confirmText` and `cancelText` so the buttons should look accordingly.
The resulting modal can be seen in [this image](https://i.imgur.com/4EtKP4M.png).
***
#### `showToast(content, options = {})`
Shows a simple toast message similar to on Android. An example of the `success` toast can be seen [here](https://i.zackrauen.com/zIagVa.png).