1- import { useRef } from 'react'
21import {
32 data ,
4- Form ,
53 Link ,
64 Links ,
75 Meta ,
@@ -10,7 +8,6 @@ import {
108 ScrollRestoration ,
119 useLoaderData ,
1210 useMatches ,
13- useSubmit ,
1411} from 'react-router'
1512import { HoneypotProvider } from 'remix-utils/honeypot/react'
1613import { type Route } from './+types/root.ts'
@@ -21,15 +18,9 @@ import { EpicProgress } from './components/progress-bar.tsx'
2118import { SearchBar } from './components/search-bar.tsx'
2219import { useToast } from './components/toaster.tsx'
2320import { Button } from './components/ui/button.tsx'
24- import {
25- DropdownMenu ,
26- DropdownMenuContent ,
27- DropdownMenuItem ,
28- DropdownMenuPortal ,
29- DropdownMenuTrigger ,
30- } from './components/ui/dropdown-menu.tsx'
31- import { Icon , href as iconsHref } from './components/ui/icon.tsx'
21+ import { href as iconsHref } from './components/ui/icon.tsx'
3222import { EpicToaster } from './components/ui/sonner.tsx'
23+ import { UserDropdown } from './components/user-dropdown.tsx'
3324import {
3425 ThemeSwitch ,
3526 useOptionalTheme ,
@@ -42,12 +33,12 @@ import { prisma } from './utils/db.server.ts'
4233import { getEnv } from './utils/env.server.ts'
4334import { pipeHeaders } from './utils/headers.server.ts'
4435import { honeypot } from './utils/honeypot.server.ts'
45- import { combineHeaders , getDomainUrl , getUserImgSrc } from './utils/misc.tsx'
36+ import { combineHeaders , getDomainUrl } from './utils/misc.tsx'
4637import { useNonce } from './utils/nonce-provider.ts'
4738import { type Theme , getTheme } from './utils/theme.server.ts'
4839import { makeTimings , time } from './utils/timing.server.ts'
4940import { getToast } from './utils/toast.server.ts'
50- import { useOptionalUser , useUser } from './utils/user.ts'
41+ import { useOptionalUser } from './utils/user.ts'
5142
5243export const links : Route . LinksFunction = ( ) => {
5344 return [
@@ -264,67 +255,6 @@ function AppWithProviders() {
264255
265256export default AppWithProviders
266257
267- function UserDropdown ( ) {
268- const user = useUser ( )
269- const submit = useSubmit ( )
270- const formRef = useRef < HTMLFormElement > ( null )
271- return (
272- < DropdownMenu >
273- < DropdownMenuTrigger asChild >
274- < Button asChild variant = "secondary" >
275- < Link
276- to = { `/users/${ user . username } ` }
277- // this is for progressive enhancement
278- onClick = { ( e ) => e . preventDefault ( ) }
279- className = "flex items-center gap-2"
280- >
281- < img
282- className = "h-8 w-8 rounded-full object-cover"
283- alt = { user . name ?? user . username }
284- src = { getUserImgSrc ( user . image ?. id ) }
285- />
286- < span className = "text-body-sm font-bold" >
287- { user . name ?? user . username }
288- </ span >
289- </ Link >
290- </ Button >
291- </ DropdownMenuTrigger >
292- < DropdownMenuPortal >
293- < DropdownMenuContent sideOffset = { 8 } align = "start" >
294- < DropdownMenuItem asChild >
295- < Link prefetch = "intent" to = { `/users/${ user . username } ` } >
296- < Icon className = "text-body-md" name = "avatar" >
297- Profile
298- </ Icon >
299- </ Link >
300- </ DropdownMenuItem >
301- < DropdownMenuItem asChild >
302- < Link prefetch = "intent" to = { `/users/${ user . username } /notes` } >
303- < Icon className = "text-body-md" name = "pencil-2" >
304- Notes
305- </ Icon >
306- </ Link >
307- </ DropdownMenuItem >
308- < DropdownMenuItem
309- asChild
310- // this prevents the menu from closing before the form submission is completed
311- onSelect = { async ( event ) => {
312- event . preventDefault ( )
313- await submit ( formRef . current )
314- } }
315- >
316- < Form action = "/logout" method = "POST" ref = { formRef } >
317- < Icon className = "text-body-md" name = "exit" >
318- < button type = "submit" > Logout</ button >
319- </ Icon >
320- </ Form >
321- </ DropdownMenuItem >
322- </ DropdownMenuContent >
323- </ DropdownMenuPortal >
324- </ DropdownMenu >
325- )
326- }
327-
328258// this is a last resort error boundary. There's not much useful information we
329259// can offer at this level.
330260export const ErrorBoundary = GeneralErrorBoundary
0 commit comments