From cd8b336635887ff2038de3c0f59592252297d020 Mon Sep 17 00:00:00 2001 From: James Grugett Date: Wed, 2 Mar 2022 14:09:53 -0800 Subject: [PATCH] Enforce a max comment length --- web/components/contract-feed.tsx | 3 ++- web/lib/firebase/comments.ts | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/web/components/contract-feed.tsx b/web/components/contract-feed.tsx index 5a3be62f..bf5885b5 100644 --- a/web/components/contract-feed.tsx +++ b/web/components/contract-feed.tsx @@ -25,7 +25,7 @@ import { import { useUser } from '../hooks/use-user' import { Linkify } from './linkify' import { Row } from './layout/row' -import { createComment } from '../lib/firebase/comments' +import { createComment, MAX_COMMENT_LENGTH } from '../lib/firebase/comments' import { useComments } from '../hooks/use-comments' import { formatMoney } from '../../common/util/format' import { ResolutionOrChance } from './contract-card' @@ -135,6 +135,7 @@ function FeedBet(props: { activityItem: any; feedType: FeedType }) { className="textarea textarea-bordered w-full" placeholder="Add a comment..." rows={3} + maxLength={MAX_COMMENT_LENGTH} onKeyDown={(e) => { if (e.key === 'Enter' && (e.ctrlKey || e.metaKey)) { submitComment() diff --git a/web/lib/firebase/comments.ts b/web/lib/firebase/comments.ts index 34e4bcfe..dfb9a01d 100644 --- a/web/lib/firebase/comments.ts +++ b/web/lib/firebase/comments.ts @@ -14,6 +14,8 @@ import { User } from '../../../common/user' import { Comment } from '../../../common/comment' export type { Comment } +export const MAX_COMMENT_LENGTH = 10000 + export async function createComment( contractId: string, betId: string, @@ -27,7 +29,7 @@ export async function createComment( contractId, betId, userId: commenter.id, - text, + text: text.slice(0, MAX_COMMENT_LENGTH), createdTime: Date.now(), userName: commenter.name, userUsername: commenter.username,