fix(app): improve comment popover - remove disabled state, add error styling, fix click-outside detection
This commit is contained in:
@@ -1900,6 +1900,7 @@ export default function Page() {
|
|||||||
const [openedComment, setOpenedComment] = createSignal<string | null>(null)
|
const [openedComment, setOpenedComment] = createSignal<string | null>(null)
|
||||||
const [commenting, setCommenting] = createSignal<SelectedLineRange | null>(null)
|
const [commenting, setCommenting] = createSignal<SelectedLineRange | null>(null)
|
||||||
const [draft, setDraft] = createSignal("")
|
const [draft, setDraft] = createSignal("")
|
||||||
|
const [draftError, setDraftError] = createSignal(false)
|
||||||
const [positions, setPositions] = createSignal<Record<string, number>>({})
|
const [positions, setPositions] = createSignal<Record<string, number>>({})
|
||||||
const [draftTop, setDraftTop] = createSignal<number | undefined>(undefined)
|
const [draftTop, setDraftTop] = createSignal<number | undefined>(undefined)
|
||||||
|
|
||||||
@@ -2086,19 +2087,30 @@ export default function Page() {
|
|||||||
onClick={() => textarea?.focus()}
|
onClick={() => textarea?.focus()}
|
||||||
onPopoverFocusOut={(e) => {
|
onPopoverFocusOut={(e) => {
|
||||||
const target = e.relatedTarget as Node | null
|
const target = e.relatedTarget as Node | null
|
||||||
if (!target || !e.currentTarget.contains(target)) {
|
if (target && e.currentTarget.contains(target)) return
|
||||||
setCommenting(null)
|
// Delay to allow click handlers to fire first
|
||||||
}
|
setTimeout(() => {
|
||||||
|
if (!document.activeElement || !e.currentTarget.contains(document.activeElement)) {
|
||||||
|
setCommenting(null)
|
||||||
|
}
|
||||||
|
}, 0)
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<div class="flex flex-col gap-2">
|
<div class="flex flex-col gap-2">
|
||||||
<textarea
|
<textarea
|
||||||
ref={textarea}
|
ref={textarea}
|
||||||
class="w-full resize-vertical p-2 rounded-[6px] bg-surface-base border border-border-base text-text-strong text-12-regular leading-5 focus:outline-none focus:shadow-xs-border-select"
|
classList={{
|
||||||
|
"w-full resize-vertical p-2 rounded-[6px] bg-surface-base border text-text-strong text-12-regular leading-5 focus:outline-none focus:shadow-xs-border-select": true,
|
||||||
|
"border-transparent": !draftError(),
|
||||||
|
"border-border-critical-base": draftError(),
|
||||||
|
}}
|
||||||
rows={3}
|
rows={3}
|
||||||
placeholder="Add comment"
|
placeholder="Add comment"
|
||||||
value={draft()}
|
value={draft()}
|
||||||
onInput={(e) => setDraft(e.currentTarget.value)}
|
onInput={(e) => {
|
||||||
|
setDraft(e.currentTarget.value)
|
||||||
|
setDraftError(false)
|
||||||
|
}}
|
||||||
onKeyDown={(e) => {
|
onKeyDown={(e) => {
|
||||||
if (e.key === "Escape") {
|
if (e.key === "Escape") {
|
||||||
setCommenting(null)
|
setCommenting(null)
|
||||||
@@ -2108,7 +2120,10 @@ export default function Page() {
|
|||||||
if (e.shiftKey) return
|
if (e.shiftKey) return
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
const value = draft().trim()
|
const value = draft().trim()
|
||||||
if (!value) return
|
if (!value) {
|
||||||
|
setDraftError(true)
|
||||||
|
return
|
||||||
|
}
|
||||||
const p = path()
|
const p = path()
|
||||||
if (!p) return
|
if (!p) return
|
||||||
addCommentToContext({
|
addCommentToContext({
|
||||||
@@ -2131,10 +2146,12 @@ export default function Page() {
|
|||||||
<Button
|
<Button
|
||||||
size="small"
|
size="small"
|
||||||
variant="primary"
|
variant="primary"
|
||||||
disabled={draft().trim().length === 0}
|
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
const value = draft().trim()
|
const value = draft().trim()
|
||||||
if (!value) return
|
if (!value) {
|
||||||
|
setDraftError(true)
|
||||||
|
return
|
||||||
|
}
|
||||||
const p = path()
|
const p = path()
|
||||||
if (!p) return
|
if (!p) return
|
||||||
addCommentToContext({
|
addCommentToContext({
|
||||||
|
|||||||
Reference in New Issue
Block a user