obolus/www/components/item.jsx

48 lines
1.2 KiB
React
Raw Normal View History

2019-05-24 13:26:22 +00:00
import { callAPI } from '../utils/api'
import React from 'react'
const Item = ({ id, text, done, refresh }) => {
2019-05-24 13:52:20 +00:00
const _done = () => callAPI(null, {
2019-05-24 13:26:22 +00:00
url: `/api/items/${id}`,
method: 'patch',
data: {
2019-05-24 13:52:20 +00:00
done: !done,
2019-05-24 13:26:22 +00:00
},
}).then(refresh)
const _delete = (e) => callAPI(null, {
url: `/api/items/${id}`,
method: 'delete',
}).then(refresh)
2019-05-24 13:52:20 +00:00
return <tr className="item" onClick={_done}>
2019-05-24 13:26:22 +00:00
<td className="item-done">
<div className="form-group">
<label className="form-checkbox">
2019-05-24 13:52:20 +00:00
<input type="checkbox" checked={done} readOnly/>
2019-05-24 13:26:22 +00:00
<i className="form-icon"/>
</label>
</div>
</td>
<td>{text}</td>
<td className="item-menu">
2019-05-24 13:52:20 +00:00
<button className="btn btn-action btn-error" onClick={_delete}>
<i className="icon icon-delete"/>
</button>
2019-05-24 13:26:22 +00:00
</td>
{/* language=CSS */}
<style jsx>{`
2019-05-24 13:52:20 +00:00
.item-done {
2019-05-24 13:26:22 +00:00
width: 2em;
}
2019-05-24 13:52:20 +00:00
.item-menu {
width: 1em;
}
2019-05-24 13:26:22 +00:00
`}</style>
</tr>
}
export default Item