mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-04 14:38:45 +00:00
cleanup: Recoil State Type Safety + Misc Cleanup (#189)
* chore(phone/settings): Removed unused state * cleanup(phone/photos): Added type safety to photo state * tweak(phone/marketplace): Added type safety to marketplace state * chore(phone/match): Removed unnecessary console.log * tweak(phone/messages): Added type safety to messages state Also fixed ESLint warning for exported anonymous hook in useMessages.ts * tweak(phone/match): Added type safety to match state * tweak(phone/dialer): Cleanup & type safety for state Renamed some types to better represent their data * cleanup(phone/gen): Added NUI event enums for phone events * tweak(phone/contacts): Type safety for contacts state & variable rename Renamed and type variable in setFilteredContacts to better represent its use * tweak(phone/gen-state): Added type-safety to gen phone global state * tweak(phone/settings): Type safety for settings state * tweak(phone/photos): Tweaked type for photo referral * fix(phone/notification-comp): Fix reference to old theme config * chore(phone/hooks): Remove keyboard service Removed as this was unused and ESLint was not happy with it * chore(phone): Cleaned up eslint warnings No more warnings hooray! * tweak(phone): Set time in dev mode * fix(phone): Remove useNuiService that appeared somehow * fix(phone/gallery): Fixed missing import for gallery * Revert removing the keyboard service as this is built upon in another PR This reverts commit 82d12255a84e918da087d988b599af98ce1fe54d. * fix(phone/keyboard): Add useKeyboardService hook back to Phone.tsx * fix(phone/gallery): Fix and standardized GalleryPhoto type
This commit is contained in:
35 files changed
+137
-148
No files matched your search
+22
-19
@@ -1,5 +1,5 @@
|
||||
import { CallEvents } from '../../typings/call';
|
||||
import { ICall } from '../../typings/call';
|
||||
import { CallHistoryItem } from '../../typings/call';
|
||||
import { phoneCallStartAnim, phoneCallEndAnim } from './functions';
|
||||
|
||||
const exp = (global as any).exports;
|
||||
@@ -34,23 +34,26 @@ on(`__cfx_nui:${CallEvents.ACCEPT_CALL}`, (data: any, cb: Function) => {
|
||||
cb();
|
||||
});
|
||||
|
||||
onNet(CallEvents.WAS_ACCEPTED, (channelId: number, currentCall: ICall, isTransmitter: boolean) => {
|
||||
exp['mumble-voip'].SetCallChannel(channelId);
|
||||
phoneCallStartAnim(); // Trigger call animation only if the call was accepted.
|
||||
SendNuiMessage(
|
||||
JSON.stringify({
|
||||
app: 'CALL',
|
||||
method: CallEvents.SET_CALLER,
|
||||
data: {
|
||||
active: true,
|
||||
transmitter: currentCall.transmitter,
|
||||
receiver: currentCall.receiver,
|
||||
isTransmitter: isTransmitter,
|
||||
accepted: true,
|
||||
},
|
||||
}),
|
||||
);
|
||||
});
|
||||
onNet(
|
||||
CallEvents.WAS_ACCEPTED,
|
||||
(channelId: number, currentCall: CallHistoryItem, isTransmitter: boolean) => {
|
||||
exp['mumble-voip'].SetCallChannel(channelId);
|
||||
phoneCallStartAnim(); // Trigger call animation only if the call was accepted.
|
||||
SendNuiMessage(
|
||||
JSON.stringify({
|
||||
app: 'CALL',
|
||||
method: CallEvents.SET_CALLER,
|
||||
data: {
|
||||
active: true,
|
||||
transmitter: currentCall.transmitter,
|
||||
receiver: currentCall.receiver,
|
||||
isTransmitter: isTransmitter,
|
||||
accepted: true,
|
||||
},
|
||||
}),
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
RegisterNuiCallbackType(CallEvents.REJECTED); // Fires when cancelling and rejecting a call.
|
||||
on(`__cfx_nui:${CallEvents.REJECTED}`, (data: any, cb: Function) => {
|
||||
@@ -115,7 +118,7 @@ function openCallModal(show: boolean) {
|
||||
);
|
||||
}
|
||||
|
||||
onNet(CallEvents.SEND_HISTORY, (calls: ICall) => {
|
||||
onNet(CallEvents.SEND_HISTORY, (calls: CallHistoryItem[]) => {
|
||||
SendNuiMessage(
|
||||
JSON.stringify({
|
||||
app: 'DIALER',
|
||||
|
||||
@@ -55,14 +55,14 @@ const showPhone = async (): Promise<void> => {
|
||||
await phoneOpenAnim(); // Animation starts before the phone is open
|
||||
emitNet('phone:getCredentials');
|
||||
SetCursorLocation(0.9, 0.922); //Experimental
|
||||
sendMessage('PHONE', 'setVisibility', true);
|
||||
sendMessage('PHONE', 'setTime', time);
|
||||
sendMessage('PHONE', PhoneEvents.SET_VISIBILITY, true);
|
||||
sendMessage('PHONE', PhoneEvents.SET_TIME, time);
|
||||
SetNuiFocus(true, true);
|
||||
};
|
||||
|
||||
const hidePhone = async (): Promise<void> => {
|
||||
isPhoneOpen = false;
|
||||
sendMessage('PHONE', 'setVisibility', false);
|
||||
sendMessage('PHONE', PhoneEvents.SET_VISIBILITY, false);
|
||||
await phoneCloseAnim();
|
||||
SetNuiFocus(false, false);
|
||||
};
|
||||
@@ -119,15 +119,15 @@ onNet(PhoneEvents.PLAYER_IS_READY, () => {
|
||||
|
||||
AddEventHandler('onResourceStop', function (resource: string) {
|
||||
if (resource === GetCurrentResourceName()) {
|
||||
sendMessage('PHONE', 'setVisibility', false);
|
||||
sendMessage('PHONE', PhoneEvents.SET_VISIBILITY, false);
|
||||
SetNuiFocus(false, false);
|
||||
removePhoneProp(); //Deletes the phone incase it was attached.
|
||||
ClearPedTasks(PlayerPedId()); //Leave here until launch as it'll fix any stuck animations.
|
||||
}
|
||||
});
|
||||
|
||||
onNet('phone:sendCredentials', (number: string) => {
|
||||
sendMessage('SIMCARD', 'setNumber', number);
|
||||
onNet(PhoneEvents.SEND_CREDENTIALS, (number: string) => {
|
||||
sendMessage('SIMCARD', PhoneEvents.SET_NUMBER, number);
|
||||
});
|
||||
|
||||
RegisterNuiCallbackType(PhoneEvents.UI_IS_READY);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { IPhoto, PhotoEvents } from '../../typings/photo';
|
||||
import { Delay } from '../utils/fivem';
|
||||
import { sendMessage, sendCameraEvent } from '../utils/messages';
|
||||
import { PhoneEvents } from '../../typings/phone';
|
||||
const SCREENSHOT_BASIC_TOKEN = GetConvar('SCREENSHOT_BASIC_TOKEN', 'none');
|
||||
|
||||
const exp = (global as any).exports;
|
||||
@@ -9,12 +10,12 @@ let inCameraMode = false;
|
||||
|
||||
function closePhoneTemp() {
|
||||
SetNuiFocus(false, false);
|
||||
sendMessage('PHONE', 'setVisibility', false);
|
||||
sendMessage('PHONE', PhoneEvents.SET_VISIBILITY, false);
|
||||
}
|
||||
|
||||
function openPhoneTemp() {
|
||||
SetNuiFocus(true, true);
|
||||
sendMessage('PHONE', 'setVisibility', true);
|
||||
sendMessage('PHONE', PhoneEvents.SET_VISIBILITY, true);
|
||||
}
|
||||
|
||||
function CellFrontCamActivate(activate: boolean) {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { CallEvents } from '../../typings/call';
|
||||
import { getIdentifierByPhoneNumber, getPlayer, getSource } from './functions';
|
||||
import { getPlayerFromIdentifier } from './functions';
|
||||
import { ICall } from '../../typings/call';
|
||||
import { CallHistoryItem } from '../../typings/call';
|
||||
|
||||
import { pool } from './db';
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
@@ -9,25 +9,25 @@ import { mainLogger } from './sv_logger';
|
||||
|
||||
const callLogger = mainLogger.child({ module: 'calls' });
|
||||
|
||||
async function saveCall(call: ICall) {
|
||||
async function saveCall(call: CallHistoryItem) {
|
||||
const query =
|
||||
'INSERT INTO npwd_calls (identifier, transmitter, receiver, start) VALUES (?, ?, ?, ?)';
|
||||
await pool.query(query, [call.identifier, call.transmitter, call.receiver, call.start]);
|
||||
}
|
||||
|
||||
async function updateCall(call: ICall, isAccepted: boolean, end: number) {
|
||||
async function updateCall(call: CallHistoryItem, isAccepted: boolean, end: number) {
|
||||
const query = 'UPDATE npwd_calls SET is_accepted=?, end=? WHERE identifier = ?';
|
||||
await pool.query(query, [isAccepted, end, call.identifier]);
|
||||
}
|
||||
|
||||
async function fetchCalls(phoneNumber: string): Promise<ICall[]> {
|
||||
async function fetchCalls(phoneNumber: string): Promise<CallHistoryItem[]> {
|
||||
const query = 'SELECT * FROM npwd_calls WHERE receiver = ? OR transmitter = ? ORDER BY id DESC';
|
||||
const [result] = await pool.query(query, [phoneNumber, phoneNumber]);
|
||||
const calls = <ICall[]>result;
|
||||
const calls = <CallHistoryItem[]>result;
|
||||
return calls;
|
||||
}
|
||||
|
||||
let calls: Map<string, ICall> = new Map();
|
||||
let calls: Map<string, CallHistoryItem> = new Map();
|
||||
|
||||
onNet(CallEvents.INITIALIZE_CALL, async (phoneNumber: string) => {
|
||||
const _source = getSource();
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { pool } from './db';
|
||||
import { getIdentifier, getSource } from './functions';
|
||||
import { mainLogger } from './sv_logger';
|
||||
import { PhoneEvents } from '../../typings/phone';
|
||||
|
||||
interface Credentials {
|
||||
phone_number: string;
|
||||
@@ -19,7 +20,7 @@ onNet('phone:getCredentials', async () => {
|
||||
try {
|
||||
const identifier = getIdentifier(_source);
|
||||
const number = await getCredentials(identifier);
|
||||
emitNet('phone:sendCredentials', _source, number);
|
||||
emitNet(PhoneEvents.SEND_CREDENTIALS, _source, number);
|
||||
} catch (e) {
|
||||
mainLogger.error(`Failed to get a number, ${e.message}`, {
|
||||
source: _source,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { pool } from './db';
|
||||
import { getIdentifier, getSource } from './functions';
|
||||
import { IPhoto, PhotoEvents } from '../../typings/photo';
|
||||
import { GalleryPhoto, PhotoEvents } from '../../typings/photo';
|
||||
import { mainLogger } from './sv_logger';
|
||||
|
||||
const photoLogger = mainLogger.child({ module: 'photo' });
|
||||
@@ -11,13 +11,13 @@ async function uploadPhoto(identifier: string, image: string): Promise<IPhoto> {
|
||||
return { id: results.insertId, image };
|
||||
}
|
||||
|
||||
async function getPhotosByIdentifier(identifier: string): Promise<IPhoto[]> {
|
||||
async function getPhotosByIdentifier(identifier: string): Promise<GalleryPhoto[]> {
|
||||
const query = 'SELECT id, image FROM npwd_phone_gallery WHERE identifier = ? ORDER BY id DESC';
|
||||
const [results] = await pool.query(query, [identifier]);
|
||||
return <IPhoto[]>results;
|
||||
return <GalleryPhoto[]>results;
|
||||
}
|
||||
|
||||
async function deletePhoto(photo: IPhoto, identifier: string) {
|
||||
async function deletePhoto(photo: GalleryPhoto, identifier: string) {
|
||||
const query = 'DELETE FROM npwd_phone_gallery WHERE image = ? AND identifier = ?';
|
||||
await pool.query(query, [photo.image, identifier]);
|
||||
}
|
||||
@@ -48,7 +48,7 @@ onNet(PhotoEvents.FETCH_PHOTOS, async () => {
|
||||
}
|
||||
});
|
||||
|
||||
onNet(PhotoEvents.DELETE_PHOTO, async (photo: IPhoto) => {
|
||||
onNet(PhotoEvents.DELETE_PHOTO, async (photo: GalleryPhoto) => {
|
||||
const _source = getSource();
|
||||
try {
|
||||
const identifier = getIdentifier(_source);
|
||||
|
||||
Reference in new issue
Block a user