Skip to content

Commit

Permalink
feat(zbugs): Put limits on textareas too for UI feedback.
Browse files Browse the repository at this point in the history
  • Loading branch information
aboodman committed Dec 27, 2024
1 parent 98d478d commit 8a15dfc
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 0 deletions.
8 changes: 8 additions & 0 deletions apps/zbugs/src/limits.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// NOTE: These limits are also in the postgres schema. These here are just for
// UI feedback.
export const MAX_ISSUE_TITLE_LENGTH = 128;
export const MAX_ISSUE_DESCRIPTION_LENGTH = 10 * 1024;

// The launch post has a special maxLength because trolls.
export const maxCommentLength = (issueID: string) =>
issueID === 'duuW9Nyj5cTNLlimp9Qje' ? 1024 : 64 * 1024;
3 changes: 3 additions & 0 deletions apps/zbugs/src/pages/issue/comment-composer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {Button} from '../../components/button.js';
import {useLogin} from '../../hooks/use-login.js';
import {useZero} from '../../hooks/use-zero.js';
import {isCtrlEnter} from './is-ctrl-enter.js';
import {maxCommentLength} from '../../limits.js';

export function CommentComposer({
id,
Expand Down Expand Up @@ -83,6 +84,8 @@ export function CommentComposer({
onChange={handleChange}
onKeyDown={handleKeyDown}
className="comment-input autoResize"
/* The launch post has a speical maxLength because trolls */
maxLength={maxCommentLength(issueID)}
/>
<Button
className="secondary-button"
Expand Down
6 changes: 6 additions & 0 deletions apps/zbugs/src/pages/issue/issue-composer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import {Button} from '../../components/button.js';
import {Modal, ModalActions, ModalBody} from '../../components/modal.js';
import {useZero} from '../../hooks/use-zero.js';
import {isCtrlEnter} from './is-ctrl-enter.js';
import {
MAX_ISSUE_DESCRIPTION_LENGTH,
MAX_ISSUE_TITLE_LENGTH,
} from '../../limits.js';

interface Props {
/** If id is defined the issue created by the composer. */
Expand Down Expand Up @@ -103,6 +107,7 @@ export function IssueComposer({isOpen, onDismiss}: Props) {
ref={focusInput} // Attach the inputRef to this input field
onChange={e => setTitle(e.target.value)}
onKeyDown={handleKeyDown}
maxLength={MAX_ISSUE_TITLE_LENGTH}
/>
</div>
<div className="w-full px-4">
Expand All @@ -112,6 +117,7 @@ export function IssueComposer({isOpen, onDismiss}: Props) {
onChange={e => setDescription(e.target.value)}
onKeyDown={handleKeyDown}
placeholder="Add description..."
maxLength={MAX_ISSUE_DESCRIPTION_LENGTH}
></textarea>
</div>
</ModalBody>
Expand Down
6 changes: 6 additions & 0 deletions apps/zbugs/src/pages/issue/issue-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ import {preload} from '../../zero-setup.js';
import {CommentComposer} from './comment-composer.js';
import {Comment} from './comment.js';
import {isCtrlEnter} from './is-ctrl-enter.js';
import {
MAX_ISSUE_DESCRIPTION_LENGTH,
MAX_ISSUE_TITLE_LENGTH,
} from '../../limits.js';

const emojiToastShowDuration = 3_000;

Expand Down Expand Up @@ -442,6 +446,7 @@ export function IssuePage({onReady}: {onReady: () => void}) {
autoFocus
onChange={e => setEdits({...edits, title: e.target.value})}
onKeyDown={e => isCtrlEnter(e) && save()}
maxLength={MAX_ISSUE_TITLE_LENGTH}
/>
</div>
)}
Expand Down Expand Up @@ -471,6 +476,7 @@ export function IssuePage({onReady}: {onReady: () => void}) {
setEdits({...edits, description: e.target.value})
}
onKeyDown={e => isCtrlEnter(e) && save()}
maxLength={MAX_ISSUE_DESCRIPTION_LENGTH}
/>
</div>
)}
Expand Down

0 comments on commit 8a15dfc

Please sign in to comment.