Enforce a max comment length

This commit is contained in:
James Grugett 2022-03-02 14:09:53 -08:00
parent 405604adef
commit cd8b336635
2 changed files with 5 additions and 2 deletions

View File

@ -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()

View File

@ -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,