Feat/inject debug - Use new abstraction to clean up debug data (#70)

* feat(phone/debug): Inject debug data for development

* refactor(phone/debug): Refactored mock data to InjectDebugEvents

* fix(phone/debug) removed useless debug injections
This commit is contained in:
Taso authored and GitHub committed 2021-02-06 16:00:09 -05:00
1 parent 686b86acf9
commit 447c51a07e
11 files changed
+243 -256

No files matched your search

+12 -256
View File
@@ -31,262 +31,15 @@ import { useRecoilState } from 'recoil';
import { useCallService } from './modal/hooks/useCallService';
import { useModal } from './modal/hooks/useModal';
import { useDialService } from './apps/dialer/hooks/useDialService';
import InjectDebugData from './os/debug/InjectDebugData';
// Inject mock data when in development env.
if (process.env.NODE_ENV === 'development') {
setTimeout(() => {
window.dispatchEvent(
new MessageEvent('message', {
data: {
app: 'CAMERA',
method: 'setPhotos',
data: [
{
id: 1,
image: 'https://i.imgur.com/OO8wx6Z.jpg',
},
{
id: 1,
image: 'https://i.imgur.com/pqGBiST.jpg',
},
],
},
})
);
}, 1000);
setTimeout(() => {
window.dispatchEvent(
new MessageEvent('message', {
data: {
app: 'DAILER',
method: 'setHistory',
data: [
{
id: 1,
transmitter: '636-6496',
start: 1612301545782,
},
{
id: 2,
transmitter: '777-7777',
start: 1612301545782,
},
],
},
})
);
}, 1000);
setTimeout(() => {
window.dispatchEvent(
new MessageEvent('message', {
data: {
app: 'CALL',
method: 'setCaller',
data: {
accepted: true,
isTransmitter: true,
transmitter: 'Chip',
receiver: 'Taso',
phone_number: '860-4504',
},
},
})
);
}, 1000);
setTimeout(() => {
window.dispatchEvent(
new MessageEvent('message', {
data: {
app: 'BANK',
method: 'setCredentials',
data: {
name: 'Firstname Lastname',
balance: 2000,
},
},
})
);
}, 1000);
setTimeout(() => {
window.dispatchEvent(
new MessageEvent('message', {
data: {
app: 'CONTACTS',
method: 'setContacts',
data: [
{
id: 1,
display: 'Ruqen',
number: '43534444',
},
{
id: 1,
display: 'Taso',
number: '456466',
},
],
},
})
);
}, 1000);
setTimeout(() => {
window.dispatchEvent(
new MessageEvent('message', {
data: {
app: 'SIMCARD',
method: 'setNumber',
data: '111-1134',
},
})
);
}, 1000);
setTimeout(() => {
window.dispatchEvent(
new MessageEvent('message', {
data: {
app: 'PHONE',
method: 'setVisibility',
data: true,
},
})
);
}, 1000);
setTimeout(() => {
window.dispatchEvent(
new MessageEvent('message', {
data: {
app: 'NOTES',
method: 'setNotes',
data: [
{
id: 1,
title: 'First note',
content: 'Hello, this is my shitty note',
},
{
id: 2,
title: 'Second note',
content: 'Hello, this is another shitty note',
},
],
},
})
);
}, 1000);
setTimeout(() => {
window.dispatchEvent(
new MessageEvent('message', {
data: {
app: 'BANK',
method: 'setNotification',
data: {
id: 1,
message: 'ahhaha',
},
},
})
);
}, 1000);
setTimeout(() => {
new MessageEvent('messsage', {
data: {
app: 'TWITTER',
method: 'setNotification',
data: {
id: 1,
message: 'ahhaha',
},
},
});
}, 1000);
setTimeout(() => {
window.dispatchEvent(
new MessageEvent('message', {
data: {
app: 'BANK',
method: 'setTransaction',
data: [
{
id: 1,
amount: 200,
type: 'Deposit',
source: 'chip',
},
{
id: 2,
amount: 200,
type: 'Withdraw',
source: 'chip',
},
{
id: 3,
amount: 200,
type: 'Withdraw',
source: 'chip',
},
{
id: 4,
amount: 50,
type: 'Deposit',
source: 'chip',
},
{
id: 4,
amount: 50,
type: 'Deposit',
source: 'chip',
},
{
id: 4,
amount: 50,
type: 'Deposit',
source: 'chip',
},
],
},
})
);
}, 1000);
setTimeout(() => {
window.dispatchEvent(
new MessageEvent('message', {
data: {
app: 'SELLOUT',
method: 'setListings',
data: [
{
id: 1,
name: 'Some guy',
number: '123-4567',
title: 'Car',
description: 'Selling this cool car',
url: 'https://i.imgur.com/ROmGTwi.jpeg',
},
{
id: 2,
name: 'Some other dude',
number: '666-6666',
title: 'Material',
description: 'Selling my wife',
url: '',
},
],
},
})
);
}, 1000);
}
InjectDebugData([
{
app: 'PHONE',
method: 'setVisibility',
data: true,
},
]);
function Phone() {
useNuiService();
@@ -327,7 +80,10 @@ function Phone() {
<div>
<div
className='Phone'
style={{ transformOrigin: 'right bottom', transform: `scale(${settings.zoom}` }}
style={{
transformOrigin: 'right bottom',
transform: `scale(${settings.zoom}`,
}}
>
<div
className='PhoneFrame'
@@ -15,6 +15,60 @@ import { BankHome } from './home/BankHome';
import { BankAccount } from './account/BankAccount';
import { TransactionList } from './transactions/TransactionList';
import { BankAlert } from './alert/BankAlert';
import InjectDebugData from '../../../os/debug/InjectDebugData';
InjectDebugData([
{
app: 'BANK',
method: 'setCredentials',
data: {
name: 'Firstname Lastname',
balance: 2000,
},
},
{
app: 'BANK',
method: 'setTransaction',
data: [
{
id: 1,
amount: 200,
type: 'Deposit',
source: 'chip',
},
{
id: 2,
amount: 200,
type: 'Withdraw',
source: 'chip',
},
{
id: 3,
amount: 200,
type: 'Withdraw',
source: 'chip',
},
{
id: 4,
amount: 50,
type: 'Deposit',
source: 'chip',
},
{
id: 4,
amount: 50,
type: 'Deposit',
source: 'chip',
},
{
id: 4,
amount: 50,
type: 'Deposit',
source: 'chip',
},
],
},
]);
const useStyles = makeStyles((theme) => ({
root: {
@@ -4,6 +4,24 @@ import { AppContent } from '../../../ui/components/AppContent';
import { usePhotoModal } from '../hooks/usePhotoModal';
import { GalleryGrid } from './grid/GalleryGrid';
import { GalleryModal } from './modal/GalleryModal';
import InjectDebugData from '../../../os/debug/InjectDebugData';
InjectDebugData([
{
app: 'CAMERA',
method: 'setPhotos',
data: [
{
id: 1,
image: 'https://i.imgur.com/OO8wx6Z.jpg',
},
{
id: 1,
image: 'https://i.imgur.com/pqGBiST.jpg',
},
],
},
]);
const CameraApp = () => {
const { modal } = usePhotoModal();
@@ -14,6 +14,26 @@ import { useContactDetail } from '../hooks/useContactDetail';
import { ContactAlert } from './alert/ContactAlert';
import useStyles from './styles.contacts';
import InjectDebugData from '../../../os/debug/InjectDebugData';
InjectDebugData([
{
app: 'CONTACTS',
method: 'setContacts',
data: [
{
id: 1,
display: 'Ruqen',
number: '43534444',
},
{
id: 1,
display: 'Taso',
number: '456466',
},
],
},
]);
export const ContactsApp = () => {
const classes = useStyles();
@@ -8,6 +8,26 @@ import { Switch, Route } from 'react-router-dom';
import DialPage from './views/DialPage';
import DialerNavBar from './DialerNavBar';
import { useDialHistory } from '../hooks/useDialHistory';
import InjectDebugData from '../../../os/debug/InjectDebugData';
InjectDebugData([
{
app: 'DAILER',
method: 'setHistory',
data: [
{
id: 1,
transmitter: '636-6496',
start: 1612301545782,
},
{
id: 2,
transmitter: '777-7777',
start: 1612301545782,
},
],
},
]);
export const DialerApp = () => {
const history = useDialHistory();
+20
View File
@@ -14,6 +14,26 @@ import { useNoteModal } from './hooks/useNoteModal';
import { useNoteDetail } from './hooks/useNoteDetail';
import useStyles from './notes.styles';
import InjectDebugData from '../../os/debug/InjectDebugData';
InjectDebugData([
{
app: 'NOTES',
method: 'setNotes',
data: [
{
id: 1,
title: 'First note',
content: 'Hello, this is my shitty note',
},
{
id: 2,
title: 'Second note',
content: 'Hello, this is another shitty note',
},
],
},
]);
export const NotesApp = () => {
const { setNoteModal } = useNoteModal();
@@ -8,6 +8,32 @@ import { Switch, Route } from 'react-router-dom';
import './Sellout.css';
import { ListingFormContainer } from './form/ListingFormContainer';
import InjectDebugData from '../../../os/debug/InjectDebugData';
InjectDebugData([
{
app: 'SELLOUT',
method: 'setListings',
data: [
{
id: 1,
name: 'Some guy',
number: '123-4567',
title: 'Car',
description: 'Selling this cool car',
url: 'https://i.imgur.com/ROmGTwi.jpeg',
},
{
id: 2,
name: 'Some other dude',
number: '666-6666',
title: 'Material',
description: 'Selling my wife',
url: '',
},
],
},
]);
export const SelloutApp = () => {
return (
@@ -19,6 +19,7 @@ import './twitter.css';
import 'emoji-mart/css/emoji-mart.css';
import { useProfile } from '../hooks/useProfile';
import ProfilePrompt from './profile/ProfilePrompt';
import InjectDebugData from '../../../os/debug/InjectDebugData';
const useStyles = makeStyles(() => ({
backgroundModal: {
+15
View File
@@ -10,6 +10,21 @@ import useStyles from './modal.styles';
import { useModal } from '../hooks/useModal';
import Nui from '../../os/nui-events/utils/Nui';
import CallTimer from './CallTimer';
import InjectDebugData from '../../os/debug/InjectDebugData';
InjectDebugData([
{
app: 'CALL',
method: 'setCaller',
data: {
accepted: true,
isTransmitter: true,
transmitter: 'Chip',
receiver: 'Taso',
phone_number: '860-4504',
},
},
]);
export const CallModal = () => {
const { call } = useCall();
+48
View File
@@ -0,0 +1,48 @@
interface DebugEvent {
app: string;
method: string;
data: any;
}
// TODO: This should be unit tested
/**
* Will mock data as if it were coming from an NUI message event
* @param events {DebugEvent[]} An array of debug events
* @example
* InjectDebugData([
* {
* app: 'CAMERA',
* method: 'setPhotos',
* data: [
* {
* id: 1,
* image: 'https://i.imgur.com/OO8wx6Z.jpg',
* },
* {
* id: 2,
* image: 'https://i.imgur.com/OO8wx6Z.jpg',
* }
* ]
* }
* ])
**/
const InjectDebugData = (events: DebugEvent[]) => {
if (process.env.NODE_ENV === 'development') {
for (const event of events) {
setTimeout(() => {
window.dispatchEvent(
new MessageEvent('message', {
data: {
app: event.app,
method: event.method,
data: event.data,
},
})
);
}, 1000);
}
}
};
export default InjectDebugData;
@@ -2,6 +2,15 @@ import { useNuiEvent } from '../../nui-events/hooks/useNuiEvent';
import { useSetRecoilState } from 'recoil';
import { simcardState } from './state';
import { useSimcard } from './useSimcard';
import InjectDebugData from '../../debug/InjectDebugData';
InjectDebugData([
{
app: 'SIMCARD',
method: 'setNumber',
data: '111-1134',
},
]);
export const useSimcardService = () => {
const setNumber = useSetRecoilState(simcardState.number);