Skip to content

Added some features :) #90

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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;
}

/**
@@ -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
@@ -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";