import React, { useState } from "react";
import { useSelector, useDispatch } from "react-redux";
import {
change_done,
remove_todo,
edit_todo,
set_sort_todo,
sort_todo,
select_todos,
select_current_sorting,
} from "../features/todo/reducer";
function sort_table_header(prefix, current_sorting) {
if (prefix.toLowerCase().startsWith(current_sorting.substr(0, 3))) {
switch (current_sorting.substr(-1)) {
case "^":
// Write Prefix and an arrow pointing up.
return (
<>
{prefix} ↑
>
);
case "v":
// Write Prefix and an arrow pointing down.
return (
<>
{prefix} ↓
>
);
}
} else {
// Write Prefix and four dots. No sorting.
return (
<>
{prefix} ⁛
>
);
}
}
function list_of_todos(edit_button, delete_button) {
const dispatch = useDispatch();
const my_todos = useSelector(select_todos);
const my_sorting = useSelector(select_current_sorting);
function handle_sort_todos(where_clicked) {
dispatch(
set_sort_todo({
where_clicked: where_clicked,
})
);
dispatch(sort_todo());
}
// Table contents
var table_head = (
);
var table_body = (
Done
Name
handle_sort_todos("priority")}>
{sort_table_header("Priority", my_sorting)}
{
handle_sort_todos("due_date");
}}
>
{sort_table_header("Due Date", my_sorting)}
Actions