import React, { useState } from 'react' import { Link } from "react-router-dom" import { useQuery } from '@wasp/queries' import getTasks from '@wasp/queries/getTasks.js' import createTask from '@wasp/actions/createTask.js' import updateTaskIsDone from '@wasp/actions/updateTaskIsDone.js' import deleteCompletedTasks from '@wasp/actions/deleteCompletedTasks.js' import toggleAllTasks from '@wasp/actions/toggleAllTasks.js' const Todo = (props) => { const defaultNewTaskDescription = '' const [newTaskDescription, setNewTaskDescription] = useState(defaultNewTaskDescription) const { data: tasks, isError, error: tasksError } = useQuery(getTasks) const isAnyTaskCompleted = () => tasks?.some(t => t.isDone) const isThereAnyTask = () => tasks?.length > 0 const createNewTask = async (description) => { const task = { isDone: false, description } await createTask(task) } const handleNewTaskSubmit = async (event) => { event.preventDefault() try { await createNewTask(newTaskDescription) setNewTaskDescription(defaultNewTaskDescription) } catch (err) { console.log(err) window.alert('Error:' + err.message) } } const Tasks = (props) => { return