-
Notifications
You must be signed in to change notification settings - Fork 0
🎨 Palette: Improve "Random idea" button with loading state #72
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,6 +32,7 @@ export default function Generate() { | |
| const [mood, setMood] = useState<string>("Happy"); | ||
| const [generatedContent, setGeneratedContent] = useState(""); | ||
| const [isPublic, setIsPublic] = useState(false); | ||
| const [isRandomLoading, setIsRandomLoading] = useState(false); | ||
|
|
||
| const [aiEngine, setAiEngine] = useState<AIEngine>("openai"); | ||
| const [isGeneratingLocal, setIsGeneratingLocal] = useState(false); | ||
|
|
@@ -95,9 +96,14 @@ export default function Generate() { | |
| }; | ||
|
|
||
| const handleRandomPrompt = async () => { | ||
| const prompt = await getRandomPrompt(); | ||
| if (prompt) { | ||
| setTopic(prompt); | ||
| setIsRandomLoading(true); | ||
| try { | ||
| const prompt = await getRandomPrompt(); | ||
| if (prompt) { | ||
| setTopic(prompt); | ||
| } | ||
| } finally { | ||
| setIsRandomLoading(false); | ||
| } | ||
| }; | ||
|
|
||
|
|
@@ -211,15 +217,18 @@ export default function Generate() { | |
| <div className="space-y-2"> | ||
| <div className="flex items-center justify-between"> | ||
| <label className="text-sm font-medium" htmlFor="topic-input">Topic / Theme</label> | ||
| <button | ||
| <Button | ||
| type="button" | ||
| variant="ghost" | ||
| size="sm" | ||
| onClick={handleRandomPrompt} | ||
| className="text-xs text-primary hover:text-primary/80 flex items-center gap-1 transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary rounded-sm" | ||
| disabled={loading || isRandomLoading} | ||
| className="text-xs text-primary hover:text-primary/80 h-auto p-0 hover:bg-transparent" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The While this works, fighting the component's built-in styles can make maintenance harder. As a small cleanup, the |
||
| data-testid="button-random-prompt" | ||
| > | ||
| <Shuffle className="w-3 h-3" /> | ||
| {isRandomLoading ? <Loader2 className="w-3 h-3 animate-spin" /> : <Shuffle className="w-3 h-3" />} | ||
| Random idea | ||
| </button> | ||
| </Button> | ||
|
Comment on lines
+220
to
+231
|
||
| </div> | ||
| <div className="flex items-start gap-1"> | ||
| <textarea | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current implementation doesn't provide feedback to the user if
getRandomPrompt()fails. ThegetRandomPrompthook swallows errors and returnsnull, so the spinner will just disappear without any explanation, leading to a confusing user experience. We should inform the user that the action failed by showing a toast notification.