From 39a07ccb6ba44866b3c3a4042c2936acfcd4fc1f Mon Sep 17 00:00:00 2001 From: Sam Becker Date: Tue, 20 Feb 2024 09:23:00 -0600 Subject: [PATCH] Refine Command-K behavior --- src/components/CommandKClient.tsx | 30 +++++++++++++++++++++++------- src/photo/PhotoTiny.tsx | 2 +- src/site/CommandK.tsx | 2 ++ 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/src/components/CommandKClient.tsx b/src/components/CommandKClient.tsx index 2791dc18..d75467ca 100644 --- a/src/components/CommandKClient.tsx +++ b/src/components/CommandKClient.tsx @@ -16,6 +16,7 @@ export type CommandKSection = { accessory?: ReactNode items: { label: string + note?: string accessory?: ReactNode path?: string action?: () => void @@ -64,19 +65,28 @@ export default function CommandKClient({ useEffect(() => { if (query === '') { setQueriedSections([]); + } else { + setIsLoading(true); } }, [query]); + useEffect(() => { + if (!open) { + setQuery(''); + setQueriedSections([]); + } + }, [open]); + const sectionTheme: CommandKSection = { heading: 'Theme', items: [{ - label: 'System', + label: 'Use System', action: () => setTheme('system'), }, { - label: 'Light', + label: 'Light Mode', action: () => setTheme('light'), }, { - label: 'Dark', + label: 'Dark Mode', action: () => setTheme('dark'), }], }; @@ -135,7 +145,7 @@ export default function CommandKClient({ '[&>*:first-child]:tracking-wider', )} > - {items.map(({ accessory, label, path, action }) => + {items.map(({ accessory, label, note, path, action }) => { - action?.(); setOpen(false); + action?.(); if (path) { router.push(path); } }} > -
+
{accessory} - {label} + + {label} + + {note && + + {note} + }
)} )} diff --git a/src/photo/PhotoTiny.tsx b/src/photo/PhotoTiny.tsx index 20e0a9f1..98eed075 100644 --- a/src/photo/PhotoTiny.tsx +++ b/src/photo/PhotoTiny.tsx @@ -23,7 +23,7 @@ export default function PhotoTiny({ 'active:brightness-75', selected && 'brightness-50', 'min-w-[50px]', - 'rounded-sm overflow-hidden', + 'rounded-[0.15rem] overflow-hidden', 'border border-gray-200 dark:border-gray-800', )} > diff --git a/src/site/CommandK.tsx b/src/site/CommandK.tsx index 83307b1f..02383b1d 100644 --- a/src/site/CommandK.tsx +++ b/src/site/CommandK.tsx @@ -19,6 +19,7 @@ import { authCached } from '@/auth/cache'; import { getPhotos } from '@/services/vercel-postgres'; import { titleForPhoto } from '@/photo'; import PhotoTiny from '@/photo/PhotoTiny'; +import { formatDate } from '@/utility/date'; export default async function CommandK() { const [ @@ -99,6 +100,7 @@ export default async function CommandK() { items: photos.map(photo => ({ accessory: , label: titleForPhoto(photo), + note: formatDate(photo.takenAt), path: pathForPhoto(photo), })), }]