From df1c134c5b2056e5f82c494bb78059a5be84f142 Mon Sep 17 00:00:00 2001 From: Sam Becker Date: Fri, 26 Apr 2024 21:01:20 -0500 Subject: [PATCH] Stop returning components from photo actions --- src/components/CommandKClient.tsx | 23 +++++++++++++++++--- src/photo/{actions.tsx => actions.ts} | 31 +++++---------------------- 2 files changed, 25 insertions(+), 29 deletions(-) rename src/photo/{actions.tsx => actions.ts} (88%) diff --git a/src/components/CommandKClient.tsx b/src/components/CommandKClient.tsx index a7fee955..5286062a 100644 --- a/src/components/CommandKClient.tsx +++ b/src/components/CommandKClient.tsx @@ -16,6 +16,7 @@ import { PATH_ADMIN_TAGS, PATH_ADMIN_UPLOADS, PATH_SIGN_IN, + pathForPhoto, } from '../site/paths'; import Modal from './Modal'; import { clsx } from 'clsx/lite'; @@ -26,11 +27,15 @@ import { useTheme } from 'next-themes'; import { BiDesktop, BiMoon, BiSun } from 'react-icons/bi'; import { IoInvertModeSharp } from 'react-icons/io5'; import { useAppState } from '@/state/AppState'; -import { getPhotoItemsAction } from '@/photo/actions'; +import { queryPhotosByTitleAction } from '@/photo/actions'; import { RiToolsFill } from 'react-icons/ri'; import { BiLockAlt, BiSolidUser } from 'react-icons/bi'; import { HiDocumentText } from 'react-icons/hi'; import { signOutAndRedirectAction } from '@/auth/actions'; +import { TbPhoto } from 'react-icons/tb'; +import { getKeywordsForPhoto, titleForPhoto } from '@/photo'; +import PhotoDate from '@/photo/PhotoDate'; +import PhotoTiny from '@/photo/PhotoTiny'; const LISTENER_KEYDOWN = 'keydown'; const MINIMUM_QUERY_LENGTH = 2; @@ -118,9 +123,21 @@ export default function CommandKClient({ useEffect(() => { if (queryDebounced.length >= MINIMUM_QUERY_LENGTH && !isPending) { setIsLoading(true); - getPhotoItemsAction(queryDebounced).then(querySections => { + queryPhotosByTitleAction(queryDebounced).then(photos => { if (isOpenRef.current) { - setQueriedSections(querySections); + setQueriedSections(photos.length > 0 + ? [{ + heading: 'Photos', + accessory: , + items: photos.map(photo => ({ + label: titleForPhoto(photo), + keywords: getKeywordsForPhoto(photo), + annotation: , + accessory: , + path: pathForPhoto(photo), + })), + }] + : []); } else { // Ignore stale requests that come in after dialog is closed setQueriedSections([]); diff --git a/src/photo/actions.tsx b/src/photo/actions.ts similarity index 88% rename from src/photo/actions.tsx rename to src/photo/actions.ts index cd4a24bb..b0c68911 100644 --- a/src/photo/actions.tsx +++ b/src/photo/actions.ts @@ -35,17 +35,10 @@ import { } from '@/site/paths'; import { extractExifDataFromBlobPath } from './server'; import { TAG_FAVS, isTagFavs } from '@/tag'; -import { TbPhoto } from 'react-icons/tb'; -import PhotoTiny from './PhotoTiny'; -import { - convertPhotoToPhotoDbInsert, - getKeywordsForPhoto, - titleForPhoto, -} from '.'; +import { convertPhotoToPhotoDbInsert } from '.'; import { safelyRunAdminServerAction } from '@/auth'; import { AI_IMAGE_QUERIES, AiImageQuery } from './ai'; import { streamOpenAiImageQuery } from '@/services/openai'; -import PhotoDate from './PhotoDate'; export async function createPhotoAction(formData: FormData) { return safelyRunAdminServerAction(async () => { @@ -202,23 +195,9 @@ export async function streamAiImageQueryAction( streamOpenAiImageQuery(imageBase64, AI_IMAGE_QUERIES[query])); } -export async function getPhotoItemsAction(query: string) { - const photos = (await getPhotos({ query, limit: 10 })) - .filter(({ title }) => Boolean(title)); - return photos.length > 0 - ? [{ - heading: 'Photos', - accessory: , - items: photos.map(photo => ({ - label: titleForPhoto(photo), - keywords: getKeywordsForPhoto(photo), - annotation: , - accessory: , - path: pathForPhoto(photo), - })), - }] - : []; -} - export const getPhotosAction = async (offset: number, limit: number) => getPhotosCachedCached({ offset, limit }); + +export const queryPhotosByTitleAction = async (query: string) => + (await getPhotos({ query, limit: 10 })) + .filter(({ title }) => Boolean(title));