diff options
author | Cynthia Foxwell <gamers@riseup.net> | 2022-10-21 16:17:18 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-22 00:17:18 +0200 |
commit | e2b622c76bd3f25f674c4c3ff899bef756cdf6ca (patch) | |
tree | eccb4c0dcb7cf54f3f66504e308a45b217f5aecf /src/api/MessageAccessories.ts | |
parent | 4b1e96b76ee4eea16fcb3b5cae74e173541b3c74 (diff) | |
download | Vencord-e2b622c76bd3f25f674c4c3ff899bef756cdf6ca.tar.gz Vencord-e2b622c76bd3f25f674c4c3ff899bef756cdf6ca.tar.bz2 Vencord-e2b622c76bd3f25f674c4c3ff899bef756cdf6ca.zip |
feat(api): Message Accessories API (#131)
Diffstat (limited to 'src/api/MessageAccessories.ts')
-rw-r--r-- | src/api/MessageAccessories.ts | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/api/MessageAccessories.ts b/src/api/MessageAccessories.ts new file mode 100644 index 0000000..3a46828 --- /dev/null +++ b/src/api/MessageAccessories.ts @@ -0,0 +1,41 @@ +export type AccessoryCallback = (props: Record<string, any>) => JSX.Element; +export type Accessory = { + callback: AccessoryCallback; + position?: number; +}; + +export const accessories = new Map<String, Accessory>(); + +export function addAccessory( + identifier: string, + callback: AccessoryCallback, + position?: number +) { + accessories.set(identifier, { + callback, + position, + }); +} + +export function removeAccessory(identifier: string) { + accessories.delete(identifier); +} + +export function _modifyAccessories( + elements: JSX.Element[], + props: Record<string, any> +) { + for (const accessory of accessories.values()) { + elements.splice( + accessory.position != null + ? accessory.position < 0 + ? elements.length + accessory.position + : accessory.position + : elements.length, + 0, + accessory.callback(props) + ); + } + + return elements; +} |