Merge pull request #65 from project-error/bug/twitter-char-limit

Bug/twitter char limit
This commit is contained in:
Christopher Gjelten authored and GitHub committed 2021-02-06 22:47:28 +01:00
commit ecd826dcd3
7 files changed
+54 -10

No files matched your search

@@ -14,6 +14,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: {
@@ -59,6 +60,7 @@ export const AddTweetModal = () => {
const [link, setLink] = useState('');
const [images, setImages] = useState<Image[]>([]);
const { characterLimit, newLineLimit } = config.twitter;
const reset = () => {
setShowImagePrompt(false);
@@ -89,10 +91,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,
@@ -106,7 +114,7 @@ export const AddTweetModal = () => {
_handleClose();
};
const handleMessageChange = (e) => setMessage(e.target.value);
const handleMessageChange = (message) => setMessage(message);
const addImage = () => {
// strip any whitespace from the link in case the user