Skip to content

Commit 48211f8

Browse files
author
claudfuen
committed
refactor: simplify TodoApp component by removing loading state and refetch functionality
- Eliminated the loading state and associated refetchTodos function to streamline the component. - Updated the rendering logic to directly display the todo list without loading indicators. - Cleaned up the component for improved readability and maintainability.
1 parent 19ec011 commit 48211f8

File tree

1 file changed

+1
-26
lines changed

1 file changed

+1
-26
lines changed

apps/web/src/app/components/TodoApp.tsx

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,8 @@ type TodoAppProps = {
1111
export default function TodoApp({ initialTodos }: TodoAppProps) {
1212
const [todos, setTodos] = useState<Todo[]>(initialTodos);
1313
const [newTodo, setNewTodo] = useState("");
14-
const [loading, setLoading] = useState(false);
1514
const [error, setError] = useState<string | null>(null);
1615

17-
// Refetch todos (mainly for after mutations if needed)
18-
const refetchTodos = async () => {
19-
try {
20-
setLoading(true);
21-
const updatedTodos = await todosApi.getTodos();
22-
setTodos(updatedTodos);
23-
setError(null);
24-
} catch (err) {
25-
setError(err instanceof Error ? err.message : "Failed to load todos");
26-
console.error(err);
27-
} finally {
28-
setLoading(false);
29-
}
30-
};
31-
3216
const addTodo = async (e: React.FormEvent) => {
3317
e.preventDefault();
3418
if (!newTodo.trim()) return;
@@ -109,9 +93,7 @@ export default function TodoApp({ initialTodos }: TodoAppProps) {
10993
</form>
11094

11195
{/* Todo List */}
112-
{loading ? (
113-
<div className="text-center py-8">Loading todos...</div>
114-
) : todos.length === 0 ? (
96+
{todos.length === 0 ? (
11597
<div className="text-center py-8 text-gray-500">
11698
No todos yet. Add one above!
11799
</div>
@@ -159,13 +141,6 @@ export default function TodoApp({ initialTodos }: TodoAppProps) {
159141
<h3 className="font-semibold mb-2">Debug Info:</h3>
160142
<p className="text-sm">Initial todos loaded: {initialTodos.length}</p>
161143
<p className="text-sm">Current todos count: {todos.length}</p>
162-
<button
163-
onClick={refetchTodos}
164-
className="mt-2 px-4 py-2 bg-blue-500 text-white rounded-lg
165-
hover:bg-blue-600 transition-colors text-sm"
166-
>
167-
Refetch Todos
168-
</button>
169144
</div>
170145
</main>
171146
</div>

0 commit comments

Comments
 (0)