Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(issues list): Prevent race condition when adding a commnet or replying to an issue #16

Merged
merged 1 commit into from
Aug 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions web/src/components/new-comment-form/new-comment-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useState } from 'react'
import { TextAreaField } from "../text-field"
import { Button } from "@/components/button"

import type { ChangeEvent } from 'react'
import type { ChangeEvent, FormEvent } from 'react'
import type { NewCommentFormProps } from './types'

const MAX_CHARACTERS_COUNT = 250
Expand All @@ -16,7 +16,9 @@ export default function NewCommentForm({ onSubmit }: NewCommentFormProps) {
setContent(event.target.value)
}

const handleSubmit = async () => {
const handleSubmit = async (event: FormEvent<HTMLFormElement>) => {
event.preventDefault();

if (content.length > MAX_CHARACTERS_COUNT) return
await onSubmit(content)
}
Expand Down
6 changes: 4 additions & 2 deletions web/src/components/new-reply-form/new-reply-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useState } from 'react'
import { TextAreaField } from "../text-field"
import { Button } from "@/components/button"

import type { ChangeEvent } from 'react'
import type { ChangeEvent, FormEvent } from 'react'
import type { NewReplyFormProps } from './types'

const MAX_CHARACTERS_COUNT = 250
Expand All @@ -16,7 +16,9 @@ export default function NewReplyForm({ onSubmit }: NewReplyFormProps) {
setContent(event.target.value)
}

const handleSubmit = async () => {
const handleSubmit = async (event: FormEvent<HTMLFormElement>) => {
event.preventDefault();

if (content.length > MAX_CHARACTERS_COUNT) return
await onSubmit(content)
}
Expand Down
8 changes: 6 additions & 2 deletions web/src/components/upvote-button/upvote-button.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use client'

import { useState } from 'react'
import { useState, type MouseEvent } from 'react'
import { ChevronIconUp } from "@/icons"

import type { UpvoteButtonProps } from './types'
Expand All @@ -9,7 +9,10 @@ export default function UpvoteButton({ issueUuid, upvotes, initialActive = false
const [upvotesCount, setUpvotesCount] = useState<number>(upvotes)
const [selected, setSelected] = useState<boolean>(initialActive)

const handleClick = () => {
const handleClick = (event: MouseEvent<HTMLButtonElement>) => {
event.stopPropagation();
event.preventDefault();

const newSelected = !selected
setSelected(newSelected)

Expand Down Expand Up @@ -37,6 +40,7 @@ export default function UpvoteButton({ issueUuid, upvotes, initialActive = false
${selected ? 'bg-savoy-blue text-white hover:opacity-80' : 'text-marian-blue bg-ghost-white hover:bg-periwinkle'}
`}
onClick={handleClick}
type="button"
>
<div className={`w-3 ${selected ? 'text-white' : 'text-savoy-blue'}`}>
<ChevronIconUp />
Expand Down
Loading