Skip to content

Commit fc8cf40

Browse files
committed
feat: add loader
1 parent ba776d9 commit fc8cf40

File tree

5 files changed

+57
-61
lines changed

5 files changed

+57
-61
lines changed

app.js

Lines changed: 22 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,16 @@ const importJsx = require('import-jsx');
33
const PropTypes = require('prop-types');
44
const { merge } = require('lodash');
55

6-
const { Box, Color, Text } = require('ink');
7-
const { default: Spinner } = require('ink-spinner');
6+
const { Box, Color } = require('ink');
87

98
const { resolve } = require('path');
109

11-
1210
const getSubDirectories = require('./lib/dir');
1311
const getUserLog = require('./lib/git');
1412
const normolize = require('./lib/normalizer');
1513

1614
const Project = importJsx('./components/project');
17-
const Errors = importJsx('./components/errors');
15+
const Loading = importJsx('./components/loading');
1816

1917
class App extends React.Component {
2018

@@ -23,7 +21,6 @@ class App extends React.Component {
2321

2422
this.state = {
2523
out: {},
26-
errors: [],
2724
loading: 'Searching',
2825
isLading: true,
2926
author: null
@@ -33,9 +30,10 @@ class App extends React.Component {
3330
handleError(e) {
3431
this.setState({
3532
...this.state,
36-
isLading: false,
37-
errors: [e.toString()]
33+
isLading: false
3834
});
35+
36+
throw e;
3937
}
4038

4139
componentDidMount() {
@@ -83,42 +81,33 @@ class App extends React.Component {
8381

8482
render() {
8583

86-
const { errors, isLading, out, loading } = this.state;
84+
const { isLading, out, loading } = this.state;
8785

88-
const isErrors = errors.length;
8986
const isContent = Object.keys(out).length;
9087

88+
if (isLading) {
89+
return <Loading text={loading}></Loading>;
90+
}
91+
9192
return (
9293
<Box flexDirection="column">
93-
{isLading ? (
94-
<Box>
95-
<Color green>
96-
<Spinner type="dots"/>
97-
<Box marginLeft={2}><Text italic>{loading}</Text></Box>
98-
</Color>
99-
</Box>
100-
) : (
94+
95+
{isContent ? (
10196
<>
102-
{isContent ? (
103-
<>
104-
{Object.keys(out).map(day => (
105-
<Box flexDirection="column" key={day}>
106-
{Object.keys(out[day]).map(project => (
107-
<Project key={project} day={day} name={project} data={out[day][project]}></Project>
108-
))}
109-
</Box>
97+
{Object.keys(out).map(day => (
98+
<Box flexDirection="column" key={day}>
99+
{Object.keys(out[day]).map(project => (
100+
<Project key={project} day={day} name={project} data={out[day][project]}></Project>
110101
))}
111-
</>
112-
) : (
113-
<Box>
114-
{!isErrors ? (<Color blueBright>Not Found</Color>) : null}
115102
</Box>
116-
)}
117-
118-
{isErrors ? (<Errors errors={errors}></Errors>) : null}
119-
103+
))}
120104
</>
105+
) : (
106+
<Box>
107+
<Color blueBright>Not Found</Color>
108+
</Box>
121109
)}
110+
122111
</Box>
123112
);
124113
}

components/errors.js

Lines changed: 0 additions & 26 deletions
This file was deleted.

components/loading.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
const React = require('react');
2+
const PropTypes = require('prop-types');
3+
const { Box, Color, Text } = require('ink');
4+
const { default: Spinner } = require('ink-spinner');
5+
6+
class Loading extends React.Component {
7+
8+
render() {
9+
10+
const { text } = this.props;
11+
12+
return (
13+
<Box flexDirection="column">
14+
<Box>
15+
<Color green>
16+
<Spinner type="dots"/>
17+
<Box marginLeft={2}><Text italic>{text}</Text></Box>
18+
</Color>
19+
</Box>
20+
</Box>
21+
);
22+
}
23+
}
24+
25+
Loading.propTypes = {
26+
text: PropTypes.string
27+
};
28+
29+
Loading.defaultProps = {
30+
text: 'Loading'
31+
};
32+
33+
module.exports = Loading;

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "git-tracker-cli",
3-
"version": "0.0.13",
3+
"version": "0.0.14",
44
"description": "The library that gives a rough estimation of the time spent on implementation based on the history of commits",
55
"authors": [
66
{

0 commit comments

Comments
 (0)