From c896691084bfc786dc1780ce36fd71e6f7ab9d60 Mon Sep 17 00:00:00 2001
From: Yuval Adam <_@yuv.al>
Date: Fri, 27 Jun 2025 10:41:40 +0200
Subject: Migrate from react to svelte
---
src/components/Counter.jsx | 16 ---
src/components/SimpleTest.tsx | 32 ------
src/components/TaskManager.svelte | 183 ++++++++++++++++++++++++++++++++++
src/components/TaskManager.tsx | 202 --------------------------------------
4 files changed, 183 insertions(+), 250 deletions(-)
delete mode 100644 src/components/Counter.jsx
delete mode 100644 src/components/SimpleTest.tsx
create mode 100644 src/components/TaskManager.svelte
delete mode 100644 src/components/TaskManager.tsx
(limited to 'src/components')
diff --git a/src/components/Counter.jsx b/src/components/Counter.jsx
deleted file mode 100644
index 8661dc0..0000000
--- a/src/components/Counter.jsx
+++ /dev/null
@@ -1,16 +0,0 @@
-import { useState } from 'react';
-
-export default function Counter() {
- const [count, setCount] = useState(0);
-
- return (
-
-
-
- );
-}
diff --git a/src/components/SimpleTest.tsx b/src/components/SimpleTest.tsx
deleted file mode 100644
index cfabeab..0000000
--- a/src/components/SimpleTest.tsx
+++ /dev/null
@@ -1,32 +0,0 @@
-import { useState } from 'react';
-
-export default function SimpleTest() {
- const [count, setCount] = useState(0);
-
- return (
-
-
Simple Test Component
-
-
This is a simple React component to test if the infinite refresh is caused by the API calls.
-
-
- {count}
-
-
-
- If this component works without refreshing, the issue is in the TaskManager API calls.
-
-
-
- );
-}
\ No newline at end of file
diff --git a/src/components/TaskManager.svelte b/src/components/TaskManager.svelte
new file mode 100644
index 0000000..735a488
--- /dev/null
+++ b/src/components/TaskManager.svelte
@@ -0,0 +1,183 @@
+
+
+{#if loading}
+
+
Task Manager
+
Loading tasks...
+
+{:else if error}
+
+
Task Manager
+
+
Error: {error}
+
+
+
+{:else}
+
+
Task Manager
+
+
+
+
+ {#if tasks.length === 0}
+
No tasks yet. Create your first task above!
+ {:else}
+ {#each tasks as task (task.id)}
+
+
+
+
+ {task.title}
+
+ {#if task.description}
+
+ {task.description}
+
+ {/if}
+ {#if task.created_at}
+
+ Created: {new Date(task.created_at).toLocaleString()}
+
+ {/if}
+
+
+
+
+
+
+
+ {/each}
+ {/if}
+
+
+{/if}
\ No newline at end of file
diff --git a/src/components/TaskManager.tsx b/src/components/TaskManager.tsx
deleted file mode 100644
index a10a5f9..0000000
--- a/src/components/TaskManager.tsx
+++ /dev/null
@@ -1,202 +0,0 @@
-import { useState, useEffect, useCallback } from 'react';
-
-interface Task {
- id: number;
- title: string;
- description: string;
- completed: boolean;
- created_at?: string;
- updated_at?: string;
-}
-
-export default function TaskManager() {
- const [tasks, setTasks] = useState([]);
- const [newTask, setNewTask] = useState({ title: '', description: '' });
- const [loading, setLoading] = useState(true);
- const [error, setError] = useState(null);
-
- const fetchTasks = useCallback(async () => {
- try {
- setError(null);
- const response = await fetch('/api/tasks');
-
- if (!response.ok) {
- throw new Error(`HTTP error! status: ${response.status}`);
- }
-
- const data = await response.json();
- console.log('Fetched tasks:', data);
- setTasks(Array.isArray(data) ? data : []);
- } catch (error) {
- console.error('Failed to fetch tasks:', error);
- setError(error instanceof Error ? error.message : 'Failed to fetch tasks');
- setTasks([]);
- } finally {
- setLoading(false);
- }
- }, []);
-
- useEffect(() => {
- fetchTasks();
- }, [fetchTasks]);
-
- const createTask = async (e: React.FormEvent) => {
- e.preventDefault();
- if (!newTask.title.trim()) return;
-
- try {
- const response = await fetch('/api/tasks', {
- method: 'POST',
- headers: { 'Content-Type': 'application/json' },
- body: JSON.stringify(newTask)
- });
-
- if (response.ok) {
- setNewTask({ title: '', description: '' });
- fetchTasks();
- }
- } catch (error) {
- console.error('Failed to create task:', error);
- }
- };
-
- const toggleTask = async (task: Task) => {
- try {
- await fetch(`/api/tasks/${task.id}`, {
- method: 'PUT',
- headers: { 'Content-Type': 'application/json' },
- body: JSON.stringify({ ...task, completed: !task.completed })
- });
- fetchTasks();
- } catch (error) {
- console.error('Failed to update task:', error);
- }
- };
-
- const deleteTask = async (id: number) => {
- try {
- await fetch(`/api/tasks/${id}`, { method: 'DELETE' });
- fetchTasks();
- } catch (error) {
- console.error('Failed to delete task:', error);
- }
- };
-
- if (loading) {
- return (
-
-
Task Manager
-
Loading tasks...
-
- );
- }
-
- if (error) {
- return (
-
-
Task Manager
-
-
Error: {error}
-
-
-
- );
- }
-
- return (
-
-
Task Manager
-
-
-
-
- {tasks.length === 0 ? (
-
No tasks yet. Create your first task above!
- ) : (
- tasks.map((task) => (
-
-
-
-
- {task.title}
-
- {task.description && (
-
- {task.description}
-
- )}
- {task.created_at && (
-
- Created: {new Date(task.created_at).toLocaleString()}
-
- )}
-
-
-
-
-
-
-
- ))
- )}
-
-
- );
-}
\ No newline at end of file
--
cgit v1.3.1