Add AI error handling
This commit is contained in:
parent
4f8313f0de
commit
020c8aee06
@ -122,35 +122,43 @@ export default function PhotoForm({
|
|||||||
requestTitle,
|
requestTitle,
|
||||||
title,
|
title,
|
||||||
isLoadingTitle,
|
isLoadingTitle,
|
||||||
|
errorTitle,
|
||||||
] = useImageQuery(imageData, 'title');
|
] = useImageQuery(imageData, 'title');
|
||||||
|
|
||||||
const [
|
const [
|
||||||
requestTags,
|
requestTags,
|
||||||
tags,
|
tags,
|
||||||
isLoadingTags,
|
isLoadingTags,
|
||||||
|
errorTags,
|
||||||
] = useImageQuery(imageData, 'tags');
|
] = useImageQuery(imageData, 'tags');
|
||||||
|
|
||||||
const [
|
const [
|
||||||
requestDescriptionSmall,
|
requestDescriptionSmall,
|
||||||
descriptionSmall,
|
descriptionSmall,
|
||||||
isLoadingDescriptionSmall,
|
isLoadingDescriptionSmall,
|
||||||
|
errorDescriptionSmall,
|
||||||
] = useImageQuery(imageData, 'descriptionSmall');
|
] = useImageQuery(imageData, 'descriptionSmall');
|
||||||
|
|
||||||
const [
|
const [
|
||||||
requestDescriptionLarge,
|
requestDescriptionLarge,
|
||||||
descriptionLarge,
|
descriptionLarge,
|
||||||
isLoadingDescriptionLarge,
|
isLoadingDescriptionLarge,
|
||||||
|
errorDescriptionLarge,
|
||||||
] = useImageQuery(imageData, 'descriptionLarge');
|
] = useImageQuery(imageData, 'descriptionLarge');
|
||||||
|
|
||||||
const renderAiButton = (
|
const renderAiButton = (
|
||||||
label: string,
|
label: string,
|
||||||
onClick: () => void,
|
onClick: () => void,
|
||||||
isLoading: boolean,
|
isLoading: boolean,
|
||||||
|
error?: any,
|
||||||
) =>
|
) =>
|
||||||
<button
|
<button
|
||||||
onClick={onClick}
|
onClick={onClick}
|
||||||
disabled={!imageData || isLoading}
|
disabled={!imageData || isLoading}
|
||||||
className="disabled:opacity-50 text-sm px-2.5 min-h-0 py-1.5"
|
className={clsx(
|
||||||
|
'disabled:opacity-50 text-sm px-2.5 min-h-0 py-1.5',
|
||||||
|
Boolean(error) && 'error text-error',
|
||||||
|
)}
|
||||||
>
|
>
|
||||||
{label} ✨
|
{label} ✨
|
||||||
</button>;
|
</button>;
|
||||||
@ -158,17 +166,29 @@ export default function PhotoForm({
|
|||||||
return (
|
return (
|
||||||
<div className="space-y-8 max-w-[38rem]">
|
<div className="space-y-8 max-w-[38rem]">
|
||||||
<div className="flex gap-2 flex-wrap">
|
<div className="flex gap-2 flex-wrap">
|
||||||
{renderAiButton('Title', requestTitle, isLoadingTitle)}
|
{renderAiButton(
|
||||||
{renderAiButton('Tags', requestTags, isLoadingTags)}
|
'Title',
|
||||||
|
requestTitle,
|
||||||
|
isLoadingTitle,
|
||||||
|
errorTitle,
|
||||||
|
)}
|
||||||
|
{renderAiButton(
|
||||||
|
'Tags',
|
||||||
|
requestTags,
|
||||||
|
isLoadingTags,
|
||||||
|
errorTags,
|
||||||
|
)}
|
||||||
{renderAiButton(
|
{renderAiButton(
|
||||||
'Description (S)',
|
'Description (S)',
|
||||||
requestDescriptionSmall,
|
requestDescriptionSmall,
|
||||||
isLoadingDescriptionSmall,
|
isLoadingDescriptionSmall,
|
||||||
|
errorDescriptionSmall,
|
||||||
)}
|
)}
|
||||||
{renderAiButton(
|
{renderAiButton(
|
||||||
'Description (L)',
|
'Description (L)',
|
||||||
requestDescriptionLarge,
|
requestDescriptionLarge,
|
||||||
isLoadingDescriptionLarge,
|
isLoadingDescriptionLarge,
|
||||||
|
errorDescriptionLarge,
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
<div className="flex gap-2">
|
<div className="flex gap-2">
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user