From 2c8d8d9989e6a385aca080db47294492c8a1379c Mon Sep 17 00:00:00 2001 From: MartinBraquet Date: Sat, 18 Oct 2025 00:12:53 +0200 Subject: [PATCH] Clean --- web/components/filters/search.tsx | 3 +-- web/components/votes/vote-buttons.tsx | 34 +++++++++++++++++++++++---- web/components/votes/vote-item.tsx | 6 +++-- web/pages/notifications.tsx | 2 +- 4 files changed, 35 insertions(+), 10 deletions(-) diff --git a/web/components/filters/search.tsx b/web/components/filters/search.tsx index eefe903..7a69feb 100644 --- a/web/components/filters/search.tsx +++ b/web/components/filters/search.tsx @@ -14,9 +14,8 @@ import {BookmarkSearchButton, BookmarkStarButton} from "web/components/searches/ import {BookmarkedSearchesType} from "web/hooks/use-bookmarked-searches"; import {submitBookmarkedSearch} from "web/lib/supabase/searches"; import {useUser} from "web/hooks/use-user"; -import {isEqual} from "lodash"; import toast from "react-hot-toast"; -import {FilterFields, initialFilters} from "common/filters"; +import {FilterFields} from "common/filters"; import {DisplayUser} from "common/api/user-types"; function isOrderBy(input: string): input is FilterFields['orderBy'] { diff --git a/web/components/votes/vote-buttons.tsx b/web/components/votes/vote-buttons.tsx index d2c080e..ec0d977 100644 --- a/web/components/votes/vote-buttons.tsx +++ b/web/components/votes/vote-buttons.tsx @@ -3,7 +3,7 @@ import {Button} from 'web/components/buttons/button' import clsx from 'clsx' import toast from 'react-hot-toast' import {api} from 'web/lib/api' -import {useState} from 'react' +import {useState, useEffect, useRef} from 'react' import {useUser} from "web/hooks/use-user"; export type VoteChoice = 'for' | 'abstain' | 'against' @@ -47,8 +47,32 @@ export function VoteButtons(props: { const {voteId, counts, onVoted, className} = props const [loading, setLoading] = useState(null) const [showPriority, setShowPriority] = useState(false) + const containerRef = useRef(null) const disabled = loading !== null + // Close the dropdown when clicking outside or pressing Escape + useEffect(() => { + if (!showPriority) return + + const handleClickOutside = (e: MouseEvent) => { + const target = e.target as Node | null + if (containerRef.current && target && !containerRef.current.contains(target)) { + setShowPriority(false) + } + } + + const handleKeyDown = (e: KeyboardEvent) => { + if (e.key === 'Escape') setShowPriority(false) + } + + document.addEventListener('mousedown', handleClickOutside) + document.addEventListener('keydown', handleKeyDown) + return () => { + document.removeEventListener('mousedown', handleClickOutside) + document.removeEventListener('keydown', handleKeyDown) + } + }, [showPriority]) + const sendVote = async (choice: VoteChoice, priority: number) => { try { setLoading(choice) @@ -79,7 +103,7 @@ export function VoteButtons(props: { return ( -
+
{showPriority && (
{priorities.map((p) => (