refactor(events): Events are now tied to a common enum typings (#167)

* chore(scripts/twitter): Refactored twitter to use event enums

* chore(scripts/marketplace): Refactored marketplace to use event enums

* chore(scripts/messages): Refactored messages to use event enums

* chore(scripts/contacts): Refactored contacts to use event enums

* chore(scripts/calls): Refactored calls to use event enums

* chore(scripts/notes): Refactored notes to use event enums

* chore(scripts/photos): Refactored photos to use event enums

* chore(scripts/bank): Refactored bank to use event enums

* chore(scripts/phone): Refactored phone to use event enums

* chore(events): Removed old events object

* refactor(phone/nui-events): Attached NUI events to respective enum

* tweak(event-enums): Added npwd prefix to all events

* tweak(phone/serve): Added craco to override CRA without eject

Also bumped react-scripts to 4.0.1, with seemingly no issues

* fix(typings/twitter): Fixed method enums for twitter
This commit is contained in:
Taso authored and GitHub committed 2021-03-22 13:37:07 -04:00
1 parent 53d5bb459d
commit 0f61088999
62 files changed
+4734 -3470

No files matched your search

@@ -5,6 +5,7 @@ import { Button, List, ListItem, TextField, makeStyles } from '@material-ui/core
import Nui from '../../../../os/nui-events/utils/Nui';
import { useBankModal } from '../../hooks/useBankModal';
import { BankEvents } from '../../../../../../typings/bank';
const useStyles = makeStyles((theme) => ({
input: {
@@ -43,7 +44,7 @@ export const TransferModal = () => {
const addTransfer = () => {
const transferAmount = parseInt(amount);
Nui.send('phone:addTransfer', {
Nui.send(BankEvents.ADD_TRANSFER, {
targetID,
transferAmount,
message,
@@ -8,6 +8,7 @@ import { useHistory } from 'react-router-dom';
import { useQueryParams } from '../../../../common/hooks/useQueryParams';
import { addQueryToLocation } from '../../../../common/utils/addQueryToLocation';
import { getLocationFromUrl } from '../../../../common/utils/getLocationFromUrl';
import { PhotoEvents } from '../../../../../../typings/photo';
export const GalleryGrid = () => {
const classes = useStyles();
@@ -19,7 +20,7 @@ export const GalleryGrid = () => {
const photos = usePhotos();
const handleCamera = () => {
Nui.send('phone:TakePhoto', {});
Nui.send(PhotoEvents.TAKE_PHOTO, {});
};
const handlePhotoOpen = (photo) => {
@@ -9,6 +9,7 @@ import { useHistory } from 'react-router-dom';
import { useQueryParams } from '../../../../common/hooks/useQueryParams';
import { ICameraPhoto } from '../../hooks/usePhotos';
import { ShareModal } from './ShareModal';
import { PhotoEvents } from '../../../../../../typings/photo';
export const GalleryModal = () => {
const classes = useStyles();
@@ -28,7 +29,7 @@ export const GalleryModal = () => {
};
const handleDeletePhoto = () => {
Nui.send('photo:deletePhoto', {
Nui.send(PhotoEvents.DELETE_PHOTO, {
image: meta.image,
});
history.push(referal);
@@ -10,6 +10,7 @@ import Nui from '../../../../os/nui-events/utils/Nui';
import { SearchContacts } from './SearchContacts';
import { useHistory } from 'react-router-dom';
import LogDebugEvent from '../../../../os/debug/LogDebugEvents';
import { CallEvents } from '../../../../../../typings/call';
export const ContactList = () => {
const { filteredContacts } = useFilteredContacts();
@@ -27,7 +28,7 @@ export const ContactList = () => {
level: 2,
data: true,
});
Nui.send('phone:beginCall', {
Nui.send(CallEvents.INITIALIZE_CALL, {
number,
});
};
@@ -8,6 +8,7 @@ import Nui from '../../../../os/nui-events/utils/Nui';
import ArrowBackIcon from '@material-ui/icons/ArrowBack';
import LogDebugEvent from '../../../../os/debug/LogDebugEvents';
import { useQueryParams } from '../../../../common/hooks/useQueryParams';
import { ContactEvents } from '../../../../../../typings/contact';
interface ContactInfoRouteParams {
mode: string;
@@ -79,7 +80,7 @@ const ContactsInfoPage = () => {
data: contact,
level: 2,
});
Nui.send('phone:addContacts', {
Nui.send(ContactEvents.ADD_CONTACT, {
display: name,
number,
avatar,
@@ -93,7 +94,7 @@ const ContactsInfoPage = () => {
data: contact,
level: 2,
});
Nui.send('phone:updateContact', {
Nui.send(ContactEvents.UPDATE_CONTACT, {
id: contact.id,
display: name,
number,
@@ -108,7 +109,7 @@ const ContactsInfoPage = () => {
data: contact,
level: 2,
});
Nui.send('phone:deleteContact', {
Nui.send(ContactEvents.DELETE_CONTACT, {
id: contact.id,
});
history.goBack();
@@ -6,6 +6,7 @@ import PersonAddIcon from '@material-ui/icons/PersonAdd';
import { DialInputCtx, IDialInputCtx } from '../context/InputContext';
import Nui from '../../../os/nui-events/utils/Nui';
import { useHistory } from 'react-router-dom';
import { CallEvents } from '../../../../../typings/call';
const useStyles = makeStyles((theme: Theme) => ({
root: {
@@ -33,7 +34,7 @@ export const DialerInput = () => {
const { inputVal, set } = useContext<IDialInputCtx>(DialInputCtx);
const handleCall = (number: string) => {
Nui.send('phone:beginCall', {
Nui.send(CallEvents.INITIALIZE_CALL, {
number,
});
};
@@ -8,7 +8,7 @@ import { ListItem } from '../../../../ui/components/ListItem';
import Nui from '../../../../os/nui-events/utils/Nui';
import { useSimcard } from '../../../../os/simcard/hooks/useSimcard';
import { useContacts } from '../../../contacts/hooks/useContacts';
import { ICall } from '../../../../../../typings/call';
import { CallEvents, ICall } from '../../../../../../typings/call';
import { useTranslation } from 'react-i18next';
import { Box, IconButton, ListItemIcon, ListItemText } from '@material-ui/core';
import { useHistory } from 'react-router-dom';
@@ -35,7 +35,7 @@ export const DialerHistory = ({ calls }) => {
const { t } = useTranslation();
const handleCall = (phoneNumber) => {
Nui.send('phone:beginCall', {
Nui.send(CallEvents.INITIALIZE_CALL, {
number: phoneNumber,
});
};
@@ -11,13 +11,14 @@ import InjectDebugData from '../../../os/debug/InjectDebugData';
import NewMessageGroupButton from './form/NewMessageGroupButton';
import Nui from '../../../os/nui-events/utils/Nui';
import { MessagesThemeProvider } from '../providers/MessagesThemeProvider';
import { MessageEvents } from '../../../../../typings/messages';
export const MessagesApp = () => {
const messages = useApp('MESSAGES');
const history = useHistory();
useEffect(() => {
Nui.send('phone:fetchMessageGroups');
Nui.send(MessageEvents.FETCH_MESSAGE_GROUPS);
}, []);
return (
@@ -4,6 +4,7 @@ import { Paper, Box, makeStyles, TextField, Button } from '@material-ui/core';
import SendIcon from '@material-ui/icons/Send';
import ImageIcon from '@material-ui/icons/Image';
import Nui from '../../../../os/nui-events/utils/Nui';
import { MessageEvents } from '../../../../../../typings/messages';
interface IProps {
onAddImageClick(): void;
@@ -25,7 +26,7 @@ const MessageInput = ({ messageGroupId, onAddImageClick }: IProps) => {
if (message.trim()) {
// don't allow the user to submit white space
Nui.send('phone:sendMessage', {
Nui.send(MessageEvents.SEND_MESSAGE, {
groupId: messageGroupId,
message,
});
@@ -7,6 +7,7 @@ import { useHistory } from 'react-router-dom';
import { Autocomplete } from '@material-ui/lab';
import { useContacts } from '../../../contacts/hooks/useContacts';
import { Contact } from '../../../../../../typings/contact';
import { MessageEvents } from '../../../../../../typings/messages';
const NewMessageGroupForm = ({ phoneNumber }: { phoneNumber?: string }) => {
const history = useHistory();
@@ -32,7 +33,7 @@ const NewMessageGroupForm = ({ phoneNumber }: { phoneNumber?: string }) => {
const labelValue = isGroupChat ? label.trim() : null;
if (phoneNumbers.length) {
Nui.send('phone:createMessageGroup', {
Nui.send(MessageEvents.CREATE_MESSAGE_GROUP, {
phoneNumbers,
label: labelValue,
});
@@ -1,6 +1,6 @@
import React, { useEffect, useState } from 'react';
import { Box, List } from '@material-ui/core';
import { MessageGroup } from '../../../../../../typings/messages';
import { MessageEvents, MessageGroup } from '../../../../../../typings/messages';
import Nui from '../../../../os/nui-events/utils/Nui';
import useMessages from '../../hooks/useMessages';
import MessageGroupItem from './MessageGroupItem';
@@ -10,6 +10,7 @@ import { useHistory, useLocation } from 'react-router-dom';
import { ContextMenu } from '../../../../ui/components/ContextMenu';
import { deleteQueryFromLocation } from '../../../../common/utils/deleteQueryFromLocation';
import { PictureResponsive } from '../../../../ui/components/PictureResponsive';
import { MessageEvents } from '../../../../../../typings/messages';
interface IProps {
isOpen: boolean;
@@ -34,7 +35,7 @@ export const MessageImageModal = ({ isOpen, messageGroupId, onClose, image }: IP
const sendImageMessage = useCallback(
(m) => {
Nui.send('phone:sendMessage', {
Nui.send(MessageEvents.SEND_MESSAGE, {
groupId: messageGroupId,
message: m,
});
@@ -23,6 +23,7 @@ import { useTranslation } from 'react-i18next';
import Modal from '../../../../ui/components/Modal';
import { useContacts } from '../../../contacts/hooks/useContacts';
import { useSimcard } from '../../../../os/simcard/hooks/useSimcard';
import { MessageEvents } from '../../../../../../typings/messages';
const LARGE_HEADER_CHARS = 30;
const MAX_HEADER_CHARS = 80;
@@ -92,7 +93,7 @@ export const MessageModal = () => {
// sends all unread messages
useEffect(() => {
if (activeMessageGroup?.groupId && activeMessageGroup.unreadCount > 0) {
Nui.send('phone:setReadMessages', {
Nui.send(MessageEvents.SET_MESSAGE_READ, {
groupId: activeMessageGroup.groupId,
});
}
+4 -3
View File
@@ -16,6 +16,7 @@ import Nui from '../../../os/nui-events/utils/Nui';
import { useTranslation } from 'react-i18next';
import { useHistory } from 'react-router-dom';
import { StatusButton } from '../../../ui/components/StatusButton';
import { NotesEvents } from '../../../../../typings/notes';
export const NoteModal = () => {
const classes = useStyles();
@@ -31,14 +32,14 @@ export const NoteModal = () => {
};
const handleNoteSave = () => {
Nui.send('phone:addNote', detail);
Nui.send(NotesEvents.ADD_NOTE, detail);
setDetail(null);
onClose();
};
const handleDeleteNote = () => {
const id = detail.id;
Nui.send('phone:deleteNote', {
Nui.send(NotesEvents.DELETE_NOTE, {
id,
});
setDetail(null);
@@ -46,7 +47,7 @@ export const NoteModal = () => {
};
const handleUpdateNote = () => {
Nui.send('phone:updateNote', detail);
Nui.send(NotesEvents.UPDATE_NOTE, detail);
setDetail(null);
onClose();
};
@@ -1,7 +1,7 @@
import { Box, Tooltip, Button } from '@material-ui/core';
import { makeStyles, Theme } from '@material-ui/core/styles';
import React from 'react';
import { MarketplaceListing } from '../../../../../../typings/marketplace';
import { MarketplaceEvents, MarketplaceListing } from '../../../../../../typings/marketplace';
import { useSimcard } from '../../../../os/simcard/hooks/useSimcard';
import DeleteIcon from '@material-ui/icons/Delete';
import ReportIcon from '@material-ui/icons/Report';
@@ -10,6 +10,7 @@ import PhoneIcon from '@material-ui/icons/Phone';
import Nui from '../../../../os/nui-events/utils/Nui';
import { useTranslation } from 'react-i18next';
import { useHistory } from 'react-router';
import { CallEvents } from '../../../../../../typings/call';
const useStyles = makeStyles((theme: Theme) => ({
icon: {
@@ -24,17 +25,17 @@ export const ListingActions = ({ listing }: { listing: MarketplaceListing }) =>
const history = useHistory();
const handleDeleteListing = () => {
Nui.send('phone:marketplaceDeleteListing', {
Nui.send(MarketplaceEvents.DELETE_LISTING, {
id: listing.id,
});
};
const handleReportListing = () => {
Nui.send('phone:reportListing', listing);
Nui.send(MarketplaceEvents.REPORT_LISTING, listing);
};
const handleCall = () => {
Nui.send('phone:beginCall', {
Nui.send(CallEvents.INITIALIZE_CALL, {
number: listing.number,
});
};
@@ -1,6 +1,7 @@
import React, { useState } from 'react';
import { makeStyles, Button, TextField } from '@material-ui/core';
import Nui from '../../../../os/nui-events/utils/Nui';
import { MarketplaceEvents } from '../../../../../../typings/marketplace';
const useStyles = makeStyles((theme) => ({
root: {
@@ -34,7 +35,7 @@ export const ListingForm = () => {
const [description, setDescription] = useState('');
const addListing = () => {
Nui.send('phone:addListing', {
Nui.send(MarketplaceEvents.ADD_LISTING, {
title,
url,
description,
@@ -15,7 +15,7 @@ import ControlButtons from './buttons/ControlButtons';
import IconButtons from './buttons/IconButtons';
import { usePhone } from '../../../os/phone/hooks/usePhone';
import { getNewLineCount } from '../utils/message';
import { NewTweet } from '../../../../../typings/twitter';
import { NewTweet, TwitterEvents } from '../../../../../typings/twitter';
const useStyles = makeStyles((theme) => ({
root: {
@@ -110,7 +110,7 @@ export const AddTweetModal = () => {
images:
images && images.length > 0 ? images.map((image) => image.link).join(IMAGE_DELIMITER) : '',
};
Nui.send('phone:createTweet', data);
Nui.send(TwitterEvents.CREATE_TWEET, data);
_handleClose();
};
@@ -20,6 +20,7 @@ import { useProfile } from '../hooks/useProfile';
import ProfilePrompt from './profile/ProfilePrompt';
import InjectDebugData from '../../../os/debug/InjectDebugData';
import { TwitterThemeProvider } from '../providers/TwitterThemeProvider';
import { TwitterEvents } from '../../../../../typings/twitter';
const useStyles = makeStyles(() => ({
backgroundModal: {
@@ -7,6 +7,7 @@ import TweetList from './tweet/TweetList';
import Nui from '../../../os/nui-events/utils/Nui';
import SearchButton from './buttons/SearchButton';
import { useFilteredTweets } from '../hooks/useFilteredTweets';
import { TwitterEvents } from '../../../../../typings/twitter';
const useStyles = makeStyles({
root: {
@@ -32,7 +33,7 @@ function TwitterSearch() {
const cleanedSearchValue = searchValue.trim();
if (!cleanedSearchValue) return;
Nui.send('phone:fetchTweetsFiltered', cleanedSearchValue);
Nui.send(TwitterEvents.FETCH_TWEETS_FILTERED, cleanedSearchValue);
};
const filteredTweets = tweets || [];
@@ -4,6 +4,7 @@ import FavoriteBorderIcon from '@material-ui/icons/FavoriteBorder';
import FavoriteIcon from '@material-ui/icons/Favorite';
import Nui from '../../../../os/nui-events/utils/Nui';
import { TwitterEvents } from '../../../../../../typings/twitter';
const LOADING_TIME = 1250;
@@ -12,7 +13,7 @@ function LikeButton({ tweetId, isLiked }) {
const [loading, setLoading] = useState(false);
const handleClick = () => {
Nui.send('phone:toggleLike', tweetId);
Nui.send(TwitterEvents.TOGGLE_LIKE, tweetId);
setLoading(true);
window.setTimeout(() => {
setLiked(!liked);
@@ -4,6 +4,7 @@ import { Button, CircularProgress, MenuItem } from '@material-ui/core';
import DoneIcon from '@material-ui/icons/Done';
import Nui from '../../../../os/nui-events/utils/Nui';
import { TwitterEvents } from '../../../../../../typings/twitter';
const LOADING_TIME = 1250;
@@ -12,7 +13,7 @@ function ReportButton({ handleClose, tweetId, isReported }) {
const [loading, setLoading] = useState(false);
const handleClick = () => {
Nui.send('phone:reportTweet', tweetId);
Nui.send(TwitterEvents.REPORT, tweetId);
setLoading(true);
window.setTimeout(() => {
setLoading(false);
@@ -3,6 +3,7 @@ import { CircularProgress, makeStyles, Button } from '@material-ui/core';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faRetweet } from '@fortawesome/free-solid-svg-icons';
import Nui from '../../../../os/nui-events/utils/Nui';
import { TwitterEvents } from '../../../../../../typings/twitter';
interface IProps {
tweetId: number;
@@ -33,7 +34,7 @@ export const RetweetButton = ({ tweetId, isRetweet, retweetId }: IProps) => {
// if someone is retweeting something that is itself a retweet
// then we want to retweet the original post (if we haven't already)
const idToRetweet = isRetweet ? retweetId : tweetId;
Nui.send('phone:retweet', idToRetweet);
Nui.send(TwitterEvents.RETWEET, idToRetweet);
setLoading(true);
window.setTimeout(() => {
setRetweeted(true);
@@ -8,6 +8,7 @@ import Avatar from '../Avatar';
import ProfileField from './ProfileField';
import ProfileUpdateButton from '../buttons/ProfileUpdateButton';
import { usePhone } from '../../../../os/phone/hooks/usePhone';
import { TwitterEvents } from '../../../../../../typings/twitter';
const useStyles = makeStyles((theme) => ({
root: {
@@ -46,7 +47,7 @@ export function Profile() {
location,
job,
};
Nui.send('phone:updateTwitterProfile', data);
Nui.send(TwitterEvents.UPDATE_PROFILE, data);
};
// fetching the config is an asynchronous call so defend against it
@@ -10,6 +10,7 @@ import ProfileUpdateButton from '../buttons/ProfileUpdateButton';
import { useRecoilValue } from 'recoil';
import { twitterState } from '../../hooks/state';
import { usePhone } from '../../../../os/phone/hooks/usePhone';
import { TwitterEvents } from '../../../../../../typings/twitter';
const useStyles = makeStyles((theme) => ({
root: {
@@ -33,8 +34,8 @@ export function ProfilePrompt() {
const showDefaultProfileNames = !config.twitter.allowEdtiableProfileName && !profile;
const eventName = showDefaultProfileNames
? 'phone:createTwitterProfile'
: 'phone:updateTwitterProfile';
? TwitterEvents.CREATE_PROFILE
: TwitterEvents.UPDATE_PROFILE;
const handleUpdate = () => {
Nui.send(eventName, {
@@ -5,6 +5,7 @@ import MoreIcon from '@material-ui/icons/MoreVert';
import { usePhone } from '../../../../os/phone/hooks/usePhone';
import Nui from '../../../../os/nui-events/utils/Nui';
import ReportButton from '../buttons/ReportButton';
import { TwitterEvents } from '../../../../../../typings/twitter';
export const ShowMore = ({ id, isReported, isMine }) => {
const [anchorEl, setAnchorEl] = useState<Element | null>(null);
@@ -23,7 +24,7 @@ export const ShowMore = ({ id, isReported, isMine }) => {
};
const handleDeleteTweet = () => {
Nui.send('phone:deleteTweet', id);
Nui.send(TwitterEvents.DELETE_TWEET, id);
handleClose();
};
@@ -4,13 +4,14 @@ import Nui from '../../../../os/nui-events/utils/Nui';
import { useTweets } from '../../hooks/useTweets';
import { useTwitterNotifications } from '../../hooks/useTwitterNotifications';
import TweetList from './TweetList';
import { TwitterEvents } from '../../../../../../typings/twitter';
export function TweetListContainer() {
const { tweets } = useTweets();
const { setUnreadCount } = useTwitterNotifications();
useEffect(() => {
Nui.send('phone:fetchTweets', {});
Nui.send(TwitterEvents.FETCH_TWEETS, {});
}, []);
useEffect(() => {