diff --git a/phone/src/Phone.tsx b/phone/src/Phone.tsx
index e2a7d94..54d21a1 100644
--- a/phone/src/Phone.tsx
+++ b/phone/src/Phone.tsx
@@ -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() {
({
root: {
diff --git a/phone/src/apps/camera/components/CameraApp.tsx b/phone/src/apps/camera/components/CameraApp.tsx
index 1e7d6f9..8f3714d 100644
--- a/phone/src/apps/camera/components/CameraApp.tsx
+++ b/phone/src/apps/camera/components/CameraApp.tsx
@@ -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();
diff --git a/phone/src/apps/contacts/components/ContactsApp.tsx b/phone/src/apps/contacts/components/ContactsApp.tsx
index c9663f2..354b144 100644
--- a/phone/src/apps/contacts/components/ContactsApp.tsx
+++ b/phone/src/apps/contacts/components/ContactsApp.tsx
@@ -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();
diff --git a/phone/src/apps/dialer/components/DialerApp.tsx b/phone/src/apps/dialer/components/DialerApp.tsx
index e45c72e..fe2c3c8 100644
--- a/phone/src/apps/dialer/components/DialerApp.tsx
+++ b/phone/src/apps/dialer/components/DialerApp.tsx
@@ -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();
diff --git a/phone/src/apps/notes/NotesApp.tsx b/phone/src/apps/notes/NotesApp.tsx
index d9471eb..7186f0c 100644
--- a/phone/src/apps/notes/NotesApp.tsx
+++ b/phone/src/apps/notes/NotesApp.tsx
@@ -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();
diff --git a/phone/src/apps/sellout/components/SelloutApp.tsx b/phone/src/apps/sellout/components/SelloutApp.tsx
index 544b00a..45ec8d5 100644
--- a/phone/src/apps/sellout/components/SelloutApp.tsx
+++ b/phone/src/apps/sellout/components/SelloutApp.tsx
@@ -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 (
diff --git a/phone/src/apps/twitter/components/TwitterApp.tsx b/phone/src/apps/twitter/components/TwitterApp.tsx
index f8425cc..01abd57 100644
--- a/phone/src/apps/twitter/components/TwitterApp.tsx
+++ b/phone/src/apps/twitter/components/TwitterApp.tsx
@@ -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: {
diff --git a/phone/src/modal/components/CallModal.tsx b/phone/src/modal/components/CallModal.tsx
index a1af711..ff33f4e 100644
--- a/phone/src/modal/components/CallModal.tsx
+++ b/phone/src/modal/components/CallModal.tsx
@@ -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();
diff --git a/phone/src/os/debug/InjectDebugData.ts b/phone/src/os/debug/InjectDebugData.ts
new file mode 100644
index 0000000..d2a342f
--- /dev/null
+++ b/phone/src/os/debug/InjectDebugData.ts
@@ -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;
diff --git a/phone/src/os/simcard/hooks/useSimcardService.ts b/phone/src/os/simcard/hooks/useSimcardService.ts
index 633b5fd..32caba9 100644
--- a/phone/src/os/simcard/hooks/useSimcardService.ts
+++ b/phone/src/os/simcard/hooks/useSimcardService.ts
@@ -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);