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

@@ -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(() => {