Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions web/src/utils/debugData.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {isEnvBrowser} from "./misc";

interface DebugEvent<T = any> {
interface DebugEvent {
action: string;
data: T;
data: any;
}

/**
Expand All @@ -12,19 +12,18 @@ interface DebugEvent<T = any> {
* @param events - The event you want to cover
* @param timer - How long until it should trigger (ms)
*/
export const debugData = <P>(events: DebugEvent<P>[], timer = 1000): void => {
export const debugData = (events: DebugEvent[], timer = 1000): void => {
if (isEnvBrowser()) {
for (const event of events) {
setTimeout(() => {
window.dispatchEvent(
new MessageEvent("message", {
data: {
action: event.action,
data: event.data,
...event
},
})
);
}, timer);
}
}
};
};
9 changes: 7 additions & 2 deletions web/src/utils/fetchNui.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { isEnvBrowser } from "./misc"
/**
* @param eventName - The endpoint eventname to target
* @param data - Data you wish to send in the NUI Callback
Expand All @@ -7,16 +8,20 @@

export async function fetchNui<T = any>(
eventName: string,
data: unknown = {}
data: unknown = {},
mockData: unknown = {}
): Promise<T> {
if (isEnvBrowser() && mockData) {
return mockData
}
const options = {
method: "post",
headers: {
"Content-Type": "application/json; charset=UTF-8",
},
body: JSON.stringify(data),
};

const resourceName = (window as any).GetParentResourceName
? (window as any).GetParentResourceName()
: "nui-frame-app";
Expand Down