Skip to content

Commit a901c6f

Browse files
author
Dmitry Yadrikhinsky
committed
[Timer] TaskControl view
1 parent 01d547e commit a901c6f

File tree

10 files changed

+111
-35
lines changed

10 files changed

+111
-35
lines changed

.erb/configs/webpack.config.renderer.dev.babel.js

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ const requiredByDLLConfig = module.parent.filename.includes(
2525
/**
2626
* Warn if the DLL is not built
2727
*/
28-
if (!requiredByDLLConfig && !(fs.existsSync(dllDir) && fs.existsSync(manifest))) {
28+
if (
29+
!requiredByDLLConfig &&
30+
!(fs.existsSync(dllDir) && fs.existsSync(manifest))
31+
) {
2932
console.log(
3033
chalk.black.bgYellow.bold(
3134
'The DLL files are missing. Sit back while we build them for you with "yarn build-dll"'
@@ -61,9 +64,7 @@ export default merge(baseConfig, {
6164
{
6265
loader: require.resolve('babel-loader'),
6366
options: {
64-
plugins: [
65-
require.resolve('react-refresh/babel'),
66-
].filter(Boolean),
67+
plugins: [require.resolve('react-refresh/babel')].filter(Boolean),
6768
},
6869
},
6970
],
@@ -152,6 +153,9 @@ export default merge(baseConfig, {
152153
loader: 'less-loader',
153154
options: {
154155
lessOptions: {
156+
modifyVars: {
157+
'primary-color': 'purple',
158+
},
155159
javascriptEnabled: true,
156160
},
157161
},
@@ -226,7 +230,6 @@ export default merge(baseConfig, {
226230
],
227231
},
228232
plugins: [
229-
230233
requiredByDLLConfig
231234
? null
232235
: new webpack.DllReferencePlugin({
@@ -287,13 +290,13 @@ export default merge(baseConfig, {
287290
},
288291
before() {
289292
console.log('Starting Main Process...');
290-
spawn('npm', ['run', 'start:main'], {
291-
shell: true,
292-
env: process.env,
293-
stdio: 'inherit',
294-
})
295-
.on('close', (code) => process.exit(code))
296-
.on('error', (spawnError) => console.error(spawnError));
293+
spawn('npm', ['run', 'start:main'], {
294+
shell: true,
295+
env: process.env,
296+
stdio: 'inherit',
297+
})
298+
.on('close', (code) => process.exit(code))
299+
.on('error', (spawnError) => console.error(spawnError));
297300
},
298301
},
299302
});
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.circle-button {
2+
display: inline-flex;
3+
align-items: center;
4+
justify-content: center;
5+
height: 28px;
6+
width: 28px;
7+
border-radius: 14px;
8+
cursor: pointer;
9+
background-color: black;
10+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import React from 'react';
2+
3+
import './CircleButton.less';
4+
5+
export default function CircleButton({ children, onClick }) {
6+
return (
7+
<span className="circle-button" onClick={onClick}>
8+
{children}
9+
</span>
10+
);
11+
}

src/components/HeaderMenu.less

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.header-menu {
2+
padding: 0 20px;
3+
}
4+
5+
.header-menu a {
6+
color: white;
7+
}

src/components/HeaderMenu.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import React from 'react';
2+
3+
import './HeaderMenu.less';
4+
5+
export default function HeaderMenu({ children }) {
6+
return <span className="header-menu">{children}</span>;
7+
}

src/helpers/DateTime.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@ function timePad(time: number): string {
22
return String(time).padStart(2, '0');
33
}
44

5-
export function msToTime(s: number) {
5+
export function msToTime(s: number, showSeconds: boolean = true) {
66
const ms = s % 1000;
77
s = (s - ms) / 1000;
88
const secs = s % 60;
99
s = (s - secs) / 60;
1010
const mins = s % 60;
1111
const hrs = (s - mins) / 60;
1212

13-
return `${timePad(hrs)}:${timePad(mins)}:${timePad(secs)}`;
13+
if (showSeconds) {
14+
return `${timePad(hrs)}:${timePad(mins)}:${timePad(secs)}`;
15+
}
16+
return `${timePad(hrs)}:${timePad(mins)}`;
1417
}

src/hooks/TaskHooks.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export function useTaskDuration(model: TaskModel | undefined) {
1818
}
1919
const duration = model.duration;
2020
if (duration !== 0) {
21-
setDuration(msToTime(duration));
21+
setDuration(msToTime(duration, model.active));
2222
}
2323
if (model.active) {
2424
intervalRef.current = setInterval(() => {

src/screens/Main.tsx

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,27 @@
11
import React from 'react';
22
import { Route, Switch, Link } from 'react-router-dom';
3-
import { Layout, Menu } from 'antd';
3+
import { Layout } from 'antd';
44
import { observer } from 'mobx-react';
5+
56
import Projects from './projects/Projects';
7+
import TaskControl from './projects/components/TaskControl/TaskControl';
8+
import HeaderMenu from '../components/HeaderMenu';
69

710
const { Header } = Layout;
811

912
export default observer(function Main() {
1013
return (
1114
<Layout className="layout">
1215
<Header>
13-
<div className="logo" />
14-
<Menu theme="dark" mode="horizontal">
15-
<Menu.Item key="1">
16+
<div>
17+
<HeaderMenu>
1618
<Link to="/hours">Hours</Link>
17-
</Menu.Item>
18-
<Menu.Item key="2">
19+
</HeaderMenu>
20+
<HeaderMenu>
1921
<Link to="/projects">Projects</Link>
20-
</Menu.Item>
21-
</Menu>
22+
</HeaderMenu>
23+
<TaskControl />
24+
</div>
2225
</Header>
2326
<Switch>
2427
<Route path="/hours">
Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,29 @@
11
.task-control {
2+
display: inline-flex;
3+
align-items: center;
4+
height: 44px;
5+
margin-left: 20px;
6+
padding: 8px;
7+
border-radius: 5px;
8+
line-height: 14px;
29
color: white;
3-
//line-height: ;
10+
background-color: #713A91;
11+
}
12+
13+
.task-control--info {
14+
display: inline-flex;
15+
flex: 1;
16+
flex-direction: column;
17+
margin-right: 8px;
18+
width: 140px;
19+
}
20+
21+
.task-control--info span {
22+
white-space: nowrap;
23+
text-overflow: ellipsis;
24+
overflow: hidden;
25+
}
26+
27+
.task-control--duration {
28+
margin-right: 8px;
429
}
Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,36 @@
11
import React, { useMemo } from 'react';
22
import { observer } from 'mobx-react';
3+
import { PauseOutlined } from '@ant-design/icons';
34

45
import './TaskControl.less';
56

67
import rootStore from '../../../../services/RootStore';
78
import { useTaskDuration } from '../../../../hooks/TaskHooks';
9+
import CircleButton from '../../../../components/CircleButton/CircleButton';
810

911
const { tasksStore, projectStore } = rootStore;
1012

1113
export default observer(function TaskControl() {
12-
const activeTask = tasksStore.activeTask;
13-
const duration = useTaskDuration(activeTask);
14+
const task = tasksStore.activeTask;
15+
const duration = useTaskDuration(task);
1416

1517
const project = useMemo(() => {
16-
return projectStore.get(activeTask?.projectId || '');
17-
}, [activeTask]);
18+
return projectStore.get(task?.projectId || '');
19+
}, [task]);
1820

19-
if (activeTask) {
21+
if (task) {
2022
return (
21-
<div className="task-control">
22-
<div>{project?.title}</div>
23-
<div>{activeTask.title}</div>
24-
{duration}
25-
</div>
23+
<span className="task-control">
24+
<div className="task-control--info">
25+
<span>{project?.title}</span>
26+
<span>{task.title}</span>
27+
</div>
28+
<span className="task-control--duration">{duration}</span>
29+
<CircleButton onClick={() => tasksStore.endTimer(task)}>
30+
<PauseOutlined />
31+
</CircleButton>
32+
</span>
2633
);
2734
}
28-
return <div className="task-control">No active tasks</div>;
35+
return <span className="task-control">No active tasks</span>;
2936
});

0 commit comments

Comments
 (0)