-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
85 lines (78 loc) · 1.8 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import React from 'react';
import ReactDOM from 'react-dom';
import PropTypes from 'prop-types';
import Time from './time';
import './index.css';
const FileList = ({files}) =>
<table className="file-list">
<tbody>
{files.map(file => <FileListItem key={file.id} file={file} />)}
</tbody>
</table>;
FileList.propTypes = {
files: PropTypes.array,
};
const FileListItem = ({file}) =>
<tr className="file-list-item">
<td className="file-name">
<FileName file={file} />
</td>
<td className="commit-message"><CommitMessage commit={file.latestCommit} /></td>
<td className="age">
<Time time={file.updated_at} />
</td>
</tr>;
FileListItem.propTypes = {
file: PropTypes.object.isRequired,
};
function FileName({file}) {
return (
<span>
<FileIcon file={file} /> {file.name}
</span>
);
}
function FileIcon({file}) {
let iconClass = file.type === 'folder' ? 'fa-folder' : 'fa-file-text-o';
return <i className={`fa ${iconClass}`} aria-hidden="true" />;
}
FileIcon.propTypes = {
file: PropTypes.object.isRequired,
};
const CommitMessage = ({commit}) =>
<span className="commit-message">
{commit.message}
</span>;
CommitMessage.propTypes = {
commit: PropTypes.object.isRequired,
};
const testFile = [
{
id: 1,
name: 'src',
type: 'folder',
updated_at: '2017-08-17 08:24:00',
latestCommit: {
message: 'Initial commit',
},
},
{
id: 2,
name: 'tests',
type: 'folder',
updated_at: '2017-08-10 21:24:00',
latestCommit: {
message: 'Initial commit',
},
},
{
id: 3,
name: 'README',
type: 'file',
updated_at: '2017-08-02 21:24:00',
latestCommit: {
message: 'Added a readme',
},
},
];
ReactDOM.render(<FileList files={testFile} />, document.getElementById('root'));