From 1c595d3e33e5d6e82dca43561a742a719587bfd3 Mon Sep 17 00:00:00 2001 From: MartinBraquet Date: Fri, 27 Feb 2026 13:26:33 +0100 Subject: [PATCH] Move DropdownOptions --- web/components/comments/dropdown-menu.tsx | 43 ++++++++++++++++ web/components/filters/last-active-filter.tsx | 49 ++----------------- 2 files changed, 46 insertions(+), 46 deletions(-) diff --git a/web/components/comments/dropdown-menu.tsx b/web/components/comments/dropdown-menu.tsx index 77d30324..9c0954e2 100644 --- a/web/components/comments/dropdown-menu.tsx +++ b/web/components/comments/dropdown-menu.tsx @@ -1,8 +1,11 @@ import {Popover, Transition} from '@headlessui/react' import {DotsHorizontalIcon} from '@heroicons/react/solid' import clsx from 'clsx' +import {toKey} from 'common/parsing' import {Fragment, ReactNode, useState} from 'react' import {usePopper} from 'react-popper' +import {Col} from 'web/components/layout/col' +import {useT} from 'web/lib/locale' export type DropdownItem = { name: string @@ -122,3 +125,43 @@ export const AnimationOrNothing = (props: { <>{props.children} ) } + +export function DropdownOptions(props: { + items: Record + onClick: (item: any) => void + activeKey: string + translationPrefix?: string +}) { + const {items, onClick, activeKey, translationPrefix} = props + + const t = useT() + + const translateOption = (key: string, value: string) => { + if (!translationPrefix) return value + return t(`${translationPrefix}.${toKey(key)}`, value) + } + + return ( + + {Object.entries(items).map(([key, item]) => ( +
+ +
+ ))} + + ) +} diff --git a/web/components/filters/last-active-filter.tsx b/web/components/filters/last-active-filter.tsx index e0a20f53..70185125 100644 --- a/web/components/filters/last-active-filter.tsx +++ b/web/components/filters/last-active-filter.tsx @@ -1,12 +1,9 @@ -import clsx from 'clsx' import {LAST_ONLINE_CHOICES} from 'common/choices' import {FilterFields} from 'common/filters' -import {toKey} from 'common/parsing' +import {DropdownOptions} from 'web/components/comments/dropdown-menu' import {Row} from 'web/components/layout/row' import {useT} from 'web/lib/locale' -import {Col} from '../layout/col' - const DEFAULT_KEY = 'any' export function LastActiveFilterText(props: { @@ -41,50 +38,10 @@ export function LastActiveFilter(props: { items={LAST_ONLINE_CHOICES} activeKey={filters.last_active || DEFAULT_KEY} translationPrefix={'filter.last_active'} - onClick={(option) => { - updateFilter({last_active: option === DEFAULT_KEY ? undefined : option}) + onClick={(key) => { + updateFilter({last_active: key === DEFAULT_KEY ? undefined : key}) close?.() }} /> ) } - -export function DropdownOptions(props: { - items: Record - onClick: (item: any) => void - activeKey: string - translationPrefix?: string -}) { - const {items, onClick, activeKey, translationPrefix} = props - - const t = useT() - - const translateOption = (key: string, value: string) => { - if (!translationPrefix) return value - return t(`${translationPrefix}.${toKey(key)}`, value) - } - - return ( - - {Object.entries(items).map(([key, item]) => ( -
- -
- ))} - - ) -}