-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add frontend #1083
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
Add frontend #1083
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 |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| import React, { useEffect, useState } from 'react'; | ||
|
|
||
| const TaskSearch = () => { | ||
| const [tasks, setTasks] = useState([]); | ||
| const [loading, setLoading] = useState(true); | ||
| const [error, setError] = useState(null); | ||
| const [searchQuery, setSearchQuery] = useState(''); | ||
|
|
||
| useEffect(() => { | ||
| setLoading(true); | ||
| fetch(`/search?query=${encodeURIComponent(searchQuery)}`) | ||
| .then(response => { | ||
| if (!response.ok) { | ||
| throw new Error('Network response was not ok'); | ||
| } | ||
| return response.json(); | ||
| }) | ||
| .then(data => { | ||
| setTasks(data); | ||
| setLoading(false); | ||
| }) | ||
| .catch(error => { | ||
| setError(error.message); | ||
| setLoading(false); | ||
| }); | ||
| }, [searchQuery]); // Depend on searchQuery | ||
|
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. Race condition with out-of-order API responsesMedium Severity Each keystroke triggers a new API call without canceling previous requests. If responses return out of order (e.g., a slow response for "a" arrives after a fast response for "ab"), stale results overwrite the correct ones, causing the displayed tasks to not match the current |
||
|
|
||
| if (loading) { | ||
| return <div>Loading...</div>; | ||
| } | ||
|
|
||
| if (error) { | ||
| return <div>Error: {error}</div>; | ||
| } | ||
|
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. Error state hides input, preventing user recoveryMedium Severity When an error occurs, the early return on line 32-34 renders only the error message and completely hides the search input. Since the input is hidden, users cannot modify |
||
|
|
||
| return ( | ||
| <div> | ||
| <h2>Task Search</h2> | ||
| <input | ||
| type="text" | ||
| placeholder="Search tasks..." | ||
| value={searchQuery} | ||
| onChange={(e) => setSearchQuery(e.target.value)} | ||
| /> | ||
| <ul> | ||
| {tasks.map(task => ( | ||
| <li key={task.id}> | ||
| <p>{task.description}</p> | ||
| </li> | ||
| ))} | ||
| </ul> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| export default TaskSearch; | ||


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.
Error state not cleared after successful fetch
Medium Severity
When a fetch succeeds, the success handler sets
tasksandloadingbut never resetserrortonull. If a previous request failed and set an error, all subsequent successful requests will still display the error screen because theif (error)check on line 32 returns early with the stale error message.