Skip to content

Commit

Permalink
feat(web): initial update to vite (#157)
Browse files Browse the repository at this point in the history
  • Loading branch information
itschip committed Jan 24, 2024
1 parent cf4b460 commit 010d232
Show file tree
Hide file tree
Showing 14 changed files with 862 additions and 566 deletions.
30 changes: 17 additions & 13 deletions src/client/cl_events.ts
Expand Up @@ -44,55 +44,59 @@ const waitForNUILoaded = (checkInterval = 250): Promise<void> => {
});
};

const SendBankUIMessage = (data: object) => {
SendNUIMessage(data);
const SendBankUIMessage = (app: string, method: string, data: unknown) => {
SendNUIMessage({
app,
method,
data,
});

if (GetResourceState('npwd') === 'started') {
npwdExports.sendUIMessage(data);
npwdExports.sendNPWDMessage(app, method, data);
}
};

onNet(Broadcasts.NewAccount, (payload: Account) => {
SendBankUIMessage({ type: Broadcasts.NewAccount, payload });
SendBankUIMessage('PEFCL', Broadcasts.NewAccount, payload);
});

onNet(Broadcasts.NewAccountBalance, (balance: number) => {
SendBankUIMessage({ type: Broadcasts.NewAccountBalance, payload: balance });
SendBankUIMessage('PEFCL', Broadcasts.NewAccountBalance, balance);
});

onNet(Broadcasts.NewTransaction, (payload: Transaction) => {
SendBankUIMessage({ type: Broadcasts.NewTransaction, payload });
SendBankUIMessage('PEFCL', Broadcasts.NewTransaction, payload);
});

onNet(Broadcasts.UpdatedAccount, (payload: Account) => {
SendBankUIMessage({ type: Broadcasts.UpdatedAccount, payload });
SendBankUIMessage('PEFCL', Broadcasts.UpdatedAccount, payload);
});

onNet(Broadcasts.NewInvoice, (payload: Invoice) => {
SendBankUIMessage({ type: Broadcasts.NewInvoice, payload });
SendBankUIMessage('PEFCL', Broadcasts.NewInvoice, payload);
});

onNet(Broadcasts.NewSharedUser, () => {
SendBankUIMessage({ type: Broadcasts.NewSharedUser });
SendBankUIMessage('PEFCL', Broadcasts.NewSharedUser, {});
});

onNet(Broadcasts.RemovedSharedUser, () => {
SendBankUIMessage({ type: Broadcasts.RemovedSharedUser });
SendBankUIMessage('PEFCL', Broadcasts.RemovedSharedUser, {});
});

onNet(UserEvents.Loaded, async () => {
console.debug('Waiting for NUI to load ..');
await waitForNUILoaded();
console.debug('Loaded. Emitting data to NUI.');
SendBankUIMessage({ type: UserEvents.Loaded, payload: true });
SendBankUIMessage('PEFCL', UserEvents.Loaded, true);

if (!useFrameworkIntegration) {
StatSetInt(CASH_BAL_STAT, (await API.getMyCash()) ?? 0, true);
}
});

onNet(UserEvents.Unloaded, () => {
SendBankUIMessage({ type: UserEvents.Unloaded });
SendBankUIMessage('PEFCL', UserEvents.Unloaded, {});
});

const CASH_BAL_STAT = GetHashKey('MP0_WALLET_BALANCE');
Expand Down Expand Up @@ -130,7 +134,7 @@ RegisterCommand(
console.debug('Waiting for NUI to load ..');
await waitForNUILoaded();
console.debug('Loaded. Emitting data to NUI.');
SendBankUIMessage({ type: UserEvents.Loaded, payload: true });
SendBankUIMessage('PEFCL', UserEvents.Loaded, true);
},
false,
);
9 changes: 6 additions & 3 deletions src/client/client.ts
Expand Up @@ -18,7 +18,10 @@ export const setBankIsOpen = (bool: boolean) => {
}

isBankOpen = bool;
SendNUIMessage({ type: 'setVisible', payload: bool });
SendNUIMessage({ app: 'PEFCL', method: 'setVisible', data: bool });

console.log('setBankIsOpen', bool);

SetNuiFocus(bool, bool);
};

Expand All @@ -28,7 +31,7 @@ export const setAtmIsOpen = (bool: boolean) => {
}

isAtmOpen = bool;
SendNUIMessage({ type: 'setVisibleATM', payload: bool });
SendNUIMessage({ app: 'PEFCL', method: 'setVisibleATM', data: bool });
SetNuiFocus(bool, bool);
};

Expand Down Expand Up @@ -63,7 +66,7 @@ if (!useFrameworkIntegration) {
if (!config.atms?.props?.includes(model)) return console.log('not atm');

isAtmOpen = !isAtmOpen;
SendNUIMessage({ type: 'setVisibleATM', payload: isAtmOpen });
SendNUIMessage({ app: 'PEFCL', method: 'setVisibleATM', data: isAtmOpen });

if (isAtmOpen) {
SetNuiFocus(true, true);
Expand Down
1 change: 0 additions & 1 deletion src/package.json
Expand Up @@ -59,7 +59,6 @@
"prettier": "^2.5.1",
"reflect-metadata": "^0.1.13",
"sequelize": "^6.17.0",
"tedious": "^14.3.0",
"tsyringe": "^4.6.0",
"winston": "^3.4.0"
}
Expand Down

0 comments on commit 010d232

Please sign in to comment.