diff --git a/www/components/item.jsx b/www/components/item.jsx
new file mode 100644
index 0000000..0e07068
--- /dev/null
+++ b/www/components/item.jsx
@@ -0,0 +1,54 @@
+import { callAPI } from '../utils/api'
+import React from 'react'
+
+
+const Item = ({ id, text, done, refresh }) => {
+
+ const _done = (e) => callAPI(null, {
+ url: `/api/items/${id}`,
+ method: 'patch',
+ data: {
+ done: e.target.checked,
+ },
+ }).then(refresh)
+
+ const _delete = (e) => callAPI(null, {
+ url: `/api/items/${id}`,
+ method: 'delete',
+ }).then(refresh)
+
+ return
+
+
+
+
+ |
+ {text} |
+
+
+ |
+ {/* language=CSS */}
+
+
+}
+
+export default Item
\ No newline at end of file
diff --git a/www/pages/list.jsx b/www/pages/list.jsx
index 64895d9..ff7aef0 100644
--- a/www/pages/list.jsx
+++ b/www/pages/list.jsx
@@ -2,93 +2,36 @@ import React, { useEffect, useRef, useState } from 'react'
import { withAuthSync } from '../utils/auth'
import Layout from '../components/layout'
-import { callAPI } from '../utils/api'
+import { callAPI, useCallAPI } from '../utils/api'
+import Item from '../components/item'
-const Item = ({ id, text, done }) => {
-
- const handleDone = async (e) => {
- await callAPI(null, {
- url: `/api/items/${id}`,
- method: 'patch',
- data: {
- done: e.target.checked,
- },
- })
- window.location.reload()
- }
-
- const handleDelete = async (e) => {
- await callAPI(null, {
- url: `/api/items/${id}`,
- method: 'delete',
- })
- window.location.reload()
- }
-
- return
-
-
-
-
- |
- {text} |
-
-
- |
- {/* language=CSS */}
-
-
-}
-
-const List = ({ items }) => {
+const List = ({ fetched }) => {
const input = useRef(undefined)
const [text, setText] = useState('')
+ const [data, refresh] = useCallAPI({ url: `/api/items` })
useEffect(() => {
if (!input.current) return
input.current.focus()
}, [input])
- const submit = async () => {
- await callAPI(null, {
- url: `/api/items/`,
- method: 'post',
- data: { text },
- })
- window.location.reload()
- }
+ const _submit = () => callAPI(null, {
+ url: `/api/items/`,
+ method: 'post',
+ data: { text },
+ }).then(refresh)
- const deleteAll = async () => {
- await callAPI(null, {
- url: `/api/items/`,
- method: 'delete',
- })
- window.location.reload()
- }
+ const _clear = () => callAPI(null, {
+ url: `/api/items/`,
+ method: 'delete',
+ }).then(refresh)
+
+ const items = data || fetched
return
-