Skip to content

Commit 02a1f1b

Browse files
committed
Init Timeline
1 parent 3bb1991 commit 02a1f1b

File tree

6 files changed

+72
-308
lines changed

6 files changed

+72
-308
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,6 @@
210210
"jest": "^27.0.6",
211211
"lint-staged": "^10.2.11",
212212
"mini-css-extract-plugin": "^1.3.1",
213-
"node-sass": "^5.0.0",
214213
"opencollective-postinstall": "^2.0.3",
215214
"prettier": "^2.0.5",
216215
"react-refresh": "^0.9.0",
@@ -248,6 +247,7 @@
248247
"moment": "2.29.1",
249248
"react": "^17.0.1",
250249
"react-dom": "^17.0.1",
250+
"react-google-charts": "4.0.0",
251251
"react-hook-media-query": "^1.0.5",
252252
"react-jss": "^10.6.0",
253253
"react-router-dom": "^5.2.0",

src/components/Header.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ function Header() {
2828
<HeaderLink>
2929
<Link to="/dashboard">Dashboard</Link>
3030
</HeaderLink>
31+
<HeaderLink>
32+
<Link to="/timeline">TL</Link>
33+
</HeaderLink>
3134
<span className={style.flex1}>{isBigScreen && <ProgressBar />}</span>
3235
<TaskControl />
3336
<Profile />

src/screens/Main.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import { Layout } from 'antd';
44

55
import ProjectsScreen from './projects/ProjectsScreen';
66
import HoursScreen from './hours/HoursScreen';
7-
import Dashboard from './dashboard/Dashboard';
7+
import DashboardScreen from './dashboard/Dashboard';
8+
import TimelineScreen from './timeline/TimelineScreen';
89
import GaService from '../services/gaService/GaService';
910
import Header from '../components/Header';
1011

@@ -25,7 +26,8 @@ const Main = () => {
2526
<Switch>
2627
<Route path="/hours" component={HoursScreen} />
2728
<Route path="/projects" component={ProjectsScreen} />
28-
<Route path="/dashboard" component={Dashboard} />
29+
<Route path="/dashboard" component={DashboardScreen} />
30+
<Route path="/timeline" component={TimelineScreen} />
2931
<Redirect from="*" to="/projects" />
3032
</Switch>
3133
</Layout>

src/screens/hours/HoursScreen.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React, { useMemo, useState } from 'react';
22
import { Layout, Space } from 'antd';
33
import { observer } from 'mobx-react';
4+
import { createUseStyles } from 'react-jss';
45

56
import rootStore from '../../modules/RootStore';
67
import HoursCard from './components/HoursCard/HoursCard';
@@ -10,7 +11,6 @@ import TimeRangeModal from '../../components/TimeRangeModal/TimeRangeModal';
1011
import TaskTimeItemModel from '../../modules/tasks/models/TaskTimeItemModel';
1112
import { Undefined } from '../../types/CommonTypes';
1213
import TotalHours from './components/TotalHours/TotalHours';
13-
import { createUseStyles } from 'react-jss';
1414
import { mapCurrentNext } from '../../helpers/ArrayHelper';
1515
import { ITimeRangeModel } from '../../modules/tasks/models/TaskModel';
1616
import { msToTime } from '../../helpers/DateTime';
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import React, { FC, memo, useMemo } from 'react';
2+
import { Chart } from 'react-google-charts';
3+
import { createUseStyles } from 'react-jss';
4+
5+
import rootStore from '../../modules/RootStore';
6+
import { getTimeItems } from '../../helpers/TaskHelper';
7+
8+
const { tasksStore } = rootStore;
9+
10+
const columns = [
11+
{ type: 'string', id: 'Task' },
12+
{ type: 'date', id: 'Start' },
13+
{ type: 'date', id: 'End' },
14+
];
15+
16+
const nowDate = new Date();
17+
18+
const Timeline: FC = () => {
19+
const classes = useStyles();
20+
21+
const tasks = useMemo(() => tasksStore.getTasksByDate(nowDate), []);
22+
const filteredTimeItems = useMemo(() => getTimeItems(tasks, nowDate), [
23+
tasks,
24+
]);
25+
26+
const data = useMemo(() => {
27+
const items = filteredTimeItems.map(({ task, time }) => [
28+
task.title,
29+
time.start,
30+
time.end || new Date(),
31+
]);
32+
return [columns, ...items];
33+
}, [filteredTimeItems]);
34+
35+
return (
36+
<div className={classes.main}>
37+
<Chart chartType="Timeline" data={data} height="100%" />;
38+
</div>
39+
);
40+
};
41+
42+
export default memo(Timeline);
43+
44+
const useStyles = createUseStyles({
45+
main: {
46+
padding: 10,
47+
},
48+
});

0 commit comments

Comments
 (0)