mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-04 22:16:40 +00:00
Fix useEffect infinite re-render (#245)
This commit is contained in:
1 parent
b257f5bc73
commit
aa185224e7
7 files changed
+11
-38
No files matched your search
@@ -4,7 +4,6 @@ import './i18n';
|
|||||||
import { Route } from 'react-router-dom';
|
import { Route } from 'react-router-dom';
|
||||||
import { CallModal } from './os/call/components/CallModal';
|
import { CallModal } from './os/call/components/CallModal';
|
||||||
import { HomeApp } from './apps/home/components/Home';
|
import { HomeApp } from './apps/home/components/Home';
|
||||||
import { Box, Paper, Typography } from '@material-ui/core';
|
|
||||||
import { NotificationBar } from './os/notifications/components/NotificationBar';
|
import { NotificationBar } from './os/notifications/components/NotificationBar';
|
||||||
import { Navigation } from './os/navigation-bar/components/Navigation';
|
import { Navigation } from './os/navigation-bar/components/Navigation';
|
||||||
import { useSimcardService } from './os/simcard/hooks/useSimcardService';
|
import { useSimcardService } from './os/simcard/hooks/useSimcardService';
|
||||||
@@ -27,11 +26,9 @@ import { PhoneSnackbar } from './ui/components/PhoneSnackbar';
|
|||||||
import { NotificationAlert } from './os/notifications/components/NotificationAlert';
|
import { NotificationAlert } from './os/notifications/components/NotificationAlert';
|
||||||
import { useCallModal } from './os/call/hooks/useCallModal';
|
import { useCallModal } from './os/call/hooks/useCallModal';
|
||||||
import WindowSnackbar from './ui/components/WindowSnackbar';
|
import WindowSnackbar from './ui/components/WindowSnackbar';
|
||||||
import { usePhone } from './os/phone/hooks/usePhone';
|
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { useSnackbar } from './ui/hooks/useSnackbar';
|
import { useSnackbar } from './ui/hooks/useSnackbar';
|
||||||
import { PhoneEvents } from '../../typings/phone';
|
import { PhoneEvents } from '../../typings/phone';
|
||||||
import { isDefaultWallpaper } from './apps/settings/utils/isDefaultWallpaper';
|
|
||||||
import { useKeyboardService } from './os/keyboard/hooks/useKeyboardService';
|
import { useKeyboardService } from './os/keyboard/hooks/useKeyboardService';
|
||||||
import PhoneWrapper from './PhoneWrapper';
|
import PhoneWrapper from './PhoneWrapper';
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import React, { useCallback, useState, useEffect } from 'react';
|
import React, { useCallback, useState } from 'react';
|
||||||
import { makeStyles } from '@material-ui/core/styles';
|
import { makeStyles } from '@material-ui/core/styles';
|
||||||
import { v4 as uuidv4 } from 'uuid';
|
import { v4 as uuidv4 } from 'uuid';
|
||||||
import { useNuiRequest } from 'fivem-nui-react-lib';
|
import { useNuiRequest } from 'fivem-nui-react-lib';
|
||||||
@@ -76,23 +76,10 @@ export const AddTweetModal = () => {
|
|||||||
setModalVisible(false);
|
setModalVisible(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
// when the user presses escape we should close the modal
|
|
||||||
const _handleEscape = (e) => {
|
|
||||||
const isEscapeKey = e.key === 'Escape' || e.key === 'Esc';
|
|
||||||
if (isEscapeKey) {
|
|
||||||
e.preventDefault();
|
|
||||||
_handleClose();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleimageChange = useCallback((link) => setLink(link), []);
|
const handleimageChange = useCallback((link) => setLink(link), []);
|
||||||
|
|
||||||
const handleMessageChange = useCallback((message) => setMessage(message), [setMessage]);
|
const handleMessageChange = useCallback((message) => setMessage(message), [setMessage]);
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
window.addEventListener('keydown', _handleEscape, true);
|
|
||||||
return () => window.removeEventListener('keydown', _handleEscape);
|
|
||||||
});
|
|
||||||
if (!ResourceConfig) return null;
|
if (!ResourceConfig) return null;
|
||||||
|
|
||||||
const isValidMessage = (message) => {
|
const isValidMessage = (message) => {
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ export function TweetList({ tweets }) {
|
|||||||
setMimimumLoadPassed(true);
|
setMimimumLoadPassed(true);
|
||||||
}, MINIMUM_LOAD_TIME);
|
}, MINIMUM_LOAD_TIME);
|
||||||
return () => window.clearTimeout(timeout);
|
return () => window.clearTimeout(timeout);
|
||||||
});
|
}, []);
|
||||||
|
|
||||||
// we add a minimum (but short) load time here so that
|
// we add a minimum (but short) load time here so that
|
||||||
// there isn't a quick flash of loading and immediately
|
// there isn't a quick flash of loading and immediately
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ const useStyles = makeStyles({
|
|||||||
});
|
});
|
||||||
|
|
||||||
export const TweetMessage = ({ modalVisible, message, handleChange }) => {
|
export const TweetMessage = ({ modalVisible, message, handleChange }) => {
|
||||||
const textFieldRef = useRef(null);
|
|
||||||
const textFieldInputRef = useRef(null);
|
const textFieldInputRef = useRef(null);
|
||||||
const classes = useStyles();
|
const classes = useStyles();
|
||||||
const { ResourceConfig } = usePhone();
|
const { ResourceConfig } = usePhone();
|
||||||
@@ -40,7 +39,7 @@ export const TweetMessage = ({ modalVisible, message, handleChange }) => {
|
|||||||
// so that we always have the latest line and error message
|
// so that we always have the latest line and error message
|
||||||
// in view
|
// in view
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
textFieldRef.current.scrollTop = textFieldRef.current.scrollHeight;
|
textFieldInputRef.current.scrollTop = textFieldInputRef.current.scrollHeight;
|
||||||
handleChange(e.target.value);
|
handleChange(e.target.value);
|
||||||
},
|
},
|
||||||
[handleChange],
|
[handleChange],
|
||||||
@@ -77,7 +76,7 @@ export const TweetMessage = ({ modalVisible, message, handleChange }) => {
|
|||||||
inputRef={textFieldInputRef}
|
inputRef={textFieldInputRef}
|
||||||
error={errorMessage !== null}
|
error={errorMessage !== null}
|
||||||
helperText={errorMessage || null}
|
helperText={errorMessage || null}
|
||||||
ref={textFieldRef}
|
// ref={textFieldRef}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import React, { useEffect } from 'react';
|
import React from 'react';
|
||||||
import CloseIcon from '@material-ui/icons/Close';
|
import CloseIcon from '@material-ui/icons/Close';
|
||||||
import { makeStyles } from '@material-ui/core/styles';
|
import { makeStyles } from '@material-ui/core/styles';
|
||||||
import { Button, Paper } from '@material-ui/core';
|
import { Button, Paper } from '@material-ui/core';
|
||||||
@@ -36,20 +36,6 @@ const useStyles = makeStyles({
|
|||||||
export const Modal = ({ children, visible, handleClose }) => {
|
export const Modal = ({ children, visible, handleClose }) => {
|
||||||
const classes = useStyles();
|
const classes = useStyles();
|
||||||
|
|
||||||
// when the user presses escape we should close the modal
|
|
||||||
const _handleEscape = (e) => {
|
|
||||||
e.stopPropagation();
|
|
||||||
const isEscapeKey = e.key === 'Escape' || e.key === 'Esc';
|
|
||||||
if (isEscapeKey) {
|
|
||||||
e.preventDefault();
|
|
||||||
handleClose();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
useEffect(() => {
|
|
||||||
window.addEventListener('keydown', _handleEscape, true);
|
|
||||||
return () => window.removeEventListener('keydown', _handleEscape);
|
|
||||||
});
|
|
||||||
|
|
||||||
const showHideClassName = visible ? classes.displayBlock : classes.displayNone;
|
const showHideClassName = visible ? classes.displayBlock : classes.displayNone;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ export class _ContactsDB {
|
|||||||
limit = FetchDefaultLimits.CONTACTS_FETCH_LIMIT,
|
limit = FetchDefaultLimits.CONTACTS_FETCH_LIMIT,
|
||||||
): Promise<Contact[]> {
|
): Promise<Contact[]> {
|
||||||
const query =
|
const query =
|
||||||
'SELECT * FROM npwd_phone_contacts WHERE identifier = ? ORDER BY display ASC LIMIT ?';
|
'SELECT * FROM npwd_phone_contacts WHERE identifier = ? ORDER BY display ASC';
|
||||||
const [results] = await pool.query(query, [identifier, limit]);
|
const [results] = await pool.query(query, [identifier, limit]);
|
||||||
return <Contact[]>results;
|
return <Contact[]>results;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,7 +25,11 @@ if (!config.general.enableMultiChar) {
|
|||||||
on('playerDropped', () => {
|
on('playerDropped', () => {
|
||||||
const src = getSource();
|
const src = getSource();
|
||||||
// Get identifier for player to remove
|
// Get identifier for player to remove
|
||||||
PlayerService.handleUnloadPlayerEvent(src, true);
|
try {
|
||||||
|
PlayerService.handleUnloadPlayerEvent(src, true);
|
||||||
|
} catch (e) {
|
||||||
|
playerLogger.debug(`${src} failed to unload, likely was never loaded in the first place.`)
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Can use this to debug the player table if needed. Disabled by default
|
// Can use this to debug the player table if needed. Disabled by default
|
||||||
|
|||||||
Reference in new issue
Block a user