Split app.js in to smaller chunks

This commit is contained in:
2025-01-30 18:18:29 +01:00
parent e74871bf94
commit 4a9139e4d8
7 changed files with 264 additions and 8 deletions

30
public/js/tasks.js Normal file
View File

@@ -0,0 +1,30 @@
import { idb } from './utils.js';
export async function saveTask(taskData) {
if (navigator.onLine) {
try {
const response = await fetch('/add-task', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(taskData)
});
return await response.json();
} catch (error) {
throw error;
}
} else {
try {
const db = await idb.openDB('org-todo-pwa', 1, {
upgrade(db) {
db.createObjectStore('tasks', { keyPath: 'id', autoIncrement: true });
}
});
await db.add('tasks', taskData);
return { message: "Task saved offline!" };
} catch (error) {
throw error;
}
}
}