diff --git a/src/pages/Tracker/Tracker.jsx b/src/pages/Tracker/Tracker.jsx index cac0cac7..706b62fa 100644 --- a/src/pages/Tracker/Tracker.jsx +++ b/src/pages/Tracker/Tracker.jsx @@ -1,5 +1,11 @@ +import { getTheme } from "@table-library/react-table-library/baseline"; +import { CompactTable } from "@table-library/react-table-library/compact"; +import { usePagination } from "@table-library/react-table-library/pagination"; +import { useSort } from "@table-library/react-table-library/sort"; +import { useTheme } from "@table-library/react-table-library/theme"; import React, { useEffect, useState } from "react"; import { useDispatch, useSelector } from "react-redux"; +import { Link } from "react-router-dom"; import { getProjects, @@ -9,7 +15,8 @@ import { setToggleTab } from "@redux/projectsTrackerSlice"; -import { caseOfNum } from "@utils/helper"; +import { getCorrectDate } from "@utils/calendarHelper"; +import { caseOfNum, urlForLocal } from "@utils/helper"; import { apiRequest } from "@api/request"; @@ -26,9 +33,10 @@ import ProjectTicket from "@components/ProjectTicket/ProjectTicket"; import addProjectImg from "assets/icons/addProjectImg.svg"; import archiveTrackerProjects from "assets/icons/archiveTrackerProjects.svg"; +import rightArrow from "assets/icons/arrows/arrowRight.svg"; import arrowViewReport from "assets/icons/arrows/arrowViewReport.svg"; import filterIcon from "assets/icons/filterIcon.svg"; -import search from "assets/icons/serchIcon.png"; +import searchImg from "assets/icons/serchIcon.png"; import project from "assets/icons/trackerProject.svg"; import tasks from "assets/icons/trackerTasks.svg"; import archive from "assets/images/archiveIcon.png"; @@ -43,15 +51,110 @@ export const Tracker = () => { const dispatch = useDispatch(); const projects = useSelector(getProjects); const tab = useSelector(getToggleTab); + const theme = useTheme(getTheme()); + const [nodes, setNodes] = useState([]); + const [initialNodes, setInitialNodes] = useState([]); const [allTasks, setAllTasks] = useState([]); const [filteredAllTasks, setFilteredAllTasks] = useState([]); const [loader, setLoader] = useState(false); const [filterCompleteTasks, setFilterCompleteTasks] = useState([]); const [allCompletedTasks, setAllCompletedTasks] = useState([]); + const [search, setSearch] = useState(""); const [modalCreateProject, setModalCreateProject] = useState(false); + const COLUMNS = [ + { + label: "Задача", + renderCell: (item) => ( +
+ ), + sort: { sortKey: "NAME" } + }, + { + label: "Создано", + renderCell: (item) => {getCorrectDate(item.created_at)}, + sort: { sortKey: "CREATE" } + }, + { + label: "Дедлайн", + renderCell: (item) => ( + + {item.dead_line ? getCorrectDate(item.dead_line) : "Без дедлайна"} + + ), + sort: { sortKey: "DEADLINE" } + }, + { + label: "Потраченное время", + renderCell: (item) => ( + + {item.timers.length + ? getSpendTime(item.timers) + : "Трекер не был включен"} + + ), + sort: { sortKey: "SPEND" } + } + ]; + + let data = { nodes }; + + const sort = useSort( + data, + { + onChange: onSortChange + }, + { + sortFns: { + NAME: (array) => array.sort((a, b) => a.title.localeCompare(b.title)), + CREATE: (array) => + array.sort((a, b) => new Date(a.created_at) - new Date(b.created_at)), + DEADLINE: (array) => + array.sort((a, b) => new Date(a.dead_line) - new Date(b.dead_line)), + SPEND: (array) => + array.sort( + (a, b) => + getSpendTime(a.timers, true) - getSpendTime(b.timers, true) + ) + } + } + ); + + const pagination = usePagination(data, { + state: { + page: 0, + size: 11 + } + }); + + function getSpendTime(times, seconds) { + let timerSeconds = 0; + times.forEach((time) => { + timerSeconds += time.deltaSeconds; + }); + if (seconds) { + return timerSeconds; + } + return `${Math.floor(timerSeconds / 60 / 60)}:${Math.floor( + (timerSeconds / 60) % 60 + )}:${timerSeconds % 60}`; + } + + function onSortChange(action, state) { + console.log(action, state); + } + + const handleSearch = (event) => { + setSearch(event.target.value); + setNodes( + initialNodes.filter((item) => + item.title.toLowerCase().includes(event.target.value.toLowerCase()) + ) + ); + }; + useEffect(() => { setLoader(true); apiRequest( @@ -84,6 +187,8 @@ export const Tracker = () => { : []; setAllTasks(allTasks); setFilteredAllTasks(allTasks); + setNodes(allTasks); + setInitialNodes(allTasks); setAllCompletedTasks(completedTasks); setFilterCompleteTasks(completedTasks); }) @@ -246,53 +351,122 @@ export const Tracker = () => { : "tracker__tabs__content__projects" } > -- {25} - {35} -
-*/} + {/* {25} - {35}*/} + {/*
*/} + {/*Фильтр
*/} + {/*Очистить фильтр
*/} + {/*Фильтр
-Очистить фильтр
-