Вроде работает
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
<script>
|
||||
import { onMount, onDestroy } from 'svelte';
|
||||
import { selectedTask } from '../lib/stores.js';
|
||||
import { api } from '../lib/api.js';
|
||||
|
||||
let tasks = [];
|
||||
let loading = true;
|
||||
@@ -21,11 +22,7 @@
|
||||
// @POST: tasks array is updated and selectedTask status synchronized.
|
||||
async function fetchTasks() {
|
||||
try {
|
||||
const token = localStorage.getItem('auth_token');
|
||||
const headers = token ? { 'Authorization': `Bearer ${token}` } : {};
|
||||
const res = await fetch('/api/tasks?limit=10', { headers });
|
||||
if (!res.ok) throw new Error('Failed to fetch tasks');
|
||||
tasks = await res.json();
|
||||
tasks = await api.fetchApi('/tasks?limit=10');
|
||||
|
||||
// [DEBUG] Check for tasks requiring attention
|
||||
tasks.forEach(t => {
|
||||
@@ -56,15 +53,10 @@
|
||||
async function clearTasks(status = null) {
|
||||
if (!confirm('Are you sure you want to clear tasks?')) return;
|
||||
try {
|
||||
let url = '/api/tasks';
|
||||
const params = new URLSearchParams();
|
||||
if (status) params.append('status', status);
|
||||
|
||||
const token = localStorage.getItem('auth_token');
|
||||
const headers = token ? { 'Authorization': `Bearer ${token}` } : {};
|
||||
const res = await fetch(`${url}?${params.toString()}`, { method: 'DELETE', headers });
|
||||
if (!res.ok) throw new Error('Failed to clear tasks');
|
||||
let endpoint = '/tasks';
|
||||
if (status) endpoint += `?status=${status}`;
|
||||
|
||||
await api.requestApi(endpoint, 'DELETE');
|
||||
await fetchTasks();
|
||||
} catch (e) {
|
||||
error = e.message;
|
||||
@@ -79,16 +71,8 @@
|
||||
async function selectTask(task) {
|
||||
try {
|
||||
// Fetch the full task details (including logs) before setting it as selected
|
||||
const token = localStorage.getItem('auth_token');
|
||||
const headers = token ? { 'Authorization': `Bearer ${token}` } : {};
|
||||
const res = await fetch(`/api/tasks/${task.id}`, { headers });
|
||||
if (res.ok) {
|
||||
const fullTask = await res.json();
|
||||
selectedTask.set(fullTask);
|
||||
} else {
|
||||
// Fallback to the list version if fetch fails
|
||||
selectedTask.set(task);
|
||||
}
|
||||
const fullTask = await api.getTask(task.id);
|
||||
selectedTask.set(fullTask);
|
||||
} catch (e) {
|
||||
console.error("Failed to fetch full task details:", e);
|
||||
selectedTask.set(task);
|
||||
|
||||
Reference in New Issue
Block a user