Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(nx-dev): when feedback button is pressed hide buttons #18141

Merged
merged 1 commit into from
Aug 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 47 additions & 34 deletions nx-dev/feature-ai/src/lib/feature-ai.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ export function FeatureAi(): JSX.Element {
const [error, setError] = useState(null);
const [query, setSearchTerm] = useState('');
const [loading, setLoading] = useState(false);
const [feedbackSent, setFeedbackSent] = useState<boolean>(false);

const warning = `
{% callout type="warning" title="Always double check!" %}
This feature is still in Alpha.
The results may not be accurate, so please always double check with our documentation.
{% /callout %}

`;

const handleSubmit = async () => {
Expand All @@ -33,11 +33,24 @@ export function FeatureAi(): JSX.Element {
setLoading(false);
}
sendCustomEvent('ai_query', 'ai', 'query', undefined, { query, ...usage });
setFeedbackSent(false);
setFinalResult(
renderMarkdown(warning + completeText, { filePath: '' }).node
);
};

const handleFeedback = (type: 'good' | 'bad') => {
try {
sendCustomEvent('ai_feedback', 'ai', type, undefined, {
query,
result: finalResult,
});
setFeedbackSent(true);
} catch (error) {
setFeedbackSent(false);
}
};

return (
<div
className="p-2 mx-auto flex h-full w-full flex-col"
Expand Down Expand Up @@ -73,43 +86,43 @@ export function FeatureAi(): JSX.Element {
<h1>Thinking...</h1>
</div>
) : null}
{finalResult && !error ? (
{finalResult && !loading && !error ? (
<>
<div className="p-4 max-w-none prose prose-slate dark:prose-invert">
{finalResult}
</div>
<div>
<Button
variant="primary"
size="small"
onClick={() =>
sendCustomEvent('ai_feedback', 'ai', 'good', undefined, {
query,
result: finalResult,
})
}
>
Answer was helpful{' '}
<span role="img" aria-label="thumbs-up">
👍
</span>
</Button>
<Button
variant="primary"
size="small"
onClick={() =>
sendCustomEvent('ai_feedback', 'ai', 'bad', undefined, {
query,
result: finalResult,
})
}
>
Answer looks wrong{' '}
<span role="img" aria-label="thumbs-down">
👎
</span>
</Button>
</div>
{!feedbackSent && (
<div>
<Button
variant="primary"
size="small"
onClick={() => handleFeedback('good')}
>
Answer was helpful{' '}
<span role="img" aria-label="thumbs-up">
👍
</span>
</Button>
<Button
variant="primary"
size="small"
onClick={() => handleFeedback('bad')}
>
Answer looks wrong{' '}
<span role="img" aria-label="thumbs-down">
👎
</span>
</Button>
</div>
)}
{feedbackSent && (
<p>
<span role="img" aria-label="check">
</span>{' '}
Thank you for your feedback!
</p>
mandarini marked this conversation as resolved.
Show resolved Hide resolved
)}
</>
) : null}
{error ? <div>There was an error: {error['message']}</div> : null}
Expand Down