diff --git a/apps/web/src/components/items/create-item-form.tsx b/apps/web/src/components/items/create-item-form.tsx index 965211e..4211756 100644 --- a/apps/web/src/components/items/create-item-form.tsx +++ b/apps/web/src/components/items/create-item-form.tsx @@ -20,6 +20,23 @@ type CreateItemFormProps = { autoFocus?: boolean } +/** The input carries this id so it can be focused from outside the form (e.g. by the nav). */ +const NEW_ITEM_INPUT_ID = 'new-item-input' + +/** + * Puts the cursor in the "add an item" input when the home page is already the one on + * screen (the route does not remount, so nothing else would move the focus). When the + * user is navigating *to* the home page this is a no-op: the input takes the focus as + * soon as it mounts, through `autoFocus`. Either way, tapping "Inicio" always ends with + * the focus in the input — and never with the focus on another page's input. + * + * @param pathname the route the link was clicked from, so only the home input is focused. + */ +export function focusNewItemInput(pathname: string): void { + if (pathname !== '/') return + document.getElementById(NEW_ITEM_INPUT_ID)?.focus() +} + /** Input to add an item to a list. Submits with Enter or the button. */ export function CreateItemForm({ listId, autoFocus = false }: CreateItemFormProps) { const createItem = useCreateItem(listId) @@ -37,6 +54,7 @@ export function CreateItemForm({ listId, autoFocus = false }: CreateItemFormProp
- + focusNewItemInput(pathname)}>
SL
@@ -68,7 +69,10 @@ export function AppSidebar() { isActive={isActive(pathname, item.to)} tooltip={item.title} > - + focusNewItemInput(pathname) : undefined} + > {item.title} diff --git a/apps/web/src/components/layout/bottom-nav.tsx b/apps/web/src/components/layout/bottom-nav.tsx new file mode 100644 index 0000000..1d22d00 --- /dev/null +++ b/apps/web/src/components/layout/bottom-nav.tsx @@ -0,0 +1,74 @@ +import { Link, useRouterState } from '@tanstack/react-router' +import { HomeIcon, SettingsIcon, ShoppingCartIcon, UserIcon } from 'lucide-react' + +import { focusNewItemInput } from '@/components/items/create-item-form' +import { cn } from '@/lib/utils' + +function isActive(pathname: string, to: string) { + if (to === '/') return pathname === '/' + return pathname === to || pathname.startsWith(`${to}/`) +} + +export function BottomNav() { + const pathname = useRouterState({ select: (state) => state.location.pathname }) + + return ( +
+ +
+ ) +} diff --git a/apps/web/src/routes/_authenticated/index.tsx b/apps/web/src/routes/_authenticated/index.tsx index 2f3c969..564993b 100644 --- a/apps/web/src/routes/_authenticated/index.tsx +++ b/apps/web/src/routes/_authenticated/index.tsx @@ -64,7 +64,7 @@ function HomePage() { {primaryList.isPrimary && Principal} - +