TrainingsPlanner.jsx 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // components
  2. import Spring from '@components/Spring';
  3. import {NavLink} from 'react-router-dom';
  4. import SelectionButton from '@ui/SelectionButton';
  5. import ScrollContainer from '@components/ScrollContainer';
  6. import DnDLayout from '@components/Todos/DnDLayout';
  7. // hooks
  8. import {useState} from 'react';
  9. import useMeasure from 'react-use-measure';
  10. import {useSelector} from 'react-redux';
  11. import {useWindowSize} from 'react-use';
  12. // utils
  13. import dayjs from 'dayjs';
  14. const TrainingsPlanner = () => {
  15. const [selectedMonth, setSelectedMonth] = useState(dayjs().format('MMMM'));
  16. const [headerRef, {height: headerHeight}] = useMeasure();
  17. const todos = useSelector(state => state['todos'].todos);
  18. const currentTodos = todos.filter(todo => dayjs(todo.timestamp).format('MMMM') === selectedMonth);
  19. const isSmallScreen = useWindowSize().width < 414;
  20. return (
  21. <Spring className="card h-2">
  22. <div className="card_header d-flex flex-column g-20" ref={headerRef} style={{paddingBottom: 20}}>
  23. <div className="d-flex justify-content-between align-items-center">
  24. <h3>Trainings {!isSmallScreen && 'planner'}</h3>
  25. <NavLink className="text-button" to="/schedule">Scheduler</NavLink>
  26. </div>
  27. <div className="d-flex flex-wrap g-20">
  28. <SelectionButton type="group"
  29. text={dayjs().format('MMMM')}
  30. onClick={() => setSelectedMonth(dayjs().format('MMMM'))}
  31. active={selectedMonth === dayjs().format('MMMM')}/>
  32. <SelectionButton type="group"
  33. text={dayjs().add(1, 'month').format('MMMM')}
  34. onClick={() => setSelectedMonth(dayjs().add(1, 'month').format('MMMM'))}
  35. active={selectedMonth === dayjs().add(1, 'month').format('MMMM')}/>
  36. <SelectionButton type="group"
  37. text={dayjs().add(2, 'month').format('MMMM')}
  38. onClick={() => setSelectedMonth(dayjs().add(2, 'month').format('MMMM'))}
  39. active={selectedMonth === dayjs().add(2, 'month').format('MMMM')}/>
  40. </div>
  41. </div>
  42. <ScrollContainer height={headerHeight}>
  43. <div className="track d-flex flex-column g-20 card-padded" style={{paddingTop: 0}}>
  44. {currentTodos.length !== 0 ? <DnDLayout variant="planner" data={currentTodos}/> : null}
  45. </div>
  46. </ScrollContainer>
  47. </Spring>
  48. )
  49. }
  50. export default TrainingsPlanner