Skip to content

Commit 2c8d8d9

Browse files
committed
Clean
1 parent d52943e commit 2c8d8d9

4 files changed

Lines changed: 35 additions & 10 deletions

File tree

web/components/filters/search.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@ import {BookmarkSearchButton, BookmarkStarButton} from "web/components/searches/
1414
import {BookmarkedSearchesType} from "web/hooks/use-bookmarked-searches";
1515
import {submitBookmarkedSearch} from "web/lib/supabase/searches";
1616
import {useUser} from "web/hooks/use-user";
17-
import {isEqual} from "lodash";
1817
import toast from "react-hot-toast";
19-
import {FilterFields, initialFilters} from "common/filters";
18+
import {FilterFields} from "common/filters";
2019
import {DisplayUser} from "common/api/user-types";
2120

2221
function isOrderBy(input: string): input is FilterFields['orderBy'] {

web/components/votes/vote-buttons.tsx

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {Button} from 'web/components/buttons/button'
33
import clsx from 'clsx'
44
import toast from 'react-hot-toast'
55
import {api} from 'web/lib/api'
6-
import {useState} from 'react'
6+
import {useState, useEffect, useRef} from 'react'
77
import {useUser} from "web/hooks/use-user";
88

99
export type VoteChoice = 'for' | 'abstain' | 'against'
@@ -47,8 +47,32 @@ export function VoteButtons(props: {
4747
const {voteId, counts, onVoted, className} = props
4848
const [loading, setLoading] = useState<VoteChoice | null>(null)
4949
const [showPriority, setShowPriority] = useState(false)
50+
const containerRef = useRef<HTMLDivElement>(null)
5051
const disabled = loading !== null
5152

53+
// Close the dropdown when clicking outside or pressing Escape
54+
useEffect(() => {
55+
if (!showPriority) return
56+
57+
const handleClickOutside = (e: MouseEvent) => {
58+
const target = e.target as Node | null
59+
if (containerRef.current && target && !containerRef.current.contains(target)) {
60+
setShowPriority(false)
61+
}
62+
}
63+
64+
const handleKeyDown = (e: KeyboardEvent) => {
65+
if (e.key === 'Escape') setShowPriority(false)
66+
}
67+
68+
document.addEventListener('mousedown', handleClickOutside)
69+
document.addEventListener('keydown', handleKeyDown)
70+
return () => {
71+
document.removeEventListener('mousedown', handleClickOutside)
72+
document.removeEventListener('keydown', handleKeyDown)
73+
}
74+
}, [showPriority])
75+
5276
const sendVote = async (choice: VoteChoice, priority: number) => {
5377
try {
5478
setLoading(choice)
@@ -79,7 +103,7 @@ export function VoteButtons(props: {
79103

80104
return (
81105
<Row className={clsx('gap-4 mt-2', className)}>
82-
<div className="relative">
106+
<div className="relative" ref={containerRef}>
83107
<VoteButton
84108
color={clsx('bg-green-700 text-white hover:bg-green-500')}
85109
count={counts.for}
@@ -89,15 +113,15 @@ export function VoteButtons(props: {
89113
/>
90114
{showPriority && (
91115
<div className={clsx(
92-
'absolute z-10 mt-2 w-40 rounded-md border border-ink-200 bg-white shadow-lg',
116+
'absolute z-10 mt-2 w-40 rounded-md border border-ink-200 bg-canvas-50 shadow-lg',
93117
'dark:bg-ink-900'
94118
)}>
95119
{priorities.map((p) => (
96120
<button
97121
key={p.value}
98122
className={clsx(
99-
'w-full text-left px-3 py-2 text-sm hover:bg-ink-100',
100-
'dark:hover:bg-ink-800'
123+
'w-full text-left px-3 py-2 text-sm hover:bg-ink-100 bg-canvas-50',
124+
'dark:hover:bg-canvas-100'
101125
)}
102126
onClick={async () => {
103127
setShowPriority(false)

web/components/votes/vote-item.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@ export function VoteItem(props: {
3333
<Col className='text-sm text-gray-500 italic'>
3434
<Content className="w-full" content={vote.description as JSONContent}/>
3535
</Col>
36-
{vote.priority && <Col>Priority: {vote.priority / vote.votes_for}</Col>}
37-
{creator?.username && <Col className={'mt-2 customlink text-right'}><Link href={`/${creator.username}`}>{creator.username}</Link></Col>}
36+
<Row className={'gap-2 mt-2 items-center justify-between w-full customlink'}>
37+
{!!vote.priority ? <div>Priority: {((vote.priority / vote.votes_for / 3) * 100).toFixed(0)}%</div> : <p></p>}
38+
{creator?.username && <Link href={`/${creator.username}`} className="customlink">{creator.username}</Link>}
39+
</Row>
3840
<VoteButtons
3941
voteId={vote.id}
4042
counts={{

web/pages/notifications.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {Col} from 'web/components/layout/col'
1111
import {UncontrolledTabs} from 'web/components/layout/tabs'
1212
import {LovePage} from 'web/components/love-page'
1313
import {NotificationItem} from 'web/components/notification-items'
14-
import {CompassLoadingIndicator, LoadingIndicator} from 'web/components/widgets/loading-indicator'
14+
import {CompassLoadingIndicator} from 'web/components/widgets/loading-indicator'
1515
import {Pagination} from 'web/components/widgets/pagination'
1616
import {Title} from 'web/components/widgets/title'
1717
import {useGroupedNotifications} from 'web/hooks/use-notifications'

0 commit comments

Comments
 (0)