From 1fca1ac200ff6116bfbce06601c05fe88260ed9f Mon Sep 17 00:00:00 2001 From: Kire Date: Thu, 4 Feb 2021 22:29:47 -0500 Subject: [PATCH 1/5] twitter char limit to 160 and added scroll --- config.json | 2 +- phone/src/apps/twitter/components/AddTweetModal.tsx | 6 +++++- phone/src/apps/twitter/components/tweet/TweetMessage.tsx | 2 ++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/config.json b/config.json index 8911194..f58d8d4 100644 --- a/config.json +++ b/config.json @@ -20,7 +20,7 @@ "allowEdtiableProfileName": true, "allowDeleteTweets": true, "allowReportTweets": true, - "characterLimit": 240, + "characterLimit": 160, "enableAvatars": true, "enableEmojis": true, "enableImages": true, diff --git a/phone/src/apps/twitter/components/AddTweetModal.tsx b/phone/src/apps/twitter/components/AddTweetModal.tsx index e780a42..157d5db 100644 --- a/phone/src/apps/twitter/components/AddTweetModal.tsx +++ b/phone/src/apps/twitter/components/AddTweetModal.tsx @@ -114,7 +114,11 @@ export const AddTweetModal = () => { _handleClose(); }; - const handleMessageChange = (e) => setMessage(e.target.value); + const handleMessageChange = (e: StandardInputProps['onChange']) => { + const message = e.target.value; + if (message.length > config.twitter.characterLimit) return; + setMessage(message) + } const addImage = () => { // strip any whitespace from the link in case the user diff --git a/phone/src/apps/twitter/components/tweet/TweetMessage.tsx b/phone/src/apps/twitter/components/tweet/TweetMessage.tsx index 520bb6e..9c81505 100644 --- a/phone/src/apps/twitter/components/tweet/TweetMessage.tsx +++ b/phone/src/apps/twitter/components/tweet/TweetMessage.tsx @@ -9,6 +9,8 @@ const useStyles = makeStyles((theme) => ({ flex: '1 1 100%', padding: '10px 15px', marginTop: '15px', + overflowY: 'auto', + maxHeight: '300px', }, textFieldInput: { fontSize: '22px', From 37504feec7fe0f6fbdaf907a8fa0595f16cc0a5c Mon Sep 17 00:00:00 2001 From: Kire Date: Thu, 4 Feb 2021 23:05:02 -0500 Subject: [PATCH 2/5] handle case where user spams new lines --- README.md | 3 +- config.json | 1 + .../apps/twitter/components/AddTweetModal.tsx | 16 +++++--- .../twitter/components/tweet/TweetMessage.tsx | 38 ++++++++++++++++--- phone/src/apps/twitter/utils/message.ts | 4 ++ phone/src/common/typings/config.ts | 1 + phone/src/locale/en.json | 1 + 7 files changed, 51 insertions(+), 13 deletions(-) create mode 100644 phone/src/apps/twitter/utils/message.ts diff --git a/README.md b/README.md index 266e269..d2390b8 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,8 @@ Below is the list of configuration options: | 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.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.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) | diff --git a/config.json b/config.json index f58d8d4..49e47a6 100644 --- a/config.json +++ b/config.json @@ -21,6 +21,7 @@ "allowDeleteTweets": true, "allowReportTweets": true, "characterLimit": 160, + "newLineLimit": 10, "enableAvatars": true, "enableEmojis": true, "enableImages": true, diff --git a/phone/src/apps/twitter/components/AddTweetModal.tsx b/phone/src/apps/twitter/components/AddTweetModal.tsx index 157d5db..487869a 100644 --- a/phone/src/apps/twitter/components/AddTweetModal.tsx +++ b/phone/src/apps/twitter/components/AddTweetModal.tsx @@ -16,6 +16,7 @@ import TweetMessage from './tweet/TweetMessage'; import ControlButtons from './buttons/ControlButtons'; import IconButtons from './buttons/IconButtons'; import { usePhone } from '../../../os/phone/hooks/usePhone'; +import { getNewLineCount } from '../utils/message'; const useStyles = makeStyles((theme) => ({ root: { @@ -67,6 +68,7 @@ export const AddTweetModal = () => { const [link, setLink] = useState(''); const [images, setImages] = useState([]); + const { characterLimit, newLineLimit } = config.twitter; const reset = () => { setShowImagePrompt(false); @@ -97,10 +99,16 @@ export const AddTweetModal = () => { if (!config) return null; + const isValidMessage = message => { + if (message.length > characterLimit) return false; + if (getNewLineCount(message) > newLineLimit) return false; + return true; + } + const submitTweet = () => { const cleanedMessage = message.trim(); if (cleanedMessage.length === 0) return; - if (cleanedMessage.length > config.twitter.characterLimit) return; + if (!isValidMessage(cleanedMessage)) return; const data = { message, @@ -114,11 +122,7 @@ export const AddTweetModal = () => { _handleClose(); }; - const handleMessageChange = (e: StandardInputProps['onChange']) => { - const message = e.target.value; - if (message.length > config.twitter.characterLimit) return; - setMessage(message) - } + const handleMessageChange = (message) => setMessage(message); const addImage = () => { // strip any whitespace from the link in case the user diff --git a/phone/src/apps/twitter/components/tweet/TweetMessage.tsx b/phone/src/apps/twitter/components/tweet/TweetMessage.tsx index 9c81505..c210be3 100644 --- a/phone/src/apps/twitter/components/tweet/TweetMessage.tsx +++ b/phone/src/apps/twitter/components/tweet/TweetMessage.tsx @@ -1,8 +1,9 @@ -import React from 'react'; +import React, { useRef } from 'react'; import { useTranslation } from 'react-i18next'; import { makeStyles } from '@material-ui/core/styles'; import { TextField } from '@material-ui/core'; import { usePhone } from '../../../../os/phone/hooks/usePhone'; +import { getNewLineCount } from '../../utils/message'; const useStyles = makeStyles((theme) => ({ textField: { @@ -21,29 +22,54 @@ const useStyles = makeStyles((theme) => ({ })); export const TweetMessage = ({ message, handleChange }) => { + const textFieldRef = useRef(null); const classes = useStyles(); const { config } = usePhone(); const { t } = useTranslation(); 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 = - message.trim().length > config.twitter.characterLimit; + message.trim().length > characterLimit; const characterWarningPrompt = `${t( '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 ( input && input.focus()} - error={overCharacterLimit} - helperText={overCharacterLimit ? characterWarningPrompt : null} + error={errorMessage !== null} + helperText={errorMessage || null} + ref={textFieldRef} /> ); }; diff --git a/phone/src/apps/twitter/utils/message.ts b/phone/src/apps/twitter/utils/message.ts new file mode 100644 index 0000000..cb8f6a7 --- /dev/null +++ b/phone/src/apps/twitter/utils/message.ts @@ -0,0 +1,4 @@ + +export function getNewLineCount(message: string): number { + return message.split(/\r\n|\r|\n/).length; +} \ No newline at end of file diff --git a/phone/src/common/typings/config.ts b/phone/src/common/typings/config.ts index 35a49d3..847d338 100644 --- a/phone/src/common/typings/config.ts +++ b/phone/src/common/typings/config.ts @@ -5,6 +5,7 @@ interface TwitterConfig { allowDeleteTweets: boolean; allowReportTweets: boolean; characterLimit: number; + newLineLimit: number; enableAvatars: boolean; enableEmojis: boolean; enableImages: boolean; diff --git a/phone/src/locale/en.json b/phone/src/locale/en.json index 9951d3a..56070c3 100644 --- a/phone/src/locale/en.json +++ b/phone/src/locale/en.json @@ -29,6 +29,7 @@ "APPS_TWITTER_SEARCH_TWEETS": "Search for tweets", "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_NEW_LINE_LIMIT": "Message is over the new line limit", "APPS_TWITTER_CREATE_SUCCESS": "Successfully sent your tweet", "APPS_TWITTER_CREATE_FAILED": "Failed to send your tweet", "APPS_TWITTER_EDIT_PROFILE_AVATAR": "Avatar URL", From 1db4dafa2d9d49848dfebcd7e6ae37ea43f05c81 Mon Sep 17 00:00:00 2001 From: J Francisco Rader Date: Sat, 6 Feb 2021 17:18:44 -0500 Subject: [PATCH 3/5] Fix sharing bug --- .../apps/calculator/components/Calculator.tsx | 29 +++++++++++++++---- .../components/modal/MessageImageModal.tsx | 22 +++++++++----- 2 files changed, 38 insertions(+), 13 deletions(-) diff --git a/phone/src/apps/calculator/components/Calculator.tsx b/phone/src/apps/calculator/components/Calculator.tsx index 598dc32..e45f71a 100644 --- a/phone/src/apps/calculator/components/Calculator.tsx +++ b/phone/src/apps/calculator/components/Calculator.tsx @@ -1,6 +1,8 @@ -import React from 'react'; +import React, { useMemo } from 'react'; 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) => ({ button: { @@ -12,6 +14,12 @@ const useStyles = makeStyles((theme) => ({ textAlign: 'right', overflow: 'hidden', textOverflow: 'ellipsis', + position: 'relative', + }, + copyFab: { + position: 'absolute', + top: '16px', + left: '16px', }, })); @@ -38,13 +46,22 @@ export const Calculator = ({ ...props }) => { nine, } = useCalculator(); const classes = useStyles(); + const resultStr = useMemo( + () => + result().toLocaleString(undefined, { + minimumFractionDigits: 0, + maximumFractionDigits: 4, + }), + [result] + ); + return ( - {result().toLocaleString(undefined, { - minimumFractionDigits: 0, - maximumFractionDigits: 4, - })} + setClipboard(resultStr)} className={classes.copyFab}> + + + {resultStr} diff --git a/phone/src/apps/messages/components/modal/MessageImageModal.tsx b/phone/src/apps/messages/components/modal/MessageImageModal.tsx index e5ecefb..d627794 100644 --- a/phone/src/apps/messages/components/modal/MessageImageModal.tsx +++ b/phone/src/apps/messages/components/modal/MessageImageModal.tsx @@ -1,6 +1,7 @@ import React, { useCallback, useEffect, useMemo, useState } from 'react'; import qs from 'qs'; import Nui from '../../../../os/nui-events/utils/Nui'; +import CloseIcon from '@material-ui/icons/Close'; import Modal from '../../../../ui/components/Modal'; import PhotoLibraryIcon from '@material-ui/icons/PhotoLibrary'; import { Box, Button, TextField, Typography } from '@material-ui/core'; @@ -32,6 +33,11 @@ export const MessageImageModal = ({ const [pasteVisible, setPasteVisible] = useState(false); const [queryParamImagePreview, setQueryParamImagePreview] = useState(null); + const removeQueryParamImage = useCallback(() => { + setQueryParamImagePreview(null); + history.replace(deleteQueryFromLocation({ pathname, search }, 'image')); + }, [history, pathname, search]); + const sendImageMessage = useCallback( (m) => { Nui.send('phone:sendMessage', { @@ -45,13 +51,10 @@ export const MessageImageModal = ({ const sendFromQueryParam = useCallback( (image) => { - setQueryParamImagePreview(null); sendImageMessage(image); - - console.log('++++', { pathname, search }); - history.replace(deleteQueryFromLocation({ pathname, search }, 'image')); + removeQueryParamImage(); }, - [history, pathname, search, sendImageMessage] + [removeQueryParamImage, sendImageMessage] ); useEffect(() => { @@ -82,8 +85,13 @@ export const MessageImageModal = ({ })}` ), }, + { + label: 'Cancel', + icon: , + onClick: onClose, + }, ], - [history, pathname, search] + [onClose, history, pathname, search] ); return ( @@ -91,7 +99,7 @@ export const MessageImageModal = ({ setQueryParamImagePreview(null)} + handleClose={removeQueryParamImage} > Do you want to share this image? From 892acd2f595b417d6bf63563b9f47c6b0064bd63 Mon Sep 17 00:00:00 2001 From: J Francisco Rader Date: Fri, 5 Feb 2021 15:08:25 -0500 Subject: [PATCH 4/5] Fix warnings + Improve CallTimer --- phone/src/apps/contacts/hooks/useContacts.ts | 1 - .../apps/dialer/components/DialerNavBar.tsx | 4 -- phone/src/modal/components/CallModal.tsx | 5 +- phone/src/modal/components/CallTimer.tsx | 49 ++++++++----------- phone/src/modal/hooks/useCall.ts | 2 +- phone/src/os/nui-events/hooks/useNuiEvent.ts | 2 +- 6 files changed, 24 insertions(+), 39 deletions(-) diff --git a/phone/src/apps/contacts/hooks/useContacts.ts b/phone/src/apps/contacts/hooks/useContacts.ts index 15df383..780e993 100644 --- a/phone/src/apps/contacts/hooks/useContacts.ts +++ b/phone/src/apps/contacts/hooks/useContacts.ts @@ -2,7 +2,6 @@ import { useRecoilValue } from 'recoil'; import { contactsState } from './state'; import { ContactProps } from '../../../common/typings/contact'; -import { useCall } from '../../../modal/hooks/useCall'; import { useCallback } from 'react'; interface IUseContacts { diff --git a/phone/src/apps/dialer/components/DialerNavBar.tsx b/phone/src/apps/dialer/components/DialerNavBar.tsx index 3da86d9..6951e4f 100644 --- a/phone/src/apps/dialer/components/DialerNavBar.tsx +++ b/phone/src/apps/dialer/components/DialerNavBar.tsx @@ -1,11 +1,7 @@ import React, { ChangeEvent, useState } from 'react'; import { BottomNavigation, BottomNavigationAction } from '@material-ui/core'; -import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; -import { faHome } from '@fortawesome/free-solid-svg-icons'; -import AddCircleIcon from '@material-ui/icons/AddCircle'; import { Link } from 'react-router-dom'; import { makeStyles, Theme } from '@material-ui/core/styles'; -import PhoneCallbackIcon from '@material-ui/icons/PhoneCallback'; import PhoneIcon from '@material-ui/icons/Phone'; import { History } from '@material-ui/icons'; diff --git a/phone/src/modal/components/CallModal.tsx b/phone/src/modal/components/CallModal.tsx index ff33f4e..6603f33 100644 --- a/phone/src/modal/components/CallModal.tsx +++ b/phone/src/modal/components/CallModal.tsx @@ -1,7 +1,6 @@ -import React, { useState } from 'react'; -import { Button, Fab } from '@material-ui/core'; +import React from 'react'; +import { Fab } from '@material-ui/core'; import { AppWrapper } from '../../ui/components/AppWrapper'; -import { AppTitle } from '../../ui/components/AppTitle'; import { AppContent } from '../../ui/components/AppContent'; import { useCall } from '../hooks/useCall'; import CallIcon from '@material-ui/icons/Call'; diff --git a/phone/src/modal/components/CallTimer.tsx b/phone/src/modal/components/CallTimer.tsx index ceea576..724dca8 100644 --- a/phone/src/modal/components/CallTimer.tsx +++ b/phone/src/modal/components/CallTimer.tsx @@ -1,8 +1,26 @@ -import React, { useState, useCallback, useEffect } from 'react'; +import React, { useCallback, useEffect, useRef } from 'react'; import { useDuration } from '../hooks/useDuration'; function CallTimer({ isAccepted }) { const { duration, setDuration } = useDuration(); + const updatedTime = useRef({ ms: 0, s: 0, m: 0, h: 0 }); + + const run = useCallback(() => { + let newTime = { ...updatedTime.current }; + if (newTime.m >= 60) { + newTime = { ...newTime, h: newTime.h + 1, m: 0 }; + } + if (newTime.s >= 60) { + newTime = { ...newTime, m: newTime.m + 1, s: 0 }; + } + if (newTime.ms >= 100) { + newTime = { ...newTime, s: newTime.s + 1, ms: 0 }; + } + + newTime = { ...newTime, ms: newTime.ms + 1 }; + updatedTime.current = newTime; + setDuration(newTime); + }, [setDuration]); useEffect(() => { let timer; @@ -12,37 +30,10 @@ function CallTimer({ isAccepted }) { } else { clearInterval(timer); } - }, []); - - let updatedMs = duration.ms, - updatedS = duration.s, - updatedM = duration.m, - updatedH = duration.h; + }, [isAccepted, run]); if (!duration) return null; - const run = () => { - if (updatedM === 60) { - updatedH++; - updatedM = 0; - } - if (updatedS === 60) { - updatedM++; - updatedS = 0; - } - if (updatedMs === 100) { - updatedS++; - updatedMs = 0; - } - updatedMs++; - return setDuration({ - ms: updatedMs, - s: updatedS, - m: updatedM, - h: updatedH, - }); - }; - return (
window.removeEventListener(eventName, eventListener, opts); - }, [app, method, capture, passive, once]); + }, [app, method, capture, passive, once, currentState]); }; From f626d1b0cefe742d10d9679e5ea5cbc552544655 Mon Sep 17 00:00:00 2001 From: Taso Date: Sat, 6 Feb 2021 19:48:18 -0500 Subject: [PATCH 5/5] fix(resources/calls): invalid sql syntax --- resources/server/sv_call.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/resources/server/sv_call.ts b/resources/server/sv_call.ts index ee2c683..eb4f31d 100644 --- a/resources/server/sv_call.ts +++ b/resources/server/sv_call.ts @@ -41,9 +41,9 @@ async function saveCall(call: ICall) { 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 = - '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]); } @@ -115,7 +115,7 @@ onNet(events.PHONE_ACCEPT_CALL, async (transmitterNumber: string) => { const currentCall = calls.get(transmitterNumber); const channelId = pSource; - await updateCall(currentCall, true); + await updateCall(currentCall, true, null); // player who is being called emitNet(