fix(ui): improve sort controls and nested theme switcher in user menu

This commit is contained in:
yiling
2026-06-01 11:46:06 +08:00
parent 3608f8a919
commit ec356cf6bf
2 changed files with 49 additions and 18 deletions
+15 -13
View File
@@ -1,5 +1,6 @@
import { type FieldInfo as MetadataFieldInfo } from '@/dtos/metadata'
import type { SearchSort } from '@/dtos/search'
import { ArrowDownUp } from 'lucide-react'
import { Button } from '@/ui/components/ui/button'
import { Popover, PopoverContent, PopoverTrigger } from '@/ui/components/ui/popover'
import {
@@ -86,7 +87,7 @@ export function SortControl({ fields, sort, onSortChange, disabled }: SortContro
<div className="grid gap-2">
<span className="text-sm text-muted-foreground">Sort by</span>
<Select value={currentFieldId} onValueChange={handleFieldChange}>
<SelectTrigger>
<SelectTrigger className="w-full">
<SelectValue />
</SelectTrigger>
<SelectContent position="popper">
@@ -99,18 +100,19 @@ export function SortControl({ fields, sort, onSortChange, disabled }: SortContro
</Select>
</div>
<div className="flex items-center gap-3">
<span className="text-sm text-muted-foreground w-8">from</span>
<Select value={isAsc ? 'asc' : 'desc'} onValueChange={handleOrderChange}>
<SelectTrigger className="flex-1">
<SelectValue />
</SelectTrigger>
<SelectContent position="popper">
<SelectItem value="asc">{dirOptions.asc}</SelectItem>
<SelectItem value="desc">{dirOptions.desc}</SelectItem>
</SelectContent>
</Select>
</div>
{currentFieldId !== 'custom' && (
<div className="grid gap-2">
<span className="text-sm text-muted-foreground">Order</span>
<Button
variant="outline"
className="w-full justify-between font-normal"
onClick={() => handleOrderChange(isAsc ? 'desc' : 'asc')}
>
<span>{isAsc ? dirOptions.asc : dirOptions.desc}</span>
<ArrowDownUp className="size-4 opacity-50" />
</Button>
</div>
)}
</div>
</PopoverContent>
</Popover>
+34 -5
View File
@@ -7,6 +7,10 @@ import {
DropdownMenuLabel,
DropdownMenuSeparator,
DropdownMenuTrigger,
DropdownMenuSub,
DropdownMenuSubTrigger,
DropdownMenuSubContent,
DropdownMenuPortal,
} from '@/ui/components/ui/dropdown-menu'
import { useTeamId } from '@/ui/hooks/use-team-id'
import { signOut } from '@/ui/lib/auth-client'
@@ -14,6 +18,7 @@ import { useAuthStore } from '@/ui/stores/auth'
import { useQuery } from '@tanstack/react-query'
import { useNavigate } from '@tanstack/react-router'
import { useTheme } from './theme-provider'
import { Check } from 'lucide-react'
export function UserMenu() {
const { clearAuth } = useAuthStore()
@@ -30,7 +35,7 @@ export function UserMenu() {
},
enabled: !!teamId,
})
const { setTheme } = useTheme()
const { setTheme, theme } = useTheme()
const navigate = useNavigate()
const handleLogout = async () => {
@@ -69,10 +74,34 @@ export function UserMenu() {
<DropdownMenuSeparator />
</>
)}
<DropdownMenuLabel>Theme</DropdownMenuLabel>
<DropdownMenuItem onClick={() => setTheme('light')}>Light</DropdownMenuItem>
<DropdownMenuItem onClick={() => setTheme('dark')}>Dark</DropdownMenuItem>
<DropdownMenuItem onClick={() => setTheme('system')}>System</DropdownMenuItem>
<DropdownMenuSub>
<DropdownMenuSubTrigger>Theme</DropdownMenuSubTrigger>
<DropdownMenuPortal>
<DropdownMenuSubContent>
<DropdownMenuItem
className="justify-between flex items-center"
onClick={() => setTheme('light')}
>
<span>Light</span>
{theme === 'light' && <Check className="size-4" />}
</DropdownMenuItem>
<DropdownMenuItem
className="justify-between flex items-center"
onClick={() => setTheme('dark')}
>
<span>Dark</span>
{theme === 'dark' && <Check className="size-4" />}
</DropdownMenuItem>
<DropdownMenuItem
className="justify-between flex items-center"
onClick={() => setTheme('system')}
>
<span>System</span>
{theme === 'system' && <Check className="size-4" />}
</DropdownMenuItem>
</DropdownMenuSubContent>
</DropdownMenuPortal>
</DropdownMenuSub>
<DropdownMenuSeparator />
<DropdownMenuItem
onClick={() =>