mirror of
https://github.com/Equicord/Equicord.git
synced 2025-06-10 23:23:04 -04:00
feat(api): Message Accessories API (#131)
This commit is contained in:
parent
4b1e96b76e
commit
e2b622c76b
3 changed files with 66 additions and 7 deletions
41
src/api/MessageAccessories.ts
Normal file
41
src/api/MessageAccessories.ts
Normal file
|
@ -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;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue