-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
feat: mount JokeForm to home route so add-joke form renders #8126
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
base: main
Are you sure you want to change the base?
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 | ||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -375,7 +375,7 @@ export function JokeForm() { | |||||||||||||||||||||||||||||||||||||||||||
| Now, let's wire the form up to our `addJoke` server function in the `handleSubmit` function. Calling a server action is simple! It's just a function call. | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| ```tsx | ||||||||||||||||||||||||||||||||||||||||||||
| //JokeForm.tsx | ||||||||||||||||||||||||||||||||||||||||||||
| // src/components/JokeForm.tsx | ||||||||||||||||||||||||||||||||||||||||||||
| import { useState } from 'react' | ||||||||||||||||||||||||||||||||||||||||||||
| import { useRouter } from '@tanstack/react-router' | ||||||||||||||||||||||||||||||||||||||||||||
| import { addJoke } from '../serverActions/jokesActions' | ||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -446,6 +446,42 @@ export function JokeForm() { | |||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| Import and render <JokeForm /> in the home route src/routes/index.tsx so the add-joke form becomes visible on the page. | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| ```tsx | ||||||||||||||||||||||||||||||||||||||||||||
| // src/components/JokesList.tsx | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| // src/components/JokesList.tsx | ||||||||||||||||||||||||||||||||||||||||||||
| import type { Joke } from '../types' | ||||||||||||||||||||||||||||||||||||||||||||
| import { JokeForm } from '@/components/JokeForm' | ||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+449
to
+456
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. 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win Align the instruction with the code sample. Line 449 names Proposed documentation fix-Import and render <JokeForm /> in the home route src/routes/index.tsx so the add-joke form becomes visible on the page.
+Import and render <JokeForm /> in src/components/JokesList.tsx so the add-joke form becomes visible on the page.
-// src/components/JokesList.tsx
-
// src/components/JokesList.tsx📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| interface JokesListProps { | ||||||||||||||||||||||||||||||||||||||||||||
| jokes: Joke[] | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| export function JokesList({ jokes }: JokesListProps) { | ||||||||||||||||||||||||||||||||||||||||||||
| if (!jokes || jokes.length === 0) { | ||||||||||||||||||||||||||||||||||||||||||||
| return <p className="text-gray-500 italic">No jokes found. Add some!</p> | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| return ( | ||||||||||||||||||||||||||||||||||||||||||||
| <div className="space-y-4"> | ||||||||||||||||||||||||||||||||||||||||||||
| <JokeForm /> | ||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+462
to
+469
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. 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win Render When Proposed fix if (!jokes || jokes.length === 0) {
- return <p className="text-gray-500 italic">No jokes found. Add some!</p>
+ return (
+ <>
+ <JokeForm />
+ <p className="text-gray-500 italic">No jokes found. Add some!</p>
+ </>
+ )
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||
| <h2 className="text-xl font-semibold">Jokes Collection</h2> | ||||||||||||||||||||||||||||||||||||||||||||
| {jokes.map((joke) => ( | ||||||||||||||||||||||||||||||||||||||||||||
| <div | ||||||||||||||||||||||||||||||||||||||||||||
| key={joke.id} | ||||||||||||||||||||||||||||||||||||||||||||
| className="bg-white p-4 rounded-lg shadow-md border border-gray-200" | ||||||||||||||||||||||||||||||||||||||||||||
| > | ||||||||||||||||||||||||||||||||||||||||||||
| <p className="font-bold text-lg mb-2">{joke.question}</p> | ||||||||||||||||||||||||||||||||||||||||||||
| <p className="text-gray-700">{joke.answer}</p> | ||||||||||||||||||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||||||||||||||||||
| ))} | ||||||||||||||||||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| With this, our UI should look like this: | ||||||||||||||||||||||||||||||||||||||||||||
|  | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.