mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-05 06:28:51 +00:00
Merge branch 'fix/warnings-and-call-timer' of https://github.com/project-error/new-phone-who-dis into fix/warnings-and-call-timer
This commit is contained in:
commit
17f186b935
10 files changed
+95
-26
No files matched your search
@@ -37,7 +37,8 @@ Below is the list of configuration options:
|
|||||||
| twitter.allowEdtiableProfileName | true | Whether or not players can edit their profile name |
|
| twitter.allowEdtiableProfileName | true | Whether or not players can edit their profile name |
|
||||||
| twitter.allowDeleteTweets | true | Whether or not players can delete their own tweets |
|
| twitter.allowDeleteTweets | true | Whether or not players can delete their own tweets |
|
||||||
| twitter.allowReportTweets | true | Whether or not players can report tweets. Optional discord integration. |
|
| twitter.allowReportTweets | true | Whether or not players can report tweets. Optional discord integration. |
|
||||||
| twitter.characterLimit | 240 | Limit on how many characters tweets can contain |
|
| twitter.characterLimit | 160 | Limit on how many characters tweets can contain |
|
||||||
|
| twitter.newLineLimit | 10 | Limit on how many new lines a message can contain |
|
||||||
| twitter.enableAvatars | true | Whether or not player's can select avatars for their twitter profile |
|
| twitter.enableAvatars | true | Whether or not player's can select avatars for their twitter profile |
|
||||||
| twitter.enableEmojis | true | Whether or not player's can use emojis in tweets |
|
| twitter.enableEmojis | true | Whether or not player's can use emojis in tweets |
|
||||||
| twitter.enableImages | true | Whether or not player's can add images to tweets (external URLs) |
|
| twitter.enableImages | true | Whether or not player's can add images to tweets (external URLs) |
|
||||||
|
|||||||
+2
-1
@@ -20,7 +20,8 @@
|
|||||||
"allowEdtiableProfileName": true,
|
"allowEdtiableProfileName": true,
|
||||||
"allowDeleteTweets": true,
|
"allowDeleteTweets": true,
|
||||||
"allowReportTweets": true,
|
"allowReportTweets": true,
|
||||||
"characterLimit": 240,
|
"characterLimit": 160,
|
||||||
|
"newLineLimit": 10,
|
||||||
"enableAvatars": true,
|
"enableAvatars": true,
|
||||||
"enableEmojis": true,
|
"enableEmojis": true,
|
||||||
"enableImages": true,
|
"enableImages": true,
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
import React from 'react';
|
import React, { useMemo } from 'react';
|
||||||
import { useCalculator, CalcButton } from '../hooks/useCalculator';
|
import { useCalculator, CalcButton } from '../hooks/useCalculator';
|
||||||
import { Grid, makeStyles, Box, Paper } from '@material-ui/core';
|
import { Grid, makeStyles, Box, Paper, Fab } from '@material-ui/core';
|
||||||
|
import { setClipboard } from '../../../os/phone/hooks/useClipboard';
|
||||||
|
import FileCopyIcon from '@material-ui/icons/FileCopy';
|
||||||
|
|
||||||
const useStyles = makeStyles((theme) => ({
|
const useStyles = makeStyles((theme) => ({
|
||||||
button: {
|
button: {
|
||||||
@@ -12,6 +14,12 @@ const useStyles = makeStyles((theme) => ({
|
|||||||
textAlign: 'right',
|
textAlign: 'right',
|
||||||
overflow: 'hidden',
|
overflow: 'hidden',
|
||||||
textOverflow: 'ellipsis',
|
textOverflow: 'ellipsis',
|
||||||
|
position: 'relative',
|
||||||
|
},
|
||||||
|
copyFab: {
|
||||||
|
position: 'absolute',
|
||||||
|
top: '16px',
|
||||||
|
left: '16px',
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
|
|
||||||
@@ -38,13 +46,22 @@ export const Calculator = ({ ...props }) => {
|
|||||||
nine,
|
nine,
|
||||||
} = useCalculator();
|
} = useCalculator();
|
||||||
const classes = useStyles();
|
const classes = useStyles();
|
||||||
|
const resultStr = useMemo(
|
||||||
|
() =>
|
||||||
|
result().toLocaleString(undefined, {
|
||||||
|
minimumFractionDigits: 0,
|
||||||
|
maximumFractionDigits: 4,
|
||||||
|
}),
|
||||||
|
[result]
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box display='flex' flexDirection='column'>
|
<Box display='flex' flexDirection='column'>
|
||||||
<Box flexGrow={1} component={Paper} p={4} className={classes.result}>
|
<Box flexGrow={1} component={Paper} p={4} className={classes.result}>
|
||||||
{result().toLocaleString(undefined, {
|
<Fab size="small" onClick={() => setClipboard(resultStr)} className={classes.copyFab}>
|
||||||
minimumFractionDigits: 0,
|
<FileCopyIcon />
|
||||||
maximumFractionDigits: 4,
|
</Fab>
|
||||||
})}
|
{resultStr}
|
||||||
</Box>
|
</Box>
|
||||||
<Box>
|
<Box>
|
||||||
<Grid container justify='space-around'>
|
<Grid container justify='space-around'>
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import React, { useCallback, useEffect, useMemo, useState } from 'react';
|
import React, { useCallback, useEffect, useMemo, useState } from 'react';
|
||||||
import qs from 'qs';
|
import qs from 'qs';
|
||||||
import Nui from '../../../../os/nui-events/utils/Nui';
|
import Nui from '../../../../os/nui-events/utils/Nui';
|
||||||
|
import CloseIcon from '@material-ui/icons/Close';
|
||||||
import Modal from '../../../../ui/components/Modal';
|
import Modal from '../../../../ui/components/Modal';
|
||||||
import PhotoLibraryIcon from '@material-ui/icons/PhotoLibrary';
|
import PhotoLibraryIcon from '@material-ui/icons/PhotoLibrary';
|
||||||
import { Box, Button, TextField, Typography } from '@material-ui/core';
|
import { Box, Button, TextField, Typography } from '@material-ui/core';
|
||||||
@@ -32,6 +33,11 @@ export const MessageImageModal = ({
|
|||||||
const [pasteVisible, setPasteVisible] = useState(false);
|
const [pasteVisible, setPasteVisible] = useState(false);
|
||||||
const [queryParamImagePreview, setQueryParamImagePreview] = useState(null);
|
const [queryParamImagePreview, setQueryParamImagePreview] = useState(null);
|
||||||
|
|
||||||
|
const removeQueryParamImage = useCallback(() => {
|
||||||
|
setQueryParamImagePreview(null);
|
||||||
|
history.replace(deleteQueryFromLocation({ pathname, search }, 'image'));
|
||||||
|
}, [history, pathname, search]);
|
||||||
|
|
||||||
const sendImageMessage = useCallback(
|
const sendImageMessage = useCallback(
|
||||||
(m) => {
|
(m) => {
|
||||||
Nui.send('phone:sendMessage', {
|
Nui.send('phone:sendMessage', {
|
||||||
@@ -45,13 +51,10 @@ export const MessageImageModal = ({
|
|||||||
|
|
||||||
const sendFromQueryParam = useCallback(
|
const sendFromQueryParam = useCallback(
|
||||||
(image) => {
|
(image) => {
|
||||||
setQueryParamImagePreview(null);
|
|
||||||
sendImageMessage(image);
|
sendImageMessage(image);
|
||||||
|
removeQueryParamImage();
|
||||||
console.log('++++', { pathname, search });
|
|
||||||
history.replace(deleteQueryFromLocation({ pathname, search }, 'image'));
|
|
||||||
},
|
},
|
||||||
[history, pathname, search, sendImageMessage]
|
[removeQueryParamImage, sendImageMessage]
|
||||||
);
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -82,8 +85,13 @@ export const MessageImageModal = ({
|
|||||||
})}`
|
})}`
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
label: 'Cancel',
|
||||||
|
icon: <CloseIcon />,
|
||||||
|
onClick: onClose,
|
||||||
|
},
|
||||||
],
|
],
|
||||||
[history, pathname, search]
|
[onClose, history, pathname, search]
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -91,7 +99,7 @@ export const MessageImageModal = ({
|
|||||||
<ContextMenu open={isOpen} options={menuOptions} onClose={onClose} />
|
<ContextMenu open={isOpen} options={menuOptions} onClose={onClose} />
|
||||||
<Modal
|
<Modal
|
||||||
visible={queryParamImagePreview}
|
visible={queryParamImagePreview}
|
||||||
handleClose={() => setQueryParamImagePreview(null)}
|
handleClose={removeQueryParamImage}
|
||||||
>
|
>
|
||||||
<Box py={1}>
|
<Box py={1}>
|
||||||
<Typography paragraph>Do you want to share this image?</Typography>
|
<Typography paragraph>Do you want to share this image?</Typography>
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import TweetMessage from './tweet/TweetMessage';
|
|||||||
import ControlButtons from './buttons/ControlButtons';
|
import ControlButtons from './buttons/ControlButtons';
|
||||||
import IconButtons from './buttons/IconButtons';
|
import IconButtons from './buttons/IconButtons';
|
||||||
import { usePhone } from '../../../os/phone/hooks/usePhone';
|
import { usePhone } from '../../../os/phone/hooks/usePhone';
|
||||||
|
import { getNewLineCount } from '../utils/message';
|
||||||
|
|
||||||
const useStyles = makeStyles((theme) => ({
|
const useStyles = makeStyles((theme) => ({
|
||||||
root: {
|
root: {
|
||||||
@@ -59,6 +60,7 @@ export const AddTweetModal = () => {
|
|||||||
const [link, setLink] = useState('');
|
const [link, setLink] = useState('');
|
||||||
|
|
||||||
const [images, setImages] = useState<Image[]>([]);
|
const [images, setImages] = useState<Image[]>([]);
|
||||||
|
const { characterLimit, newLineLimit } = config.twitter;
|
||||||
|
|
||||||
const reset = () => {
|
const reset = () => {
|
||||||
setShowImagePrompt(false);
|
setShowImagePrompt(false);
|
||||||
@@ -89,10 +91,16 @@ export const AddTweetModal = () => {
|
|||||||
|
|
||||||
if (!config) return null;
|
if (!config) return null;
|
||||||
|
|
||||||
|
const isValidMessage = message => {
|
||||||
|
if (message.length > characterLimit) return false;
|
||||||
|
if (getNewLineCount(message) > newLineLimit) return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
const submitTweet = () => {
|
const submitTweet = () => {
|
||||||
const cleanedMessage = message.trim();
|
const cleanedMessage = message.trim();
|
||||||
if (cleanedMessage.length === 0) return;
|
if (cleanedMessage.length === 0) return;
|
||||||
if (cleanedMessage.length > config.twitter.characterLimit) return;
|
if (!isValidMessage(cleanedMessage)) return;
|
||||||
|
|
||||||
const data = {
|
const data = {
|
||||||
message,
|
message,
|
||||||
@@ -106,7 +114,7 @@ export const AddTweetModal = () => {
|
|||||||
_handleClose();
|
_handleClose();
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleMessageChange = (e) => setMessage(e.target.value);
|
const handleMessageChange = (message) => setMessage(message);
|
||||||
|
|
||||||
const addImage = () => {
|
const addImage = () => {
|
||||||
// strip any whitespace from the link in case the user
|
// strip any whitespace from the link in case the user
|
||||||
|
|||||||
@@ -1,14 +1,17 @@
|
|||||||
import React from 'react';
|
import React, { useRef } from 'react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { makeStyles } from '@material-ui/core/styles';
|
import { makeStyles } from '@material-ui/core/styles';
|
||||||
import { TextField } from '@material-ui/core';
|
import { TextField } from '@material-ui/core';
|
||||||
import { usePhone } from '../../../../os/phone/hooks/usePhone';
|
import { usePhone } from '../../../../os/phone/hooks/usePhone';
|
||||||
|
import { getNewLineCount } from '../../utils/message';
|
||||||
|
|
||||||
const useStyles = makeStyles((theme) => ({
|
const useStyles = makeStyles((theme) => ({
|
||||||
textField: {
|
textField: {
|
||||||
flex: '1 1 100%',
|
flex: '1 1 100%',
|
||||||
padding: '10px 15px',
|
padding: '10px 15px',
|
||||||
marginTop: '15px',
|
marginTop: '15px',
|
||||||
|
overflowY: 'auto',
|
||||||
|
maxHeight: '300px',
|
||||||
},
|
},
|
||||||
textFieldInput: {
|
textFieldInput: {
|
||||||
fontSize: '22px',
|
fontSize: '22px',
|
||||||
@@ -19,29 +22,54 @@ const useStyles = makeStyles((theme) => ({
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
export const TweetMessage = ({ message, handleChange }) => {
|
export const TweetMessage = ({ message, handleChange }) => {
|
||||||
|
const textFieldRef = useRef(null);
|
||||||
const classes = useStyles();
|
const classes = useStyles();
|
||||||
const { config } = usePhone();
|
const { config } = usePhone();
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
if (!config) return null;
|
if (!config) return null;
|
||||||
|
const { characterLimit, newLineLimit } = config.twitter;
|
||||||
|
|
||||||
|
const _handleChange = (e) => {
|
||||||
|
// when the user types scroll the text field to the bottom
|
||||||
|
// so that we always have the latest line and error message
|
||||||
|
// in view
|
||||||
|
e.preventDefault();
|
||||||
|
textFieldRef.current.scrollTop = textFieldRef.current.scrollHeight;
|
||||||
|
handleChange(e.target.value);
|
||||||
|
}
|
||||||
|
|
||||||
|
let errorMessage = null;
|
||||||
|
|
||||||
const overCharacterLimit =
|
const overCharacterLimit =
|
||||||
message.trim().length > config.twitter.characterLimit;
|
message.trim().length > characterLimit;
|
||||||
const characterWarningPrompt = `${t(
|
const characterWarningPrompt = `${t(
|
||||||
'APPS_TWITTER_TWEET_MESSAGE_CHAR_LIMIT'
|
'APPS_TWITTER_TWEET_MESSAGE_CHAR_LIMIT'
|
||||||
)} (${config.twitter.characterLimit})`;
|
)} (${characterLimit})`;
|
||||||
|
|
||||||
|
const overNewLineLimit = getNewLineCount(message) > newLineLimit;
|
||||||
|
const newLineWarningPrompt = `${t(
|
||||||
|
'APPS_TWITTER_TWEET_MESSAGE_NEW_LINE_LIMIT'
|
||||||
|
)} (${newLineLimit})`;
|
||||||
|
|
||||||
|
if (overCharacterLimit) {
|
||||||
|
errorMessage = characterWarningPrompt;
|
||||||
|
} else if (overNewLineLimit) {
|
||||||
|
errorMessage = newLineWarningPrompt;
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<TextField
|
<TextField
|
||||||
value={message}
|
value={message}
|
||||||
inputProps={{ className: classes.textFieldInput }}
|
inputProps={{ className: classes.textFieldInput }}
|
||||||
className={classes.textField}
|
className={classes.textField}
|
||||||
onChange={handleChange}
|
onChange={_handleChange}
|
||||||
multiline
|
multiline
|
||||||
placeholder={t('APPS_TWITTER_TWEET_MESSAGE_PLACEHOLDER')}
|
placeholder={t('APPS_TWITTER_TWEET_MESSAGE_PLACEHOLDER')}
|
||||||
inputRef={(input) => input && input.focus()}
|
inputRef={(input) => input && input.focus()}
|
||||||
error={overCharacterLimit}
|
error={errorMessage !== null}
|
||||||
helperText={overCharacterLimit ? characterWarningPrompt : null}
|
helperText={errorMessage || null}
|
||||||
|
ref={textFieldRef}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
|
||||||
|
export function getNewLineCount(message: string): number {
|
||||||
|
return message.split(/\r\n|\r|\n/).length;
|
||||||
|
}
|
||||||
@@ -5,6 +5,7 @@ interface TwitterConfig {
|
|||||||
allowDeleteTweets: boolean;
|
allowDeleteTweets: boolean;
|
||||||
allowReportTweets: boolean;
|
allowReportTweets: boolean;
|
||||||
characterLimit: number;
|
characterLimit: number;
|
||||||
|
newLineLimit: number;
|
||||||
enableAvatars: boolean;
|
enableAvatars: boolean;
|
||||||
enableEmojis: boolean;
|
enableEmojis: boolean;
|
||||||
enableImages: boolean;
|
enableImages: boolean;
|
||||||
|
|||||||
@@ -33,6 +33,7 @@
|
|||||||
"APPS_TWITTER_SEARCH_TWEETS": "Search for tweets",
|
"APPS_TWITTER_SEARCH_TWEETS": "Search for tweets",
|
||||||
"APPS_TWITTER_SEARCH_TWEETS_PLACEHOLDER": "Search by profile name or message",
|
"APPS_TWITTER_SEARCH_TWEETS_PLACEHOLDER": "Search by profile name or message",
|
||||||
"APPS_TWITTER_TWEET_MESSAGE_CHAR_LIMIT": "Message is over the character limit",
|
"APPS_TWITTER_TWEET_MESSAGE_CHAR_LIMIT": "Message is over the character limit",
|
||||||
|
"APPS_TWITTER_TWEET_MESSAGE_NEW_LINE_LIMIT": "Message is over the new line limit",
|
||||||
"APPS_TWITTER_CREATE_SUCCESS": "Successfully sent your tweet",
|
"APPS_TWITTER_CREATE_SUCCESS": "Successfully sent your tweet",
|
||||||
"APPS_TWITTER_CREATE_FAILED": "Failed to send your tweet",
|
"APPS_TWITTER_CREATE_FAILED": "Failed to send your tweet",
|
||||||
"APPS_TWITTER_EDIT_PROFILE_AVATAR": "Avatar URL",
|
"APPS_TWITTER_EDIT_PROFILE_AVATAR": "Avatar URL",
|
||||||
|
|||||||
@@ -41,9 +41,9 @@ async function saveCall(call: ICall) {
|
|||||||
await pool.query(query, [call.transmitter, call.receiver, call.start]);
|
await pool.query(query, [call.transmitter, call.receiver, call.start]);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function updateCall(call: ICall, isAccepted: boolean, end?: number) {
|
async function updateCall(call: ICall, isAccepted: boolean, end: number) {
|
||||||
const query =
|
const query =
|
||||||
'UPDATE npwd_calls SET is_accepted, end (?, ?) WHERE identifier = ?';
|
'UPDATE npwd_calls SET is_accepted=?, end=? WHERE identifier = ?';
|
||||||
await pool.query(query, [isAccepted, end, call.identifier]);
|
await pool.query(query, [isAccepted, end, call.identifier]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -115,7 +115,7 @@ onNet(events.PHONE_ACCEPT_CALL, async (transmitterNumber: string) => {
|
|||||||
const currentCall = calls.get(transmitterNumber);
|
const currentCall = calls.get(transmitterNumber);
|
||||||
const channelId = pSource;
|
const channelId = pSource;
|
||||||
|
|
||||||
await updateCall(currentCall, true);
|
await updateCall(currentCall, true, null);
|
||||||
|
|
||||||
// player who is being called
|
// player who is being called
|
||||||
emitNet(
|
emitNet(
|
||||||
|
|||||||
Reference in new issue
Block a user