-
Notifications
You must be signed in to change notification settings - Fork 1
/
TodoList.tsx
71 lines (68 loc) · 1.94 KB
/
TodoList.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import type { FC } from 'react';
import { useAppSelector, useAppDispatch } from '../../../app/hooks';
import { remove, selectTodos } from '../todosSlice';
export const TodoList: FC = () => {
const todos = useAppSelector(selectTodos);
const dispatch = useAppDispatch();
return (
<>
<table border={1}>
<thead>
<tr>
<th>id</th>
<th>タイトル</th>
<th>本文</th>
<th>ステータス</th>
<th>作成日時</th>
<th>更新日時</th>
<th>削除日時</th>
<th>更新ボタン</th>
<th>削除ボタン</th>
</tr>
</thead>
<tbody>
{todos.length === 0 ? (
<tr>
<td colSpan={9} style={{ textAlign: 'center' }}>
データなし
</td>
</tr>
) : (
todos.map((todo) => {
return (
<tr key={todo.id}>
<td>{todo.id}</td>
<td>{todo.title}</td>
<td>{todo.body}</td>
<td>{todo.status}</td>
<td>{todo.createdAt}</td>
<td>{todo.updatedAt ?? '無し'}</td>
<td>{todo.deletedAt ?? '無し'}</td>
<td>
<button
onClick={() => {
//TODO: 更新機能の実装
}}
>
更新
</button>
</td>
<td>
<button
onClick={() => {
dispatch(remove(todo.id));
}}
>
削除
</button>
</td>
</tr>
);
})
)}
</tbody>
</table>
</>
);
};
export default TodoList;