Skip to content

Commit f2368e1

Browse files
committed
fix summary click
1 parent 957fc37 commit f2368e1

File tree

2 files changed

+54
-51
lines changed

2 files changed

+54
-51
lines changed

exercises/99.final/01.solution.final/src/routes.tsx

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,29 +21,29 @@ import { SignupRoute } from './routes/signup.tsx'
2121

2222
export const router = createBrowserRouter(
2323
createRoutesFromElements(
24-
<Route errorElement={<UnknownErrorBoundary />}>
25-
<Route path="/" element={<AppLayout />}>
26-
<Route element={<MarketingLayout />}>
27-
<Route index element={<HomepageRoute />} />
28-
<Route path="about" element={<AboutRoute />} />
24+
<Route ErrorBoundary={UnknownErrorBoundary}>
25+
<Route path="/" Component={AppLayout}>
26+
<Route Component={MarketingLayout}>
27+
<Route index Component={HomepageRoute} />
28+
<Route path="about" Component={AboutRoute} />
2929
</Route>
30-
<Route path="recipients" element={<RecipientsLayout />}>
31-
<Route index element={<RecipientIndexRoute />} />
32-
<Route path="new" element={<NewRecipientRoute />} />
30+
<Route path="recipients" Component={RecipientsLayout}>
31+
<Route index Component={RecipientIndexRoute} />
32+
<Route path="new" Component={NewRecipientRoute} />
3333
<Route
3434
path=":id"
35-
element={<RecipientRoute />}
36-
errorElement={<RecipientErrorBoundary />}
35+
Component={RecipientRoute}
36+
ErrorBoundary={RecipientErrorBoundary}
3737
/>
3838
<Route
3939
path=":id/edit"
40-
element={<RecipientEditRoute />}
41-
errorElement={<RecipientErrorBoundary />}
40+
Component={RecipientEditRoute}
41+
ErrorBoundary={RecipientErrorBoundary}
4242
/>
4343
</Route>
4444
</Route>
45-
<Route path="/signup" element={<SignupRoute />} />
46-
<Route path="*" element={<NotFoundRoute />} />
45+
<Route path="/signup" Component={SignupRoute} />
46+
<Route path="*" Component={NotFoundRoute} />
4747
</Route>,
4848
),
4949
)

exercises/99.final/01.solution.final/src/routes/app/recipients/layout.tsx

Lines changed: 40 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,13 @@ export function RecipientsLayout() {
2424
onBlur={(e) => {
2525
const relatedTarget = e.relatedTarget
2626
if (!e.currentTarget.contains(relatedTarget)) {
27-
e.currentTarget.removeAttribute('open')
27+
const el = e.currentTarget
28+
// seems to cause the browser to crash if relatedTarget is null
29+
// (like clicking within the details, but not on anything in particular)
30+
// so we wrap it in a requestAnimationFrame and it closes fine.
31+
requestAnimationFrame(() => {
32+
el.removeAttribute('open')
33+
})
2834
}
2935
}}
3036
onKeyDown={(e) => {
@@ -38,45 +44,42 @@ export function RecipientsLayout() {
3844
</summary>
3945
<div className="bg-background-alt absolute top-full left-0 z-10 mt-1 max-w-full min-w-64 border p-2 shadow-lg">
4046
{recipients.map((recipient) => (
41-
<div key={recipient.id} className="flex items-center gap-2">
42-
<NavLink
43-
to={recipient.id}
44-
className={({ isActive }) =>
45-
clsx(
46-
'overflow-x-auto text-xl',
47-
isActive ? 'underline' : '',
48-
)
49-
}
50-
onClick={(e) => {
51-
e.currentTarget
52-
.closest('details')
53-
?.removeAttribute('open')
54-
}}
55-
>
56-
{({ isActive }) => (
57-
<div className="flex items-center gap-1">
47+
<NavLink
48+
key={recipient.id}
49+
to={recipient.id}
50+
className={({ isActive }) =>
51+
clsx(
52+
'hover:bg-background flex items-center gap-2 overflow-x-auto text-xl',
53+
isActive ? 'underline' : '',
54+
)
55+
}
56+
onClick={(e) => {
57+
e.currentTarget.closest('details')?.removeAttribute('open')
58+
}}
59+
>
60+
{({ isActive }) => (
61+
<div className="flex items-center gap-1">
62+
<Icon
63+
name="ArrowRight"
64+
size="sm"
65+
className={clsx(
66+
isActive ? 'opacity-100' : 'opacity-0',
67+
'transition-opacity',
68+
)}
69+
/>
70+
{recipient.name}
71+
{recipient.messages.some(
72+
(m) => m.status === 'scheduled',
73+
) ? null : (
5874
<Icon
59-
name="ArrowRight"
60-
size="sm"
61-
className={clsx(
62-
isActive ? 'opacity-100' : 'opacity-0',
63-
'transition-opacity',
64-
)}
75+
name="ExclamationCircle"
76+
className="text-danger-foreground"
77+
title="no messages scheduled"
6578
/>
66-
{recipient.name}
67-
</div>
68-
)}
69-
</NavLink>
70-
{recipient.messages.some(
71-
(m) => m.status === 'scheduled',
72-
) ? null : (
73-
<Icon
74-
name="ExclamationCircle"
75-
className="text-danger-foreground"
76-
title="no messages scheduled"
77-
/>
79+
)}
80+
</div>
7881
)}
79-
</div>
82+
</NavLink>
8083
))}
8184
{recipients.length === 0 && (
8285
<div className="bg-warning-background text-warning-foreground px-4 py-2 text-sm">

0 commit comments

Comments
 (0)