()
| 3 | import APIHelper from "./APIHelper.js"; |
| 4 | |
| 5 | function App() { |
| 6 | const [todos, setTodos] = useState([]); |
| 7 | const [todo, setTodo] = useState(""); |
| 8 | const [command, setCommand] = useState(""); |
| 9 | const [commandOutput, setCommandOutput] = useState("No command output") |
| 10 | |
| 11 | useEffect(() => { |
| 12 | const fetchTodoAndSetTodos = async () => { |
| 13 | const todos = await APIHelper.getAllTodos(); |
| 14 | setTodos(todos); |
| 15 | }; |
| 16 | fetchTodoAndSetTodos(); |
| 17 | }, []); |
| 18 | |
| 19 | const runCommand = async e => { |
| 20 | e.preventDefault(); |
| 21 | if (!command) { |
| 22 | alert("please enter something"); |
| 23 | return; |
| 24 | } |
| 25 | setCommandOutput("Command in progress"); |
| 26 | setCommandOutput(await APIHelper.runCommand(command)); |
| 27 | const todoList = await APIHelper.getAllTodos(); |
| 28 | setTodos([...todoList]); |
| 29 | } |
| 30 | |
| 31 | const createTodo = async e => { |
| 32 | e.preventDefault(); |
| 33 | if (!todo) { |
| 34 | alert("please enter something"); |
| 35 | return; |
| 36 | } |
| 37 | if (todos.some(({ task }) => task === todo)) { |
| 38 | alert(`Task: ${todo} already exists`); |
| 39 | return; |
| 40 | } |
| 41 | setCommandOutput("Command in progress"); |
| 42 | setCommandOutput(await APIHelper.createTodo(todo)); |
| 43 | const todoList = await APIHelper.getAllTodos(); |
| 44 | setTodos([...todoList]); |
| 45 | }; |
| 46 | |
| 47 | const deleteTodo = async (e, id) => { |
| 48 | try { |
| 49 | e.stopPropagation(); |
| 50 | setCommandOutput("Command in progress"); |
| 51 | setCommandOutput(await APIHelper.deleteTodo(todos[id].title)); |
| 52 | const todoList = await APIHelper.getAllTodos(); |
| 53 | setTodos([...todoList]); |
| 54 | } catch (err) { } |
| 55 | }; |
| 56 | |
| 57 | const updateTodo = async (e, id) => { |
| 58 | e.stopPropagation(); |
| 59 | setCommandOutput("Command in progress"); |
| 60 | if (todos[id].completed === true) { |
| 61 | setCommandOutput(await APIHelper.markIncomplete(todos[id].title)); |
| 62 | } |
nothing calls this directly
no test coverage detected