Refactor task data management with composables and remove direct API calls from components
This commit is contained in:
@@ -1,25 +1,15 @@
|
||||
<script setup lang="ts">
|
||||
import { fetch } from '@tauri-apps/plugin-http';
|
||||
import { router } from '../router.ts';
|
||||
import { useTasks } from '../composables/useTasks.ts';
|
||||
import { Task } from '../types.ts';
|
||||
|
||||
const { createTask } = useTasks();
|
||||
|
||||
const handleSubmit = async(e: Event) => {
|
||||
const data = new FormData(e.target as HTMLFormElement);
|
||||
const task: Partial<Task> = Object.fromEntries(data)
|
||||
|
||||
const nextId = await fetch(
|
||||
'https://automation.deep-node.de/webhook/d49dde4c-530d-46ee-8205-d1357563ac16',
|
||||
{ method: 'GET', headers: { 'Content-Type': 'application/json', 'Authorization': 'Basic cGF1bDoxMG1hYmF1MTU=', }}
|
||||
).then((response) => response.json()).then((json) => json.nextId as number).catch(() => null);
|
||||
|
||||
if (!nextId) return;
|
||||
task.id_ = nextId;
|
||||
task.logs = [];
|
||||
|
||||
await fetch(
|
||||
'https://automation.deep-node.de/webhook/e5880167-9322-4d7b-8a38-e06bae8a7734/list',
|
||||
{ method: 'PUT', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ tasks: [task] } )}
|
||||
);
|
||||
await createTask(task);
|
||||
await router.push('/');
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -1,19 +1,16 @@
|
||||
<script setup lang="ts">
|
||||
import { fetch } from '@tauri-apps/plugin-http';
|
||||
import { computed, onMounted, ref } from 'vue';
|
||||
import { Task, TaskStatus } from '../types.ts';
|
||||
import { useTasks } from '../composables/useTasks.ts';
|
||||
import { TaskStatus } from '../types.ts';
|
||||
import { PhCaretDown, PhCaretUp, PhCheckSquare, PhDotsThree, PhPlay, PhSquare } from '@phosphor-icons/vue';
|
||||
|
||||
const rawTasks = ref<Task[]>([]);
|
||||
const { tasks, fetchTasks } = useTasks();
|
||||
|
||||
onMounted(async () => {
|
||||
rawTasks.value = await fetch('https://automation.deep-node.de/webhook/e5880167-9322-4d7b-8a38-e06bae8a7734/list', { method: 'GET', headers: { 'Content-Type': 'application/json'} })
|
||||
.then(response => response.json())
|
||||
.then((data: { tasks: Task[] }) => rawTasks.value = data.tasks ?? [])
|
||||
.catch(() => []);
|
||||
await fetchTasks();
|
||||
})
|
||||
|
||||
const visibleTasks = computed(() => rawTasks.value.filter(task => !task.archived))
|
||||
const visibleTasks = computed(() => tasks.value.filter(task => !task.archived))
|
||||
|
||||
const categorizedTasks = computed(() => visibleTasks.value.reduce((acc, task) => {
|
||||
const tag = task.tag ?? 'Uncategorized';
|
||||
|
||||
Reference in New Issue
Block a user