Skip to content

Commit

Permalink
feat[frontend]: shift send in topic overview to instantly mark solution
Browse files Browse the repository at this point in the history
  • Loading branch information
darmiel committed Oct 20, 2023
1 parent 57d5652 commit e604be7
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 12 deletions.
1 change: 1 addition & 0 deletions frontend/src/api/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ export type priorityDeleteVars = {
// Comment Types
// ======================
export type sendCommentVars = {
__shift?: boolean
comment: string
}

Expand Down
25 changes: 13 additions & 12 deletions frontend/src/components/comment/CommentSendNewBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Button, Kbd, Textarea } from "@nextui-org/react"
import { useState } from "react"
import { toast } from "sonner"

import { CommentEntityType } from "@/api/types"
import { Comment, CommentEntityType } from "@/api/types"
import { extractErrorMessage } from "@/api/util"
import { useAuth } from "@/contexts/AuthContext"

Expand All @@ -11,11 +11,13 @@ export default function CommentSendNewBox({
commentType,
commentEntityID,
className = "",
onShiftSend,
}: {
projectID: number
commentType: CommentEntityType
commentEntityID: number
className?: string
onShiftSend?: (comment: Comment) => void
}) {
const [commentBoxText, setCommentBoxText] = useState("")

Expand All @@ -25,17 +27,20 @@ export default function CommentSendNewBox({
projectID,
commentType,
commentEntityID,
() => {
({ data }, { __shift }) => {
setCommentBoxText("")
toast.success("Comment sent!")
toast.success(`Comment sent! (#${data.ID})`)
if (__shift) {
onShiftSend?.(data)
}
},
)

function send() {
function send(shift: boolean) {
if (sendCommentMutation.isLoading) {
return
}
sendCommentMutation.mutate({ comment: commentBoxText })
sendCommentMutation.mutate({ comment: commentBoxText, __shift: shift })
}

const error = extractErrorMessage(sendCommentMutation.error)
Expand All @@ -50,12 +55,8 @@ export default function CommentSendNewBox({
value={commentBoxText}
onValueChange={setCommentBoxText}
onKeyDown={(e) => {
if (
e.key === "Enter" &&
e.getModifierState("Meta") &&
!e.getModifierState("Shift")
) {
send()
if (e.key === "Enter" && e.getModifierState("Meta")) {
send(e.getModifierState("Shift"))
}
}}
variant="bordered"
Expand All @@ -68,7 +69,7 @@ export default function CommentSendNewBox({
<Button
color="primary"
isLoading={sendCommentMutation.isLoading}
onClick={() => send()}
onClick={() => send(false)}
startContent={<Kbd keys={["command", "enter"]} />}
>
Send
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/components/comment/CommentSuite.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export default function CommentSuite({
listClassName = "",
onSolutionClick,
isSolutionMutLoading,
onShiftSend,
}: {
projectID: number
commentType: CommentEntityType
Expand All @@ -22,6 +23,7 @@ export default function CommentSuite({
listClassName?: string
onSolutionClick?: (mark: boolean, comment: Comment) => void
isSolutionMutLoading?: boolean
onShiftSend?: (comment: Comment) => void
}) {
const { comments: comment } = useAuth()

Expand Down Expand Up @@ -72,6 +74,7 @@ export default function CommentSuite({
projectID={projectID}
commentType={commentType}
commentEntityID={commentEntityID}
onShiftSend={onShiftSend}
/>
</>
)
Expand Down
6 changes: 6 additions & 0 deletions frontend/src/components/topic/TopicOverview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,12 @@ export default function TopicOverview({
commentSolutionID={topic.solution_id}
onSolutionClick={onSolutionClick}
isSolutionMutLoading={markSolutionMutation.isLoading}
onShiftSend={(comment) => {
markSolutionMutation.mutate({
commentID: comment.ID,
mark: true,
})
}}
/>
</OverviewContent>
<OverviewSide>
Expand Down

0 comments on commit e604be7

Please sign in to comment.