Skip to content

Commit 56c79c8

Browse files
committed
some improvements
1 parent 249b4cf commit 56c79c8

File tree

4 files changed

+20
-40
lines changed

4 files changed

+20
-40
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,5 @@ node_modules
2424

2525
# generated files
2626
/app/components/ui/icons
27+
28+
vite.config.ts.timestamp*

app/routes/_app+/recipients+/$recipientId.tsx

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
import { invariantResponse } from '@epic-web/invariant'
22
import { type LoaderFunctionArgs, type MetaFunction } from '@remix-run/node'
3-
import {
4-
Link,
5-
json,
6-
useLoaderData,
7-
useMatches,
8-
useOutlet,
9-
} from '@remix-run/react'
3+
import { Link, Outlet, json, useLoaderData, useMatches } from '@remix-run/react'
104
import { useEffect, useRef } from 'react'
115
import { GeneralErrorBoundary } from '#app/components/error-boundary.js'
126
import { Icon } from '#app/components/ui/icon.js'
@@ -58,7 +52,6 @@ export const meta: MetaFunction<typeof loader> = ({ data }) => {
5852
export default function RecipientRoute() {
5953
const data = useLoaderData<typeof loader>()
6054
const firstLinkRef = useRef<HTMLAnchorElement | null>(null)
61-
const outlet = useOutlet()
6255
const matches = useMatches()
6356
const lastMatch = matches[matches.length - 1]
6457
const idPortion = lastMatch?.id.split('.')?.at(-1) ?? '.'
@@ -135,7 +128,7 @@ export default function RecipientRoute() {
135128
<Link
136129
to="edit"
137130
className={`flex items-center gap-2 rounded-md px-3 py-2 transition-colors ${
138-
currentPath === 'past'
131+
currentPath === 'edit'
139132
? 'bg-accent text-accent-foreground'
140133
: 'hover:bg-accent/50'
141134
}`}
@@ -144,7 +137,9 @@ export default function RecipientRoute() {
144137
</Link>
145138
</nav>
146139
</div>
147-
<div className="overflow-y-auto px-4 py-6">{outlet}</div>
140+
<div className="overflow-y-auto px-4 py-6">
141+
<Outlet />
142+
</div>
148143
</div>
149144
)
150145
}

app/routes/_app+/recipients+/_layout.tsx

Lines changed: 13 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ import { json, type LoaderFunctionArgs } from '@remix-run/node'
22
import { Link, NavLink, Outlet, useLoaderData } from '@remix-run/react'
33
import { GeneralErrorBoundary } from '#app/components/error-boundary.tsx'
44
import { ButtonLink } from '#app/components/ui/button.tsx'
5+
import {
6+
DropdownMenu,
7+
DropdownMenuContent,
8+
DropdownMenuTrigger,
9+
} from '#app/components/ui/dropdown-menu.tsx'
510
import { Icon } from '#app/components/ui/icon.tsx'
611
import { SimpleTooltip } from '#app/components/ui/tooltip.js'
712
import { requireUserId } from '#app/utils/auth.server.js'
@@ -46,30 +51,11 @@ export default function RecipientsLayout() {
4651

4752
<div className="bg-background-alt flex min-h-0 flex-1 flex-col">
4853
<div className="flex flex-col gap-4 overflow-visible border-b-2 py-4 pl-1 pr-4">
49-
<details
50-
className="relative"
51-
onBlur={(e) => {
52-
const relatedTarget = e.relatedTarget
53-
if (!e.currentTarget.contains(relatedTarget)) {
54-
const el = e.currentTarget
55-
// seems to cause the browser to crash if relatedTarget is null
56-
// (like clicking within the details, but not on anything in particular)
57-
// so we wrap it in a requestAnimationFrame and it closes fine.
58-
requestAnimationFrame(() => {
59-
el.removeAttribute('open')
60-
})
61-
}
62-
}}
63-
onKeyDown={(e) => {
64-
if (e.key === 'Escape') {
65-
e.currentTarget.removeAttribute('open')
66-
}
67-
}}
68-
>
69-
<summary className="hover:bg-background-alt-hover cursor-pointer px-2 py-1">
70-
Select recipient
71-
</summary>
72-
<div className="bg-background-alt absolute left-0 top-full z-10 mt-1 min-w-64 max-w-full border p-2 shadow-lg">
54+
<DropdownMenu>
55+
<DropdownMenuTrigger className="hover:bg-background-alt-hover cursor-pointer px-2 py-1">
56+
<Icon name="chevron-down">Select recipient</Icon>
57+
</DropdownMenuTrigger>
58+
<DropdownMenuContent className="min-w-64">
7359
{recipients.map((recipient) => (
7460
<NavLink
7561
key={recipient.id}
@@ -80,9 +66,6 @@ export default function RecipientsLayout() {
8066
isActive ? 'underline' : '',
8167
)
8268
}
83-
onClick={(e) => {
84-
e.currentTarget.closest('details')?.removeAttribute('open')
85-
}}
8669
>
8770
{({ isActive }) => (
8871
<div className="flex items-center gap-1">
@@ -113,10 +96,10 @@ export default function RecipientsLayout() {
11396
No recipients found. Add one to get started.
11497
</div>
11598
)}
116-
</div>
117-
</details>
99+
</DropdownMenuContent>
100+
</DropdownMenu>
118101
</div>
119-
<main className="flex flex-1 overflow-auto">
102+
<main className="flex-1 overflow-auto">
120103
<Outlet />
121104
</main>
122105
</div>

0 commit comments

Comments
 (0)